Skip to content

Commit

Permalink
resource/aws_s3_bucket_policy: add import ability
Browse files Browse the repository at this point in the history
closes #6519
  • Loading branch information
acburdine committed Nov 21, 2018
1 parent 1ef089b commit 2b4f06f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
6 changes: 6 additions & 0 deletions aws/resource_aws_s3_bucket_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ func resourceAwsS3BucketPolicy() *schema.Resource {
Read: resourceAwsS3BucketPolicyRead,
Update: resourceAwsS3BucketPolicyPut,
Delete: resourceAwsS3BucketPolicyDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"bucket": {
Expand Down Expand Up @@ -86,6 +89,9 @@ func resourceAwsS3BucketPolicyRead(d *schema.ResourceData, meta interface{}) err
if err := d.Set("policy", v); err != nil {
return err
}
if err := d.Set("bucket", d.Id()); err != nil {
return err
}

return nil
}
Expand Down
13 changes: 12 additions & 1 deletion aws/resource_aws_s3_bucket_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

func TestAccAWSS3BucketPolicy_basic(t *testing.T) {
Expand Down Expand Up @@ -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,
},
},
})
}
Expand Down Expand Up @@ -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,
},
},
})
}
Expand Down
10 changes: 8 additions & 2 deletions website/docs/r/s3_bucket_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
```
$ terraform import aws_s3_bucket_policy.example my-bucket-name
```

0 comments on commit 2b4f06f

Please sign in to comment.