CORS rules configuration on a new S3 bucket fails
ArghyaChakraborty opened this issue · comments
Description
I am trying to create a new S3 bucket with CORS rules configured. But Terraform fails in Plan phase with following error:
Error: Invalid count argument
on .terraform/modules/s3_interim_bucket/main.tf line 200, in resource "aws_s3_bucket_cors_configuration" "this":
200: count = local.create_bucket && length(local.cors_rules) > 0 ? 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.
If your request is for a new feature, please use the Feature request
template.
- [ X] ✋ I have searched the open/closed issues and my issue is not listed.
⚠️ Note
Before you submit an issue, please perform the following first:
- Remove the local
.terraform
directory (! ONLY if state is stored remotely, which hopefully you are following that best practice!):rm -rf .terraform/
- Re-initialize the project root to pull down modules:
terraform init
- Re-attempt your terraform plan or apply and check if the issue still persists
Versions
-
Module version [Required]:
-
Terraform version:
- Provider version(s):
Reproduction Code [Required]
module "s3_interim_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
bucket = "some-bucket"
acl = "private"
control_object_ownership = true
object_ownership = "ObjectWriter"
force_destroy = true
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
versioning = {
enabled = false
}
lifecycle_rule = [
{
id = "file"
enabled = true
filter = {
prefix = "file/"
}
expiration = {
days = 3
}
}
]
cors_rule = [
{
allowed_headers = ["*"],
allowed_methods = ["GET"],
allowed_origins = ["https://corporatedns.com"],
expose_headers = []
}
]
server_side_encryption_configuration = {
rule = {
apply_server_side_encryption_by_default = {
sse_algorithm = "AES256"
}
}
}
}
Steps to reproduce the behavior:
NO YESJust doing terraform init -> terraform plan -> the above mentioned issue arises
Expected behavior
We would expect the S3 bucket to be created and CORS rules to be applied properly
Actual behavior
The terraform plan failed. Pasted error message at the top
Terminal Output Screenshot(s)
Additional context
This issue has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this issue will be closed in 10 days
This issue was automatically closed because of stale in 10 days
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.