hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.86k stars 9.2k forks source link

[Bug]: aws_elasticache_cluster.cache_nodes output is not considered a dynamic field #40282

Open aallawala opened 4 days ago

aallawala commented 4 days ago

Terraform Core Version

1.9.5

AWS Provider Version

5.77.0

Affected Resource(s)

Expected Behavior

The cache_nodes value should be computed after the apply occurs so that other resources depending on it can enact on those.

Actual Behavior

The cache_nodes show no change during a TF Plan and will fail during a TF apply.

The error is produced when num_cache_nodes for aws_elasticache_cluster is changed and the cache_nodes is used elsewhere in another resource.

Relevant Error/Panic Output Snippet

{"@level":"error","@message":"Error: Provider produced inconsistent final plan","@module":"terraform.ui","@timestamp":"2024-11-22T23:47:09.372277Z","diagnostic":{"severity":"error","summary":"Provider produced inconsistent final plan","detail":"When expanding the plan for module.index-staging-mc.aws_route53_record.default to include new values learned so far during apply, provider \"registry.terraform.io/hashicorp/aws\" produced an invalid new value for .records: planned set element cty.StringVal(\"0 10 11211 index-stg-mc.xxxxxx.0003.use1.cache.amazonaws.com.\") does not correlate with any element in actual.\n\nThis is a bug in the provider, which should be reported in the provider's own issue tracker."},"type":"diagnostic"}
Operation failed: failed running terraform apply (exit 1)

Terraform Configuration Files

resource "aws_elasticache_cluster" "default" {
  count                  = var.destroy_cluster ? 0 : 1
  cluster_id             = var.cluster_name
  num_cache_nodes        = var.node_count > 3 && var.node_count % 3 > 0 ? var.node_count / 3 * 3 : var.node_count
  engine                 = "memcached"
  engine_version         = var.engine_version
  port                   = var.port
  node_type              = var.node_type
...
}

resource "aws_route53_record" "default" {
  zone_id = var.zone_id
  name    = var.dns_name
  type    = "SRV"
  ttl     = "60"

  records = [for server in aws_elasticache_cluster.default[0].cache_nodes : "0 10 ${server.port} ${server.address}."]
}

Steps to Reproduce

Create an elasticache cluster and create another resource that depends on the value of cache_nodes. Change the number of cache nodes and the TF plan will fail to apply.

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 4 days ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue