Skip to content
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

Add support Import for aws_sns_topic_policy resource #10163

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions aws/resource_aws_sns_topic_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func resourceAwsSnsTopicPolicy() *schema.Resource {
Update: resourceAwsSnsTopicPolicyUpsert,
Delete: resourceAwsSnsTopicPolicyDelete,

Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Expand Down Expand Up @@ -91,6 +95,7 @@ func resourceAwsSnsTopicPolicyRead(d *schema.ResourceData, meta interface{}) err
}

d.Set("policy", policy)
d.Set("arn", attrmap["TopicArn"])

return nil
}
Expand Down
8 changes: 7 additions & 1 deletion aws/resource_aws_sns_topic_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

func TestAccAWSSNSTopicPolicy_basic(t *testing.T) {
attributes := make(map[string]string)
resourceName := "aws_sns_topic_policy.custom"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -19,10 +20,15 @@ func TestAccAWSSNSTopicPolicy_basic(t *testing.T) {
Config: testAccAWSSNSTopicConfig_withPolicy,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSNSTopicExists("aws_sns_topic.test", attributes),
resource.TestMatchResourceAttr("aws_sns_topic_policy.custom", "policy",
resource.TestMatchResourceAttr(resourceName, "policy",
regexp.MustCompile("^{\"Version\":\"2012-10-17\".+")),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down
9 changes: 9 additions & 0 deletions website/docs/r/sns_topic_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,12 @@ The following arguments are supported:

* `arn` - (Required) The ARN of the SNS topic
* `policy` - (Required) The fully-formed AWS policy as JSON. 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

SNS Topic Policy can be imported using the topic ARN, e.g.

```
$ terraform import aws_sns_topic.user_updates arn:aws:sns:us-west-2:0123456789012:my-topic
```