Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Invalid count argument (Due to S3 resources not yet created at apply time) #29

Open
russmac opened this issue Apr 20, 2021 · 4 comments

Comments

@russmac
Copy link

russmac commented Apr 20, 2021

The count logic here is relying on resources pre-existing with known outputs:

count = var.cloudtrail_bucket_id != "" ? 1 : 0

count = var.cloudtrail_bucket_id != "" ? 1 : 0

For example, If comment out the module instantiation, create my s3 bucket, then uncomment the module I can deploy (as the s3 bucket outputs are known beforehand).

If I attempt a DR deployment with the bucket and module instantiation in the same workspace I get the below errors;

Error: Invalid count argument

  on .terraform/modules/datadog/logs_monitoring_cloudtrail.tf line 3, in resource "aws_lambda_permission" "allow-ctbucket-trigger":
   3:   count         = var.cloudtrail_bucket_id != "" ? 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.


Error: Invalid count argument

  on .terraform/modules/datadog/logs_monitoring_cloudtrail.tf line 13, in resource "aws_s3_bucket_notification" "ctbucket-notification-dd-log":
  13:   count  = var.cloudtrail_bucket_id != "" ? 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.

Switching to for_each would be the solution but of course lose backwards compatibility.

@houqp
Copy link
Contributor

houqp commented Apr 21, 2021

I am guessing the current cloudtrail integration expects a static bucket id value @jim80net ? @russmac what's the source of your cloudtrail_bucket_id?

@russmac
Copy link
Author

russmac commented Apr 23, 2021

@houqp an s3 bucket resource created within the same workspace. The reference var.cloudtrail_bucket_id is an output from that resource so its not known at compile time which is what causes the error.

If the s3 bucket is created using any other method (manually, -target, commenting out this module, separate workspace) the error does not occur.

@houqp
Copy link
Contributor

houqp commented Apr 28, 2021

Got it, could you send a PR so we can continue the discussion over there? I think it's ok to break backwards compatibility with another major release as long as it's the right fix.

@russmac
Copy link
Author

russmac commented Apr 29, 2021

@houqp I ended up using something in house to avoid the CFN completely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants