Is your feature request related to a problem? Please describe.
Im creating a terraform module for creating an RKE2 cluster using the rancher2 terraform provider. I create the cluster and machine_pools within the rancher2_cluster_v2 resource in my module like so:
resource "rancher2_cluster_v2" "cluster" {
name = "${local.namespace}-cluster"
kubernetes_version = local.kube_rke2_version
enable_network_policy = local.network_policy
cloud_credential_secret_name = rancher2_cloud_credential.openstack.id
labels = merge({
"NAMESPACE" = local.namespace,
"TENANT_NAME" = local.openstack_tenant_name }, local.cluster_labels
)
rke_config {
machine_pools {
name = "master"
cloud_credential_secret_name = rancher2_cloud_credential.openstack.id
control_plane_role = true
etcd_role = true
worker_role = false
quantity = local.master_count
drain_before_delete = true
machine_config {
kind = rancher2_machine_config_v2.openstack_master_node.kind
name = rancher2_machine_config_v2.openstack_master_node.name
}
}
machine_pools {
name = "worker"
cloud_credential_secret_name = rancher2_cloud_credential.openstack.id
control_plane_role = false
etcd_role = false
worker_role = true
quantity = local.worker_count
drain_before_delete = true
unhealthy_node_timeout_seconds = "3600"
machine_config {
kind = rancher2_machine_config_v2.openstack_worker_node.kind
name = rancher2_machine_config_v2.openstack_worker_node.name
}
}
...omitted
But I cannot add more pools in unless I copy and paste more machine pools into this resource.
I have different host configurations with different memory, vcpu, etc and will require more unique pools. I would like to dynamically create these pools by passing in terraform variables. Currently I do not see a way to do this without updating the terraform module with multiple pools which defeats the purpose of the module.
Describe the solution you'd like
Please create a rancher2_node_pool_v2 to add new machine pools
resource "rancher2_node_pool_v2" "foo" {
cluster_id = rancher2_cluster.foo-custom.id
name = "foo"
machine_pools {
name = "worker"
cloud_credential_secret_name = rancher2_cloud_credential.openstack.id
control_plane_role = true
etcd_role = true
worker_role = false
quantity = 3
drain_before_delete = true
machine_config {
kind = rancher2_machine_config_v2.openstack_master_node.kind
name = rancher2_machine_config_v2.openstack_master_node.name
}
}
If that were created, I could do a for_each loop on that resource by passing a variable to my module and I could dynamically create multiple pools
machine_pools = [
{
"name" = "worker"
"quantity" = "1"
"taints" = ""
"image" = "ubuntu-noble"
"flavor" = "medium"
},
{
"name" = "worker2"
"quantity" = "1"
"taints" = ""
"image" = "ubuntu-noble"
"flavor" = "medium"
},
{
"name" = "worker3"
"quantity" = "1"
"taints" = ""
"image" = "ubuntu-noble"
"flavor" = "medium"
}
]
resource "rancher2_cluster_v2" "cluster" {
name = "${local.namespace}-cluster"
kubernetes_version = local.kube_rke2_version
enable_network_policy = local.network_policy
cloud_credential_secret_name = rancher2_cloud_credential.openstack.id
labels = merge({
"NAMESPACE" = local.namespace,
"TENANT_NAME" = local.openstack_tenant_name }, local.cluster_labels
)
rke_config {
machine_pools {
name = "master"
cloud_credential_secret_name = rancher2_cloud_credential.openstack.id
control_plane_role = true
etcd_role = true
worker_role = false
quantity = local.master_count
drain_before_delete = true
machine_config {
kind = rancher2_machine_config_v2.openstack_master_node.kind
name = rancher2_machine_config_v2.openstack_master_node.name
}
}
machine_pools {
name = "worker"
cloud_credential_secret_name = rancher2_cloud_credential.openstack.id
control_plane_role = false
etcd_role = false
worker_role = true
quantity = local.worker_count
drain_before_delete = true
unhealthy_node_timeout_seconds = "3600"
machine_config {
kind = rancher2_machine_config_v2.openstack_worker_node.kind
name = rancher2_machine_config_v2.openstack_worker_node.name
}
}
...omitted
}
resource "rancher2_node_pool_v2" "foo" {
for_each = { for pool in var.machine_pools }
cluster_id = rancher2_cluster.cluster.id
name = each.value.name
machine_pools {
name = each.value.name
cloud_credential_secret_name = rancher2_cloud_credential.openstack.id
control_plane_role = false
etcd_role = false
worker_role = true
quantity = each.value.quantity
drain_before_delete = true
machine_config {
kind = rancher2_machine_config_v2.openstack_worker[machine_pool.key].kind
name = rancher2_machine_config_v2.openstack_worker[machine_pool.key].name
}
}
Of course that is all pseudo code. Hopefully that helps understand the feature and reason for it.
Describe alternatives you've considered
I investigated terraforms dynamic blocks to build out the rancher2_cluster_v2 machine_pools but it was not supported by terraform.
Additional context
None
Thanks for maintaining and improving this module. Terraform is awesome and im glad to see SUSE maintain this provider.
Is your feature request related to a problem? Please describe.
Im creating a terraform module for creating an RKE2 cluster using the rancher2 terraform provider. I create the cluster and machine_pools within the
rancher2_cluster_v2resource in my module like so:But I cannot add more pools in unless I copy and paste more machine pools into this resource.
I have different host configurations with different memory, vcpu, etc and will require more unique pools. I would like to dynamically create these pools by passing in terraform variables. Currently I do not see a way to do this without updating the terraform module with multiple pools which defeats the purpose of the module.
Describe the solution you'd like
Please create a
rancher2_node_pool_v2to add new machine poolsIf that were created, I could do a for_each loop on that resource by passing a variable to my module and I could dynamically create multiple pools
Of course that is all pseudo code. Hopefully that helps understand the feature and reason for it.
Describe alternatives you've considered
I investigated terraforms dynamic blocks to build out the
rancher2_cluster_v2machine_poolsbut it was not supported by terraform.Additional context
None
Thanks for maintaining and improving this module. Terraform is awesome and im glad to see SUSE maintain this provider.