terraform-provider-aws: import aws_s3_bucket does not store important attributes like acl
i am trying to import exist s3 resource. generating hcl with terraforming, and importing statefile with terraform. after import , while run terraform plan cannot get zero changes. Terraform verion
Terraform v0.11.8
+ provider.aws v1.38.0
Terraform Configuration Files
main.tf
terraform {
backend "s3" {
bucket = "terraform-state-foodev-global"
dynamodb_table = "terraform-lock-foodev-global"
key = "s3/terraform.tfstate"
region = "ap-southeast-1"
}
}
provider "aws" {
region = "ap-southeast-1"
}
resource.tf – generated by terraforming
resource "aws_s3_bucket" "freeman-test2" {
bucket = "freeman-test2"
acl = "private"
}
Output
$ terraform import aws_s3_bucket.freeman-test2 freeman-test2
Acquiring state lock. This may take a few moments...
aws_s3_bucket.freeman-test2: Importing from ID "freeman-test2"...
aws_s3_bucket.freeman-test2: Import complete!
Imported aws_s3_bucket (ID: freeman-test2)
aws_s3_bucket.freeman-test2: Refreshing state... (ID: freeman-test2)
Import successful!
The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.
Releasing state lock. This may take a few moments...
$ terraform plan
aws_s3_bucket.freeman-test2: Refreshing state... (ID: freeman-test2)
------------------------------------------------------------------------
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
~ aws_s3_bucket.freeman-test2
acl: "" => "private"
force_destroy: "" => "false"
Plan: 0 to add, 1 to change, 0 to destroy.
and check s3/terraform.tfstate file, without acl attribute
Expected Behavior run terraform plan get zero changes.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 55
- Comments: 18 (4 by maintainers)
The issue is persist in Terraform v0.12.18. The
aclandforce_destroyof S3 is still missing after imported.Still an issue.
I’m seeing this with Terraform 0.12.26 and version 2.69.0 of the aws provider. It’s concerning when there are grants involved since trying to
applypast this actually removed the grant. Here are the steps I observed:aclproperty but did have onegrantblock.aclandforce_destroyshowed as dirty.acleven though it’s conflicting but this was disallowed. Settingforce_destroytofalseas the plan showed also did not seem to take any effect.applyanyway, as this was a low risk bucket. Applying the phantomacl = "private"change actually removed my grant!I am not sure how to account for this without hacking the state file to add the
acl(and maybeforce_destroy) attributes directly but I have not been able to get an empty plan in this case and applying it is dangerous on high risk buckets since this would temporarily remove the policy as specified in code.https://docs.aws.amazon.com/cli/latest/reference/s3api/get-bucket-acl.html
Hi all 👋 Just letting you know that this is issue is featured on this quarters roadmap. If a PR exists to close the issue a maintainer will review and either make changes directly, or work with the original author to get the contribution merged. If you have written a PR to resolve the issue please ensure the “Allow edits from maintainers” box is checked. Thanks for your patience and we are looking forward to getting this merged soon!
Here’s an OK workaround depending on your comfort level:
Step 1. Pull the state file down
Ensure you’re in the directory of your imported s3 bucket and run:
Step 2. Edit the state.json file and set the correct state on force_destroy/acl
In the JSON file you’ll have to find your resource and in the attributes object you’ll find both the
aclandforce_destroyare set to null, set these to the appropriate values:You can map your S3 ACL to set of canned ACLs here: https://docs.aws.amazon.com/AmazonS3/latest/userguide/acl-overview.html#canned-acl As for the force_destroy, i set mine to
false, but i’m not actually sure what this related to in AWS.Step 3. Increment the serial number at the top of the state.json file
If its currently 5 set it to 6… etc…
Step 4. Push the state file back up, and make sure to erase the local copy*
After that all of it came out clean without having to ignore the state.