Skip to content

Eliminate errors with the monitoring module on a single terraform apply #128

@BCTBB

Description

@BCTBB

This issue is from the report from @MScottBlake in #79.

The monitoring addon still requires a secondary -target in order to deploy correctly. In my testing, I am receiving the following errors when I run terraform plan. I can't even get to terraform apply without removing this addon.

Error: Invalid for_each argument

  on .terraform/modules/monitoring/addons/monitoring/main.tf line 3, in resource "aws_cloudwatch_metric_alarm" "cpu_utilization_too_high":
   3:   for_each            = toset(var.mysql_cluster_members)
    ├────────────────
    │ var.mysql_cluster_members is a list of string, known only after apply

The "for_each" set includes values derived from resource attributes that cannot be determined until apply, and so Terraform cannot determine the full set of keys
that will identify the instances of this resource.

When working with unknown values in for_each, it's better to use a map value where the keys are defined statically in your configuration and where only the values
contain apply-time results.

Alternatively, you could use the -target planning option to first apply only the resources that the for_each value depends on, and then apply a second time to fully
converge.

Error: Invalid for_each argument

  on .terraform/modules/monitoring/addons/monitoring/main.tf line 131, in resource "aws_cloudwatch_metric_alarm" "redis_cpu":
 131:   for_each            = toset(var.redis_cluster_members)
    ├────────────────
    │ var.redis_cluster_members is a list of string, known only after apply

The "for_each" set includes values derived from resource attributes that cannot be determined until apply, and so Terraform cannot determine the full set of keys
that will identify the instances of this resource.

When working with unknown values in for_each, it's better to use a map value where the keys are defined statically in your configuration and where only the values
contain apply-time results.

Alternatively, you could use the -target planning option to first apply only the resources that the for_each value depends on, and then apply a second time to fully
converge.

Error: Invalid for_each argument

  on .terraform/modules/monitoring/addons/monitoring/main.tf line 152, in resource "aws_cloudwatch_metric_alarm" "redis_cpu_engine_utilization":
 152:   for_each            = toset(var.redis_cluster_members)
    ├────────────────
    │ var.redis_cluster_members is a list of string, known only after apply

The "for_each" set includes values derived from resource attributes that cannot be determined until apply, and so Terraform cannot determine the full set of keys
that will identify the instances of this resource.

When working with unknown values in for_each, it's better to use a map value where the keys are defined statically in your configuration and where only the values
contain apply-time results.

Alternatively, you could use the -target planning option to first apply only the resources that the for_each value depends on, and then apply a second time to fully
converge.

Error: Invalid for_each argument

  on .terraform/modules/monitoring/addons/monitoring/main.tf line 173, in resource "aws_cloudwatch_metric_alarm" "redis-database-memory-percentage":
 173:   for_each            = toset(var.redis_cluster_members)
    ├────────────────
    │ var.redis_cluster_members is a list of string, known only after apply

The "for_each" set includes values derived from resource attributes that cannot be determined until apply, and so Terraform cannot determine the full set of keys
that will identify the instances of this resource.

When working with unknown values in for_each, it's better to use a map value where the keys are defined statically in your configuration and where only the values
contain apply-time results.

Alternatively, you could use the -target planning option to first apply only the resources that the for_each value depends on, and then apply a second time to fully
converge.

Error: Invalid for_each argument

  on .terraform/modules/monitoring/addons/monitoring/main.tf line 194, in resource "aws_cloudwatch_metric_alarm" "redis-current-connections":
 194:   for_each                  = toset(var.redis_cluster_members)
    ├────────────────
    │ var.redis_cluster_members is a list of string, known only after apply

The "for_each" set includes values derived from resource attributes that cannot be determined until apply, and so Terraform cannot determine the full set of keys
that will identify the instances of this resource.

When working with unknown values in for_each, it's better to use a map value where the keys are defined statically in your configuration and where only the values
contain apply-time results.

Alternatively, you could use the -target planning option to first apply only the resources that the for_each value depends on, and then apply a second time to fully
converge.

Error: Invalid for_each argument

  on .terraform/modules/monitoring/addons/monitoring/main.tf line 229, in resource "aws_cloudwatch_metric_alarm" "redis-replication-lag":
 229:   for_each                  = toset(var.redis_cluster_members)
    ├────────────────
    │ var.redis_cluster_members is a list of string, known only after apply

The "for_each" set includes values derived from resource attributes that cannot be determined until apply, and so Terraform cannot determine the full set of keys
that will identify the instances of this resource.

When working with unknown values in for_each, it's better to use a map value where the keys are defined statically in your configuration and where only the values
contain apply-time results.

Alternatively, you could use the -target planning option to first apply only the resources that the for_each value depends on, and then apply a second time to fully
converge.

Error: Invalid count argument

  on .terraform/modules/monitoring/addons/monitoring/main.tf line 264, in resource "aws_cloudwatch_metric_alarm" "acm_certificate_expired":
 264:   count               = var.acm_certificate_arn == null ? 0 : 1

The "count" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created. To work
around this, use the -target argument to first apply only the resources that the count depends on.

Metadata

Metadata

Assignees

Labels

:help-customersIssues for the customer success team

Type

No fields configured for Bug.

Projects

Status
🪺 Not yet

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions