github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/builtin/providers/aws/resource_aws_sns_topic_policy_test.go (about) 1 package aws 2 3 import ( 4 "regexp" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/resource" 8 ) 9 10 func TestAccAWSSNSTopicPolicy_basic(t *testing.T) { 11 resource.Test(t, resource.TestCase{ 12 PreCheck: func() { testAccPreCheck(t) }, 13 Providers: testAccProviders, 14 CheckDestroy: testAccCheckAWSSNSTopicDestroy, 15 Steps: []resource.TestStep{ 16 resource.TestStep{ 17 Config: testAccAWSSNSTopicConfig_withPolicy, 18 Check: resource.ComposeTestCheckFunc( 19 testAccCheckAWSSNSTopicExists("aws_sns_topic.test"), 20 resource.TestMatchResourceAttr("aws_sns_topic_policy.custom", "policy", 21 regexp.MustCompile("^{\"Version\":\"2012-10-17\".+")), 22 ), 23 }, 24 }, 25 }) 26 } 27 28 const testAccAWSSNSTopicConfig_withPolicy = ` 29 resource "aws_sns_topic" "test" { 30 name = "tf-acc-test-topic-with-policy" 31 } 32 33 resource "aws_sns_topic_policy" "custom" { 34 arn = "${aws_sns_topic.test.arn}" 35 policy = <<POLICY 36 { 37 "Version":"2012-10-17", 38 "Id": "default", 39 "Statement":[{ 40 "Sid":"default", 41 "Effect":"Allow", 42 "Principal":{"AWS":"*"}, 43 "Action":["SNS:GetTopicAttributes","SNS:SetTopicAttributes","SNS:AddPermission","SNS:RemovePermission","SNS:DeleteTopic"], 44 "Resource":"${aws_sns_topic.test.arn}" 45 }] 46 } 47 POLICY 48 } 49 `