Skip to content

Unable to reference an origin bucket that does not existing yet #270

Open
@tms0

Description

Describe the Bug

I need to create the bucket outside of this module (because I want to customize his name) but when I "terraform plan", it fails with these errors:

╷
│ Error: Invalid count argument
│ 
│   on .terraform/modules/example_cdn/main.tf line 258, in resource "aws_s3_bucket" "origin":
│  258:   count = local.create_s3_origin_bucket ? 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/example_cdn/main.tf line 361, in data "aws_s3_bucket" "origin":
│  361:   count  = local.enabled && (var.origin_bucket != 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.
╵

Expected Behavior

The ability to use a bucket not managed by this module, but without having it already created.

Steps to Reproduce

# Does not exist yet
resource "aws_s3_bucket" "example" {
  bucket = "example"
}

module "example_cdn" {
  source  = "cloudposse/cloudfront-s3-cdn/aws"
  version = "0.88.0"

  name                              = "example-cdn"
  origin_bucket                = aws_s3_bucket.example.id
  ...
}

Screenshots

No response

Environment

No response

Additional Context

No response

Metadata

Assignees

No one assigned

    Labels

    bug🐛 An issue with the system

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions