Loading...
Loading...
### Terraform Version ```shell Terraform v1.3.6 on linux_amd64 + provider registry.terraform.io/hashicorp/archive v2.2.0 + provider registry.terraform.io/hashicorp/aws v4.47.0 + provider registry.terraform.io/hashicorp/random v3.4.3 + provider registry.terraform.io/hashicorp/template v2.2.0 ``` ### Terraform Configuration Files ```terraform resource "aws_iam_role_policy" "permissions_role_policy" { count = length(var.permissions) > 0 && var.instance_profile_arn == null ? 1 : 0 name = "permissions" role = aws_iam_role.role[0].name policy = data.aws_iam_policy_document.permissions.json lifecycle { ignore_changes = [name] } } ``` See steps to reproduce ### Debug Output Nothing that looks relevant ### Expected Behavior The error message should indicate which instance of a module is causing the error, so that it is easier to resolve the issue. ### Actual Behavior I get an error like: ``` ╷ │ Error: Invalid count argument │ │ on ../modules/autoscaling_group/main.tf line 139, in resource "aws_iam_role_policy" "permissions_role_policy": │ 139: count = length(var.permissions) > 0 && var.instance_profile_arn == null ? 1 : 0 │ │ 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. ╵ ``` Note that it doesn't say anything about which instance of the autoscaling_group module caused this error. and there are several instances of this module in the root module, so determining which one caused this error is difficult. ### Steps to Reproduce 1. create a module where a resource is conditionally created based on a variable, such as in the example configuration above 2. Create multiple instances of the module in a root module 3. Have one of the module instances use a variable that uses an interpolated value based on a resource that doesn't exist yet, so that the value used in the expression for the count is `unkown`. 4. run `terraform plan` 5. See the error ### Additional Context This wouldn't be as much of an issue if terraform could be intelligent about converting unknown values to known values where possible. For example, in this case even though `var.permissions` contains values that use interpolated values from unknown values, the length of `var.permissions` could be known at plan time, because the number of elements passed in is static, even if some of the individual elements don't have known values yet. However, I recognize that is a more difficult problem to solve, but having better diagnostics would make troubleshooting this kind of issue easier. ### References - https://github.com/hashicorp/terraform/issues/30937
Click on a version to see all relevant bugs
Terraform Integration
Learn more about where this data comes from
Bug Scrub Advisor
Streamline upgrades with automated vendor bug scrubs
BugZero Enterprise
Wish you caught this bug sooner? Get proactive today.