github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/aws/resource_aws_sqs_queue_policy_test.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 "regexp" 6 "testing" 7 8 "github.com/hashicorp/terraform/helper/acctest" 9 "github.com/hashicorp/terraform/helper/resource" 10 ) 11 12 func TestAccAWSSQSQueuePolicy_basic(t *testing.T) { 13 queueName := fmt.Sprintf("sqs-queue-%s", acctest.RandString(5)) 14 resource.Test(t, resource.TestCase{ 15 PreCheck: func() { testAccPreCheck(t) }, 16 Providers: testAccProviders, 17 CheckDestroy: testAccCheckAWSSQSQueueDestroy, 18 Steps: []resource.TestStep{ 19 resource.TestStep{ 20 Config: testAccAWSSQSPolicyConfig_basic(queueName), 21 Check: resource.ComposeTestCheckFunc( 22 testAccCheckAWSSQSExistsWithDefaults("aws_sqs_queue.q"), 23 resource.TestMatchResourceAttr("aws_sqs_queue_policy.test", "policy", 24 regexp.MustCompile("^{\"Version\":\"2012-10-17\".+")), 25 ), 26 }, 27 }, 28 }) 29 } 30 31 func testAccAWSSQSPolicyConfig_basic(r string) string { 32 return fmt.Sprintf(testAccAWSSQSPolicyConfig_basic_tpl, r) 33 } 34 35 const testAccAWSSQSPolicyConfig_basic_tpl = ` 36 resource "aws_sqs_queue" "q" { 37 name = "%s" 38 } 39 40 resource "aws_sqs_queue_policy" "test" { 41 queue_url = "${aws_sqs_queue.q.id}" 42 policy = <<POLICY 43 { 44 "Version": "2012-10-17", 45 "Id": "sqspolicy", 46 "Statement": [ 47 { 48 "Sid": "First", 49 "Effect": "Allow", 50 "Principal": "*", 51 "Action": "sqs:SendMessage", 52 "Resource": "${aws_sqs_queue.q.arn}", 53 "Condition": { 54 "ArnEquals": { 55 "aws:SourceArn": "${aws_sqs_queue.q.arn}" 56 } 57 } 58 } 59 ] 60 } 61 POLICY 62 } 63 `