terraform-provider-scaleway icon indicating copy to clipboard operation
terraform-provider-scaleway copied to clipboard

Changing k8s_pool.size and referencing k8s_pool.nodes in dynamic block of other resource results in error

Open mrohlof-protofy opened this issue 3 years ago • 2 comments
trafficstars

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

Terraform v1.1.6

Affected Resource(s)

  • resource scaleway_k8s_pool

Terraform Configuration Files

resource "scaleway_k8s_cluster" "cluster" {
  name    = "cluster"
  version = "1.23"
  cni     = "cilium"
}

resource "scaleway_k8s_pool" "pool" {
  cluster_id          = scaleway_k8s_cluster.cluster.id
  name                = "pool"
  node_type           = "DEV1-M"
  size                = 1 # change to 2 after initial setup
  # autoscaling does not work with the RDB at the moment...
  # scaling must be done manually via terraform to ensure all nodes have access to the database.
  autoscaling         = false
  autohealing         = true
  wait_for_pool_ready = true
}

resource "scaleway_rdb_instance" "rdb" {
  name           = "postgresql"
  node_type      = "DB-DEV-S"
  engine         = "PostgreSQL-14"
  user_name      = "admin"
  password       = "admin"
}

# any other resource with dynamic block using the scaleway_k8s_pool.nodes attribute works as well
resource "scaleway_rdb_acl" "main" {
  depends_on = [scaleway_k8s_pool.pool]
  instance_id = scaleway_rdb_instance.rdb.id

  # Add each kubernetes node IP to the access list so they can use the database
  dynamic "acl_rules" {
    for_each = scaleway_k8s_pool.pool.nodes # <-- error happens here
    content {
      ip          = "${acl_rules.value["public_ip"]}/32"
      description = "IP of Cluster Node ${acl_rules.value["name"]}"
    }
  }
}

Error Output

│ Error: Provider produced inconsistent final plan
│ 
│ When expanding the plan for scaleway_rdb_acl.main to include new values learned so far during apply, provider "registry.terraform.io/scaleway/scaleway" produced an invalid new value for .acl_rules: actual
│ set element cty.ObjectVal(map[string]cty.Value{"description":cty.StringVal("IP of Cluster Node my-cluster-node"), "ip":cty.StringVal("my-public-ip/32")}) does not correlate
│ with any element in plan.
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
╵
╷
│ Error: Provider produced inconsistent final plan
│ 
│ When expanding the plan for scaleway_rdb_acl.main to include new values learned so far during apply, provider "registry.terraform.io/scaleway/scaleway" produced an invalid new value for .acl_rules: block
│ set length changed from 1 to 2.
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

Expected Behavior

When using scaleway_k8s_pool.nodes attribute in another resource, the provider should suggest "known after apply" for affected fields when updating the pool, like it already does when initially creating the pool.

Actual Behavior

The plan suggests a length of 1 (or any other previous value of size) for the dynamic block, then fails when the number of nodes changed because of the change in the size attribute.

Steps to Reproduce

  1. terraform apply
  2. change size of pool from 1 to 2
  3. terraform apply

mrohlof-protofy avatar Mar 30 '22 09:03 mrohlof-protofy

@Sh4d1

remyleone avatar Apr 15 '22 14:04 remyleone

We cannot add acceptance tests because of the for_each block (https://github.com/hashicorp/terraform-plugin-sdk/issues/536).

remyleone avatar May 11 '22 14:05 remyleone