-
Notifications
You must be signed in to change notification settings - Fork 10k
Closed
Labels
bugexplaineda Terraform Core team member has described the root cause of this issue in codea Terraform Core team member has described the root cause of this issue in code
Milestone
Description
Terraform Version
0.13.1
Terraform Configuration Files
#################
# at root level #
#################
module "profileapi" {
source = "./modules/s3_bucket"
bucket_name = "1plusx-profileapi"
enable_versioning = true
retention_days = 7
destination_bucket_arn = module.profileapi-dub.bucket_arn
providers = {
aws = aws.frankfurt
}
}
module "profileapi-dub" {
source = "./modules/s3_bucket"
bucket_name = "1plusx-profileapi-dub"
enable_versioning = true
retention_days = 7
providers = {
aws = aws.dublin
}
}
output "test" {
value = module.profileapi-dub.bucket_arn
}
###########################
# inside s3_bucket module #
###########################
locals {
enable_replication = signum(length(var.destination_bucket_arn)) == 1 ? true : false
replication_cnt = signum(length(var.destination_bucket_arn))
}
resource "aws_s3_bucket" "logged_retention_crrd_bucket" {
count = var.enable_logging && var.enable_expiration && local.enable_replication && false == local.enable_encryption ? 1 : 0
...
}
resource "aws_s3_bucket" "logged_retention_bucket" {
count = var.enable_logging && var.enable_expiration && var.encryption_algorithm == "" && false == local.enable_replication ? 1 : 0
...
}
resource "aws_s3_bucket" "retention_bucket" {
count = false == var.enable_logging && var.enable_expiration && var.encryption_algorithm == "" && false == local.enable_replication ? 1 : 0
...
}
resource "aws_s3_bucket" "logged_bucket" {
count = var.enable_logging && false == var.enable_expiration && var.encryption_algorithm == "" && false == local.enable_replication ? 1 : 0
...
}
Debug Output
Trace outputs were too large for gist, so used gdrive instead
- When output is not explicitly defined at root (and state has been refreshed to make sure it is removed) :
https://drive.google.com/file/d/16w0cj2NWDVLSWnYJdNqiLu6aO-hY84lK/view?usp=sharing
Snippet of the errors:
Error: Invalid count argument
on modules/s3_bucket/main.tf line 434, in resource "aws_s3_bucket" "logged_retention_crrd_bucket":
434: count = var.enable_logging && var.enable_expiration && local.enable_replication && false == local.enable_encryption ? 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.
- When having defined the output at root level, and by having applied targeting specifically the module containing the required output, there is no error:
https://drive.google.com/file/d/1awuoO8c_bZJObV1vlU0d0k-Uh7CrUZhH/view?usp=sharing
Expected Behavior
As it was in 0.12, the module output should be computed and provided to the root level where it is referenced as one of another's module's inputs, without having to explicitly define an output value with it. Commands like state show
correctly output the state that the other module presumes that has never been applied.
Actual Behavior
tf 0.13 thinks that module has never been applied, and therefore its output is not available to another module which uses it as an input.
Steps to Reproduce
- Define the outputs and apply to make them available
- Run tf plan, which works fine
- Remove the outputs, and apply again in order to remove them from the state.
- Plan again, now you get "Error: Invalid count argument"
Additional Context
Nothing special in particular.
jdamata, vivian-src, insider89, fishfacemcgee, jay-lark and 7 more
Metadata
Metadata
Assignees
Labels
bugexplaineda Terraform Core team member has described the root cause of this issue in codea Terraform Core team member has described the root cause of this issue in code