Add contabo provider

This commit is contained in:
Tobias Reisinger 2024-09-30 20:00:24 +02:00
parent ed555418e2
commit 048ea26034
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
10 changed files with 73 additions and 15 deletions

View file

@ -0,0 +1,4 @@
resource "contabo_instance" "nodes" {
for_each = local.contabo_hosts
display_name = each.value.hostname
}

View file

@ -12,10 +12,6 @@ data "template_file" "cloud_init" {
}
}
locals {
hetzner_hosts = {for key, val in var.hosts : key => val if val.provider == "hetzner"}
}
resource "hcloud_primary_ip" "node_ipv4_addresses" {
for_each = local.hetzner_hosts
name = "primary_ipv4_${each.value.hostname}"

View file

@ -1,5 +1,9 @@
terraform {
required_providers {
contabo = {
source = "contabo/contabo"
version = "~> 0.1.26"
}
hcloud = {
source = "hetznercloud/hcloud"
version = "~> 1.45.0"
@ -19,6 +23,12 @@ terraform {
}
}
provider "contabo" {
oauth2_client_id = var.contabo_provider_vars.client_id
oauth2_client_secret = var.contabo_provider_vars.client_secret
oauth2_user = var.contabo_provider_vars.user
oauth2_pass = var.contabo_provider_vars.pass
}
provider "hcloud" {
token = var.hcloud_token
@ -50,4 +60,7 @@ locals {
services_auth = {for key, val in var.services : key => val if val.auth}
services_database = {for key, val in var.services : key => val if val.database}
services_s3 = {for key, val in var.services : key => val if val.s3}
contabo_hosts = {for key, val in var.hosts : key => val if val.provider == "contabo"}
hetzner_hosts = {for key, val in var.hosts : key => val if val.provider == "hetzner"}
}

View file

@ -1,12 +1,11 @@
locals {
contabo_hosts = {for key, val in var.hosts : key => val if val.provider == "contabo"}
server_addresses = flatten([
[
for host in local.contabo_hosts : [
for host in contabo_instance.nodes : [
{
hostname = host.hostname
ipv4_address = host.ipv4_address
ipv6_address = host.ipv6_address
hostname = host.display_name
ipv4_address = host.ip_config[0].v4[0].ip
ipv6_address = host.ip_config[0].v6[0].ip
},
]
],

View file

@ -1,3 +1,14 @@
variable "contabo_provider_vars" {
type = object({
client_id = string
client_secret = string
user = string
pass = string
})
sensitive = true
}
variable "hcloud_token" {
sensitive = true
}
@ -66,8 +77,6 @@ variable "hosts" {
hostname = string
rdns = string
provider = string
ipv4_address = optional(string)
ipv6_address = optional(string)
image = optional(string)
server_type = optional(string)
datacenter = optional(string)