Skip to content

Commit

Permalink
Add support Import for aws_sns_topic_policy resource
Browse files Browse the repository at this point in the history
  • Loading branch information
teraken0509 committed Sep 24, 2019
1 parent 1f8efa5 commit eaa676f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
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
```

0 comments on commit eaa676f

Please sign in to comment.