-
-
Notifications
You must be signed in to change notification settings - Fork 94
Description
Found a bug? Maybe our Slack Community can help.
Describe the Bug
After upgrading to version 0.15.0, terraform plan
fails with the error "Invalid count argument" when planning on an empty configuration (no existing resources) if the variable master_password
is set from a random_password
resource.
Expected Behavior
The configuration should be planned.
Steps to Reproduce
This is a minimal configuration to reproduce:
resource "random_password" "documentdb" {
length = 22
special = false
}
module "documentdb_cluster" {
source = "cloudposse/documentdb-cluster/aws"
version = "0.15.0"
master_password = random_password.documentdb.result
name = "foo"
vpc_id = ""
subnet_ids = [""]
}
Run terraform plan
to get the error.
Screenshots
╷
│ Error: Invalid count argument
│
│ on .terraform/modules/documentdb_cluster/main.tf line 43, in resource "random_password" "password":
│ 43: count = module.this.enabled && var.master_password != "" ? 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.
╵
Environment (please complete the following information):
- OS: Linux
- Terraform version: 1.1.8
- Version: 0.15.0
Additional Context
The separate random_password
resource is there because this code was written against version 0.14.
The easy workaround for this would be to remove the random_password
resource and use the one provided by the module, but that doesn't work for our purposes because the module doesn't return the generated password (in our case, it gets stored in Secrets Manager).
Providing the password as an output would be the easiest fix for this, but another way would be to add a separate generate_password
boolean parameter.
Aside - it looks like there may be another bug in the count
condition:
count = module.this.enabled && var.master_password != "" ? 0 : 1
If module.this.enabled
is false
, then count
is always set to 1 - this should surely be the other way around?