-
Notifications
You must be signed in to change notification settings - Fork 9.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
resource/aws_s3_bucket_policy: add import ability #6543
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ import ( | |
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
"github.com/jen20/awspolicyequivalence" | ||
awspolicy "github.com/jen20/awspolicyequivalence" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. goimports added this automatically, let me know if I need to revert the change. |
||
) | ||
|
||
func TestAccAWSS3BucketPolicy_basic(t *testing.T) { | ||
|
@@ -39,6 +39,11 @@ func TestAccAWSS3BucketPolicy_basic(t *testing.T) { | |
testAccCheckAWSS3BucketHasPolicy("aws_s3_bucket.bucket", expectedPolicyText), | ||
), | ||
}, | ||
{ | ||
ResourceName: "aws_s3_bucket_policy.bucket", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
@@ -89,6 +94,12 @@ func TestAccAWSS3BucketPolicy_policyUpdate(t *testing.T) { | |
testAccCheckAWSS3BucketHasPolicy("aws_s3_bucket.bucket", expectedPolicyText2), | ||
), | ||
}, | ||
|
||
{ | ||
ResourceName: "aws_s3_bucket_policy.bucket", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,8 +35,8 @@ resource "aws_s3_bucket_policy" "b" { | |
"Resource": "arn:aws:s3:::my_tf_test_bucket/*", | ||
"Condition": { | ||
"IpAddress": {"aws:SourceIp": "8.8.8.8/32"} | ||
} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
POLICY | ||
|
@@ -49,3 +49,9 @@ The following arguments are supported: | |
|
||
* `bucket` - (Required) The name of the bucket to which to apply the policy. | ||
* `policy` - (Required) The text of the policy. For more information about building AWS IAM policy documents with Terraform, see the [AWS IAM Policy Document Guide](/docs/providers/aws/guides/iam-policy-documents.html). | ||
|
||
## Import | ||
S3 bucket policies can be imported using the bucket name, e.g. | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like an extra space snuck in here, which would likely break the page formatting. Maybe someday we'll get markdownlint running against pull requests to catch this. 😅 I'll fix this on merge. |
||
$ terraform import aws_s3_bucket_policy.example my-bucket-name | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bflad not sure if this will break anything - had to do it in order for import to work correctly though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a valid (non-breaking) change, thanks!