You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
modules/s3-document-bucket/main.tf
So we have a simple module to create a bucket and attach a policy giving read/ write perms to specified roles based on arns passed in as variables.
variable"bucket_name" {
description="(Required) A name our S3 bucket."
}
variable"read_object_roles" {
type="list"description="A list of role ARNs to apply get object permssions to."
}
variable"write_object_roles" {
type="list"description="A list of role ARNs to apply S3:PutObject and S3:PutObjectACL permissions to."
}
data"aws_iam_policy_document""document_bucket_policy_document" {
# Assign read rolesstatement {
sid=""effect="Allow"principals {
identifiers="${var.read_object_roles}"type="AWS"
}
actions=[
"s3:GetObject",
"s3:GetBucketLocation",
"s3:ListBucket",
]
resources=[
"arn:aws:s3:::${var.bucket_name}/*",
"arn:aws:s3:::${var.bucket_name}",
]
}
# Assign write rolesstatement {
sid=""effect="Allow"principals {
identifiers="${var.write_object_roles}"type="AWS"
}
actions=[
"s3:PutObject",
"s3:PutObjectAcl",
]
resources=[
"arn:aws:s3:::${var.bucket_name}/*",
"arn:aws:s3:::${var.bucket_name}",
]
}
}
resource"aws_s3_bucket""document_bucket" {
bucket="${var.bucket_name}"acl="private"versioning {
enabled=true
}
# Apply policy to bucketpolicy="${data.aws_iam_policy_document.document_bucket_policy_document.json}"
}
main.tf
We call the module, in the first instance it's fine, creates the policy, saves it to the remote state file etc. The problem arises when we have an empty list as our principal variable (read_only_bucket.write_object_roles)
Terraform plan shows there is a change to make and is saying it will add an empty principal block. It doesn't appear to complete this action because running plan, then apply then plan yields the same message.
The state file gets saved without a principal block because it would have been empty.
The plan gets generated with an empty principal block.
There's always a mismatch.
if the policy document is not specific enough (but still valid), Terraform may view the policy as constantly changing in a terraform plan.
However... This is slightly more of a problem than the issues referenced below. In those, resource, action and principal list variables are converted to strings if they contain a single value. In my case the principal block is removed altogether when no principal is specified. I can't replicate this in my terraform because I can't conditionally remove the principal block
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.
ghost
locked and limited conversation to collaborators
Apr 2, 2020
This issue was closed.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Terraform Version
Terraform Configuration Files
modules/s3-document-bucket/main.tf
So we have a simple module to create a bucket and attach a policy giving read/ write perms to specified roles based on arns passed in as variables.
main.tf
We call the module, in the first instance it's fine, creates the policy, saves it to the remote state file etc. The problem arises when we have an empty list as our principal variable (
read_only_bucket.write_object_roles
)Output of
terraform plan
Terraform plan shows there is a change to make and is saying it will add an empty principal block. It doesn't appear to complete this action because running plan, then apply then plan yields the same message.
What's happening
The state file gets saved without a principal block because it would have been empty.
The plan gets generated with an empty principal block.
There's always a mismatch.
Additional Context
It looks like this might be a known issue:
https://www.terraform.io/docs/providers/aws/r/s3_bucket.html#policy
However... This is slightly more of a problem than the issues referenced below. In those,
resource
,action
andprincipal
list variables are converted to strings if they contain a single value. In my case the principal block is removed altogether when no principal is specified. I can't replicate this in my terraform because I can't conditionally remove theprincipal
blockCan anyone suggest a work around until
0.12
? https://www.hashicorp.com/blog/terraform-0-1-2-previewReferences
#5613
#4948
The text was updated successfully, but these errors were encountered: