Skip to content

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

@russmac

Description

@russmac

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions