Skip to content

Commit

Permalink
Add config option to allow provider adoption
Browse files Browse the repository at this point in the history
  • Loading branch information
bastjan committed Oct 25, 2024
1 parent 544cdd2 commit 0256a11
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 45 deletions.
23 changes: 12 additions & 11 deletions infra.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
module "infra" {
source = "./modules/node-group"

region = var.region
role = "infra"
node_count = var.infra_count
node_name_suffix = local.node_name_suffix
image_slug = var.image_slug
flavor_slug = var.infra_flavor
volume_size_gb = var.default_volume_size_gb
subnet_uuid = local.subnet_uuid
ignition_ca = var.ignition_ca
api_int = "api-int.${local.node_name_suffix}"
cluster_id = var.cluster_id
region = var.region
role = "infra"
node_count = var.infra_count
node_name_suffix = local.node_name_suffix
image_slug = var.image_slug
flavor_slug = var.infra_flavor
volume_size_gb = var.default_volume_size_gb
subnet_uuid = local.subnet_uuid
ignition_ca = var.ignition_ca
api_int = "api-int.${local.node_name_suffix}"
cluster_id = var.cluster_id
make_adoptable_by_provider = var.make_worker_adoptable_by_provider
}
25 changes: 13 additions & 12 deletions master.tf
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
module "master" {
source = "./modules/node-group"

region = var.region
role = "master"
ignition_config = "master"
node_count = var.master_count
node_name_suffix = local.node_name_suffix
image_slug = var.image_slug
flavor_slug = var.master_flavor
volume_size_gb = var.default_volume_size_gb
subnet_uuid = local.subnet_uuid
ignition_ca = var.ignition_ca
api_int = "api-int.${local.node_name_suffix}"
cluster_id = var.cluster_id
region = var.region
role = "master"
ignition_config = "master"
node_count = var.master_count
node_name_suffix = local.node_name_suffix
image_slug = var.image_slug
flavor_slug = var.master_flavor
volume_size_gb = var.default_volume_size_gb
subnet_uuid = local.subnet_uuid
ignition_ca = var.ignition_ca
api_int = "api-int.${local.node_name_suffix}"
cluster_id = var.cluster_id
make_adoptable_by_provider = var.make_master_adoptable_by_provider
}
6 changes: 6 additions & 0 deletions modules/node-group/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ resource "cloudscale_server" "node" {
subnet_uuid = var.subnet_uuid
}
}

tags = var.make_adoptable_by_provider ? {
"machine-api-provider-cloudscale_appuio_io_name" : random_id.node[count.index].hex
} : {
}

user_data = <<-EOF
{
"ignition": {
Expand Down
6 changes: 6 additions & 0 deletions modules/node-group/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@ variable "cluster_id" {
type = string
description = "ID of the cluster to which the nodes belong, used for rendering machines and machine sets"
}

variable "make_adoptable_by_provider" {
type = bool
description = "Whether to make the nodes adoptable by https://github.com/appuio/machine-api-provider-cloudscale"
default = false
}
12 changes: 12 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,15 @@ variable "internal_router_vip" {
description = "Custom internal floating IP for the router. Users must provide an IP that's within the final privnet CIDR."
default = ""
}

variable "make_worker_adoptable_by_provider" {
type = bool
description = "Whether to make the worker nodes adoptable by https://github.com/appuio/machine-api-provider-cloudscale"
default = false
}

variable "make_master_adoptable_by_provider" {
type = bool
description = "Whether to make the master nodes adoptable by https://github.com/appuio/machine-api-provider-cloudscale"
default = false
}
46 changes: 24 additions & 22 deletions worker.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
module "worker" {
source = "./modules/node-group"

region = var.region
role = "worker"
node_count = var.worker_count
node_name_suffix = local.node_name_suffix
image_slug = var.image_slug
flavor_slug = var.worker_flavor
volume_size_gb = local.worker_volume_size_gb
subnet_uuid = local.subnet_uuid
ignition_ca = var.ignition_ca
api_int = "api-int.${local.node_name_suffix}"
cluster_id = var.cluster_id
region = var.region
role = "worker"
node_count = var.worker_count
node_name_suffix = local.node_name_suffix
image_slug = var.image_slug
flavor_slug = var.worker_flavor
volume_size_gb = local.worker_volume_size_gb
subnet_uuid = local.subnet_uuid
ignition_ca = var.ignition_ca
api_int = "api-int.${local.node_name_suffix}"
cluster_id = var.cluster_id
make_adoptable_by_provider = var.make_worker_adoptable_by_provider
}

// Additional worker groups.
Expand All @@ -21,15 +22,16 @@ module "additional_worker" {

source = "./modules/node-group"

region = var.region
role = each.key
node_count = each.value.count
node_name_suffix = local.node_name_suffix
image_slug = var.image_slug
flavor_slug = each.value.flavor
volume_size_gb = each.value.volume_size_gb != null ? each.value.volume_size_gb : local.worker_volume_size_gb
subnet_uuid = local.subnet_uuid
ignition_ca = var.ignition_ca
api_int = "api-int.${local.node_name_suffix}"
cluster_id = var.cluster_id
region = var.region
role = each.key
node_count = each.value.count
node_name_suffix = local.node_name_suffix
image_slug = var.image_slug
flavor_slug = each.value.flavor
volume_size_gb = each.value.volume_size_gb != null ? each.value.volume_size_gb : local.worker_volume_size_gb
subnet_uuid = local.subnet_uuid
ignition_ca = var.ignition_ca
api_int = "api-int.${local.node_name_suffix}"
cluster_id = var.cluster_id
make_adoptable_by_provider = var.make_worker_adoptable_by_provider
}

0 comments on commit 0256a11

Please sign in to comment.