terraform/builtin/providers/aws/resource_aws_sqs_queue_test.go

365 lines
9.6 KiB
Go
Raw Normal View History

package aws
import (
"fmt"
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/sqs"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
provider/aws: Add DiffSupressionFunc to `aws_elasticsearch_domain`, `aws_sqs_queue` and `aws_sns_topic` ``` SQS Queue Tests: %make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSSQSQueue' 2 ↵ ✹ ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/05 09:46:04 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSQSQueue -timeout 120m === RUN TestAccAWSSQSQueue_importBasic --- PASS: TestAccAWSSQSQueue_importBasic (18.99s) === RUN TestAccAWSSQSQueue_basic --- PASS: TestAccAWSSQSQueue_basic (44.31s) === RUN TestAccAWSSQSQueue_policy --- PASS: TestAccAWSSQSQueue_policy (32.76s) === RUN TestAccAWSSQSQueue_redrivePolicy --- PASS: TestAccAWSSQSQueue_redrivePolicy (66.42s) === RUN TestAccAWSSQSQueue_Policybasic --- PASS: TestAccAWSSQSQueue_Policybasic (32.40s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 194.895s ``` SNS Topic Tests: % make testacc TEST=./builtin/providers/aws % TESTARGS='-run=TestAccAWSSNSTopic_' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/04 22:56:26 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSNSTopic_ -timeout 120m === RUN TestAccAWSSNSTopic_importBasic --- PASS: TestAccAWSSNSTopic_importBasic (17.67s) === RUN TestAccAWSSNSTopic_basic --- PASS: TestAccAWSSNSTopic_basic (17.92s) === RUN TestAccAWSSNSTopic_policy --- PASS: TestAccAWSSNSTopic_policy (20.99s) === RUN TestAccAWSSNSTopic_withIAMRole --- PASS: TestAccAWSSNSTopic_withIAMRole (26.51s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 83.112s ```
2016-09-04 11:04:10 +02:00
"github.com/jen20/awspolicyequivalence"
)
func TestAccAWSSQSQueue_basic(t *testing.T) {
queueName := fmt.Sprintf("sqs-queue-%s", acctest.RandString(5))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSQSQueueDestroy,
Steps: []resource.TestStep{
provider/aws: Add DiffSupressionFunc to `aws_elasticsearch_domain`, `aws_sqs_queue` and `aws_sns_topic` ``` SQS Queue Tests: %make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSSQSQueue' 2 ↵ ✹ ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/05 09:46:04 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSQSQueue -timeout 120m === RUN TestAccAWSSQSQueue_importBasic --- PASS: TestAccAWSSQSQueue_importBasic (18.99s) === RUN TestAccAWSSQSQueue_basic --- PASS: TestAccAWSSQSQueue_basic (44.31s) === RUN TestAccAWSSQSQueue_policy --- PASS: TestAccAWSSQSQueue_policy (32.76s) === RUN TestAccAWSSQSQueue_redrivePolicy --- PASS: TestAccAWSSQSQueue_redrivePolicy (66.42s) === RUN TestAccAWSSQSQueue_Policybasic --- PASS: TestAccAWSSQSQueue_Policybasic (32.40s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 194.895s ``` SNS Topic Tests: % make testacc TEST=./builtin/providers/aws % TESTARGS='-run=TestAccAWSSNSTopic_' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/04 22:56:26 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSNSTopic_ -timeout 120m === RUN TestAccAWSSNSTopic_importBasic --- PASS: TestAccAWSSNSTopic_importBasic (17.67s) === RUN TestAccAWSSNSTopic_basic --- PASS: TestAccAWSSNSTopic_basic (17.92s) === RUN TestAccAWSSNSTopic_policy --- PASS: TestAccAWSSNSTopic_policy (20.99s) === RUN TestAccAWSSNSTopic_withIAMRole --- PASS: TestAccAWSSNSTopic_withIAMRole (26.51s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 83.112s ```
2016-09-04 11:04:10 +02:00
{
Config: testAccAWSSQSConfigWithDefaults(queueName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSQSExistsWithDefaults("aws_sqs_queue.queue"),
),
},
provider/aws: Add DiffSupressionFunc to `aws_elasticsearch_domain`, `aws_sqs_queue` and `aws_sns_topic` ``` SQS Queue Tests: %make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSSQSQueue' 2 ↵ ✹ ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/05 09:46:04 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSQSQueue -timeout 120m === RUN TestAccAWSSQSQueue_importBasic --- PASS: TestAccAWSSQSQueue_importBasic (18.99s) === RUN TestAccAWSSQSQueue_basic --- PASS: TestAccAWSSQSQueue_basic (44.31s) === RUN TestAccAWSSQSQueue_policy --- PASS: TestAccAWSSQSQueue_policy (32.76s) === RUN TestAccAWSSQSQueue_redrivePolicy --- PASS: TestAccAWSSQSQueue_redrivePolicy (66.42s) === RUN TestAccAWSSQSQueue_Policybasic --- PASS: TestAccAWSSQSQueue_Policybasic (32.40s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 194.895s ``` SNS Topic Tests: % make testacc TEST=./builtin/providers/aws % TESTARGS='-run=TestAccAWSSNSTopic_' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/04 22:56:26 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSNSTopic_ -timeout 120m === RUN TestAccAWSSNSTopic_importBasic --- PASS: TestAccAWSSNSTopic_importBasic (17.67s) === RUN TestAccAWSSNSTopic_basic --- PASS: TestAccAWSSNSTopic_basic (17.92s) === RUN TestAccAWSSNSTopic_policy --- PASS: TestAccAWSSNSTopic_policy (20.99s) === RUN TestAccAWSSNSTopic_withIAMRole --- PASS: TestAccAWSSNSTopic_withIAMRole (26.51s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 83.112s ```
2016-09-04 11:04:10 +02:00
{
Config: testAccAWSSQSConfigWithOverrides(queueName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSQSExistsWithOverrides("aws_sqs_queue.queue"),
),
},
provider/aws: Add DiffSupressionFunc to `aws_elasticsearch_domain`, `aws_sqs_queue` and `aws_sns_topic` ``` SQS Queue Tests: %make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSSQSQueue' 2 ↵ ✹ ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/05 09:46:04 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSQSQueue -timeout 120m === RUN TestAccAWSSQSQueue_importBasic --- PASS: TestAccAWSSQSQueue_importBasic (18.99s) === RUN TestAccAWSSQSQueue_basic --- PASS: TestAccAWSSQSQueue_basic (44.31s) === RUN TestAccAWSSQSQueue_policy --- PASS: TestAccAWSSQSQueue_policy (32.76s) === RUN TestAccAWSSQSQueue_redrivePolicy --- PASS: TestAccAWSSQSQueue_redrivePolicy (66.42s) === RUN TestAccAWSSQSQueue_Policybasic --- PASS: TestAccAWSSQSQueue_Policybasic (32.40s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 194.895s ``` SNS Topic Tests: % make testacc TEST=./builtin/providers/aws % TESTARGS='-run=TestAccAWSSNSTopic_' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/04 22:56:26 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSNSTopic_ -timeout 120m === RUN TestAccAWSSNSTopic_importBasic --- PASS: TestAccAWSSNSTopic_importBasic (17.67s) === RUN TestAccAWSSNSTopic_basic --- PASS: TestAccAWSSNSTopic_basic (17.92s) === RUN TestAccAWSSNSTopic_policy --- PASS: TestAccAWSSNSTopic_policy (20.99s) === RUN TestAccAWSSNSTopic_withIAMRole --- PASS: TestAccAWSSNSTopic_withIAMRole (26.51s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 83.112s ```
2016-09-04 11:04:10 +02:00
{
Config: testAccAWSSQSConfigWithDefaults(queueName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSQSExistsWithDefaults("aws_sqs_queue.queue"),
),
},
},
})
}
provider/aws: Add DiffSupressionFunc to `aws_elasticsearch_domain`, `aws_sqs_queue` and `aws_sns_topic` ``` SQS Queue Tests: %make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSSQSQueue' 2 ↵ ✹ ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/05 09:46:04 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSQSQueue -timeout 120m === RUN TestAccAWSSQSQueue_importBasic --- PASS: TestAccAWSSQSQueue_importBasic (18.99s) === RUN TestAccAWSSQSQueue_basic --- PASS: TestAccAWSSQSQueue_basic (44.31s) === RUN TestAccAWSSQSQueue_policy --- PASS: TestAccAWSSQSQueue_policy (32.76s) === RUN TestAccAWSSQSQueue_redrivePolicy --- PASS: TestAccAWSSQSQueue_redrivePolicy (66.42s) === RUN TestAccAWSSQSQueue_Policybasic --- PASS: TestAccAWSSQSQueue_Policybasic (32.40s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 194.895s ``` SNS Topic Tests: % make testacc TEST=./builtin/providers/aws % TESTARGS='-run=TestAccAWSSNSTopic_' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/04 22:56:26 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSNSTopic_ -timeout 120m === RUN TestAccAWSSNSTopic_importBasic --- PASS: TestAccAWSSNSTopic_importBasic (17.67s) === RUN TestAccAWSSNSTopic_basic --- PASS: TestAccAWSSNSTopic_basic (17.92s) === RUN TestAccAWSSNSTopic_policy --- PASS: TestAccAWSSNSTopic_policy (20.99s) === RUN TestAccAWSSNSTopic_withIAMRole --- PASS: TestAccAWSSNSTopic_withIAMRole (26.51s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 83.112s ```
2016-09-04 11:04:10 +02:00
func TestAccAWSSQSQueue_policy(t *testing.T) {
queueName := fmt.Sprintf("sqs-queue-%s", acctest.RandString(5))
topicName := fmt.Sprintf("sns-topic-%s", acctest.RandString(5))
expectedPolicyText := fmt.Sprintf(
`{"Version": "2012-10-17","Id": "sqspolicy","Statement":[{"Sid": "Stmt1451501026839","Effect": "Allow","Principal":"*","Action":"sqs:SendMessage","Resource":"arn:aws:sqs:us-west-2:470663696735:%s","Condition":{"ArnEquals":{"aws:SourceArn":"arn:aws:sns:us-west-2:470663696735:%s"}}}]}`,
topicName, queueName)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSQSQueueDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSSQSConfig_PolicyFormat(topicName, queueName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSQSHasPolicy("aws_sqs_queue.test-email-events", expectedPolicyText),
),
},
},
})
}
func TestAccAWSSQSQueue_redrivePolicy(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSQSQueueDestroy,
Steps: []resource.TestStep{
provider/aws: Add DiffSupressionFunc to `aws_elasticsearch_domain`, `aws_sqs_queue` and `aws_sns_topic` ``` SQS Queue Tests: %make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSSQSQueue' 2 ↵ ✹ ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/05 09:46:04 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSQSQueue -timeout 120m === RUN TestAccAWSSQSQueue_importBasic --- PASS: TestAccAWSSQSQueue_importBasic (18.99s) === RUN TestAccAWSSQSQueue_basic --- PASS: TestAccAWSSQSQueue_basic (44.31s) === RUN TestAccAWSSQSQueue_policy --- PASS: TestAccAWSSQSQueue_policy (32.76s) === RUN TestAccAWSSQSQueue_redrivePolicy --- PASS: TestAccAWSSQSQueue_redrivePolicy (66.42s) === RUN TestAccAWSSQSQueue_Policybasic --- PASS: TestAccAWSSQSQueue_Policybasic (32.40s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 194.895s ``` SNS Topic Tests: % make testacc TEST=./builtin/providers/aws % TESTARGS='-run=TestAccAWSSNSTopic_' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/04 22:56:26 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSNSTopic_ -timeout 120m === RUN TestAccAWSSNSTopic_importBasic --- PASS: TestAccAWSSNSTopic_importBasic (17.67s) === RUN TestAccAWSSNSTopic_basic --- PASS: TestAccAWSSNSTopic_basic (17.92s) === RUN TestAccAWSSNSTopic_policy --- PASS: TestAccAWSSNSTopic_policy (20.99s) === RUN TestAccAWSSNSTopic_withIAMRole --- PASS: TestAccAWSSNSTopic_withIAMRole (26.51s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 83.112s ```
2016-09-04 11:04:10 +02:00
{
Config: testAccAWSSQSConfigWithRedrive(acctest.RandStringFromCharSet(5, acctest.CharSetAlpha)),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSQSExistsWithDefaults("aws_sqs_queue.my_dead_letter_queue"),
),
},
},
})
}
// Tests formatting and compacting of Policy, Redrive json
func TestAccAWSSQSQueue_Policybasic(t *testing.T) {
provider/aws: Add DiffSupressionFunc to `aws_elasticsearch_domain`, `aws_sqs_queue` and `aws_sns_topic` ``` SQS Queue Tests: %make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSSQSQueue' 2 ↵ ✹ ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/05 09:46:04 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSQSQueue -timeout 120m === RUN TestAccAWSSQSQueue_importBasic --- PASS: TestAccAWSSQSQueue_importBasic (18.99s) === RUN TestAccAWSSQSQueue_basic --- PASS: TestAccAWSSQSQueue_basic (44.31s) === RUN TestAccAWSSQSQueue_policy --- PASS: TestAccAWSSQSQueue_policy (32.76s) === RUN TestAccAWSSQSQueue_redrivePolicy --- PASS: TestAccAWSSQSQueue_redrivePolicy (66.42s) === RUN TestAccAWSSQSQueue_Policybasic --- PASS: TestAccAWSSQSQueue_Policybasic (32.40s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 194.895s ``` SNS Topic Tests: % make testacc TEST=./builtin/providers/aws % TESTARGS='-run=TestAccAWSSNSTopic_' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/04 22:56:26 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSNSTopic_ -timeout 120m === RUN TestAccAWSSNSTopic_importBasic --- PASS: TestAccAWSSNSTopic_importBasic (17.67s) === RUN TestAccAWSSNSTopic_basic --- PASS: TestAccAWSSNSTopic_basic (17.92s) === RUN TestAccAWSSNSTopic_policy --- PASS: TestAccAWSSNSTopic_policy (20.99s) === RUN TestAccAWSSNSTopic_withIAMRole --- PASS: TestAccAWSSNSTopic_withIAMRole (26.51s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 83.112s ```
2016-09-04 11:04:10 +02:00
queueName := fmt.Sprintf("sqs-queue-%s", acctest.RandString(5))
topicName := fmt.Sprintf("sns-topic-%s", acctest.RandString(5))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSQSQueueDestroy,
Steps: []resource.TestStep{
provider/aws: Add DiffSupressionFunc to `aws_elasticsearch_domain`, `aws_sqs_queue` and `aws_sns_topic` ``` SQS Queue Tests: %make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSSQSQueue' 2 ↵ ✹ ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/05 09:46:04 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSQSQueue -timeout 120m === RUN TestAccAWSSQSQueue_importBasic --- PASS: TestAccAWSSQSQueue_importBasic (18.99s) === RUN TestAccAWSSQSQueue_basic --- PASS: TestAccAWSSQSQueue_basic (44.31s) === RUN TestAccAWSSQSQueue_policy --- PASS: TestAccAWSSQSQueue_policy (32.76s) === RUN TestAccAWSSQSQueue_redrivePolicy --- PASS: TestAccAWSSQSQueue_redrivePolicy (66.42s) === RUN TestAccAWSSQSQueue_Policybasic --- PASS: TestAccAWSSQSQueue_Policybasic (32.40s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 194.895s ``` SNS Topic Tests: % make testacc TEST=./builtin/providers/aws % TESTARGS='-run=TestAccAWSSNSTopic_' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/04 22:56:26 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSNSTopic_ -timeout 120m === RUN TestAccAWSSNSTopic_importBasic --- PASS: TestAccAWSSNSTopic_importBasic (17.67s) === RUN TestAccAWSSNSTopic_basic --- PASS: TestAccAWSSNSTopic_basic (17.92s) === RUN TestAccAWSSNSTopic_policy --- PASS: TestAccAWSSNSTopic_policy (20.99s) === RUN TestAccAWSSNSTopic_withIAMRole --- PASS: TestAccAWSSNSTopic_withIAMRole (26.51s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 83.112s ```
2016-09-04 11:04:10 +02:00
{
Config: testAccAWSSQSConfig_PolicyFormat(topicName, queueName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSQSExistsWithOverrides("aws_sqs_queue.test-email-events"),
),
},
},
})
}
func testAccCheckAWSSQSQueueDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).sqsconn
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_sqs_queue" {
continue
}
// Check if queue exists by checking for its attributes
params := &sqs.GetQueueAttributesInput{
QueueUrl: aws.String(rs.Primary.ID),
}
_, err := conn.GetQueueAttributes(params)
if err == nil {
return fmt.Errorf("Queue %s still exists. Failing!", rs.Primary.ID)
}
// Verify the error is what we want
_, ok := err.(awserr.Error)
if !ok {
return err
}
}
return nil
}
provider/aws: Add DiffSupressionFunc to `aws_elasticsearch_domain`, `aws_sqs_queue` and `aws_sns_topic` ``` SQS Queue Tests: %make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSSQSQueue' 2 ↵ ✹ ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/05 09:46:04 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSQSQueue -timeout 120m === RUN TestAccAWSSQSQueue_importBasic --- PASS: TestAccAWSSQSQueue_importBasic (18.99s) === RUN TestAccAWSSQSQueue_basic --- PASS: TestAccAWSSQSQueue_basic (44.31s) === RUN TestAccAWSSQSQueue_policy --- PASS: TestAccAWSSQSQueue_policy (32.76s) === RUN TestAccAWSSQSQueue_redrivePolicy --- PASS: TestAccAWSSQSQueue_redrivePolicy (66.42s) === RUN TestAccAWSSQSQueue_Policybasic --- PASS: TestAccAWSSQSQueue_Policybasic (32.40s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 194.895s ``` SNS Topic Tests: % make testacc TEST=./builtin/providers/aws % TESTARGS='-run=TestAccAWSSNSTopic_' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/04 22:56:26 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSNSTopic_ -timeout 120m === RUN TestAccAWSSNSTopic_importBasic --- PASS: TestAccAWSSNSTopic_importBasic (17.67s) === RUN TestAccAWSSNSTopic_basic --- PASS: TestAccAWSSNSTopic_basic (17.92s) === RUN TestAccAWSSNSTopic_policy --- PASS: TestAccAWSSNSTopic_policy (20.99s) === RUN TestAccAWSSNSTopic_withIAMRole --- PASS: TestAccAWSSNSTopic_withIAMRole (26.51s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 83.112s ```
2016-09-04 11:04:10 +02:00
func testAccCheckAWSQSHasPolicy(n string, expectedPolicyText string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No Queue URL specified!")
}
conn := testAccProvider.Meta().(*AWSClient).sqsconn
params := &sqs.GetQueueAttributesInput{
QueueUrl: aws.String(rs.Primary.ID),
AttributeNames: []*string{aws.String("Policy")},
}
resp, err := conn.GetQueueAttributes(params)
if err != nil {
return err
}
var actualPolicyText string
for k, v := range resp.Attributes {
if k == "Policy" {
actualPolicyText = *v
break
}
}
equivalent, err := awspolicy.PoliciesAreEquivalent(actualPolicyText, expectedPolicyText)
if err != nil {
return fmt.Errorf("Error testing policy equivalence: %s", err)
}
if !equivalent {
return fmt.Errorf("Non-equivalent policy error:\n\nexpected: %s\n\n got: %s\n",
expectedPolicyText, actualPolicyText)
}
return nil
}
}
func testAccCheckAWSSQSExistsWithDefaults(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No Queue URL specified!")
}
conn := testAccProvider.Meta().(*AWSClient).sqsconn
params := &sqs.GetQueueAttributesInput{
QueueUrl: aws.String(rs.Primary.ID),
AttributeNames: []*string{aws.String("All")},
}
resp, err := conn.GetQueueAttributes(params)
if err != nil {
return err
}
// checking if attributes are defaults
for k, v := range resp.Attributes {
if k == "VisibilityTimeout" && *v != "30" {
return fmt.Errorf("VisibilityTimeout (%s) was not set to 30", *v)
}
if k == "MessageRetentionPeriod" && *v != "345600" {
return fmt.Errorf("MessageRetentionPeriod (%s) was not set to 345600", *v)
}
if k == "MaximumMessageSize" && *v != "262144" {
return fmt.Errorf("MaximumMessageSize (%s) was not set to 262144", *v)
}
if k == "DelaySeconds" && *v != "0" {
return fmt.Errorf("DelaySeconds (%s) was not set to 0", *v)
}
if k == "ReceiveMessageWaitTimeSeconds" && *v != "0" {
return fmt.Errorf("ReceiveMessageWaitTimeSeconds (%s) was not set to 0", *v)
}
}
return nil
}
}
func testAccCheckAWSSQSExistsWithOverrides(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("No Queue URL specified!")
}
conn := testAccProvider.Meta().(*AWSClient).sqsconn
params := &sqs.GetQueueAttributesInput{
QueueUrl: aws.String(rs.Primary.ID),
AttributeNames: []*string{aws.String("All")},
}
resp, err := conn.GetQueueAttributes(params)
if err != nil {
return err
}
// checking if attributes match our overrides
for k, v := range resp.Attributes {
if k == "VisibilityTimeout" && *v != "60" {
return fmt.Errorf("VisibilityTimeout (%s) was not set to 60", *v)
}
if k == "MessageRetentionPeriod" && *v != "86400" {
return fmt.Errorf("MessageRetentionPeriod (%s) was not set to 86400", *v)
}
if k == "MaximumMessageSize" && *v != "2048" {
return fmt.Errorf("MaximumMessageSize (%s) was not set to 2048", *v)
}
if k == "DelaySeconds" && *v != "90" {
return fmt.Errorf("DelaySeconds (%s) was not set to 90", *v)
}
if k == "ReceiveMessageWaitTimeSeconds" && *v != "10" {
return fmt.Errorf("ReceiveMessageWaitTimeSeconds (%s) was not set to 10", *v)
}
}
return nil
}
}
func testAccAWSSQSConfigWithDefaults(r string) string {
return fmt.Sprintf(`
resource "aws_sqs_queue" "queue" {
name = "%s"
}
`, r)
}
func testAccAWSSQSConfigWithOverrides(r string) string {
return fmt.Sprintf(`
resource "aws_sqs_queue" "queue" {
name = "%s"
delay_seconds = 90
max_message_size = 2048
message_retention_seconds = 86400
receive_wait_time_seconds = 10
visibility_timeout_seconds = 60
}`, r)
}
func testAccAWSSQSConfigWithRedrive(name string) string {
return fmt.Sprintf(`
resource "aws_sqs_queue" "my_queue" {
name = "tftestqueuq-%s"
delay_seconds = 0
visibility_timeout_seconds = 300
redrive_policy = <<EOF
{
"maxReceiveCount": 3,
"deadLetterTargetArn": "${aws_sqs_queue.my_dead_letter_queue.arn}"
}
EOF
}
resource "aws_sqs_queue" "my_dead_letter_queue" {
name = "tfotherqueuq-%s"
}
`, name, name)
}
provider/aws: Add DiffSupressionFunc to `aws_elasticsearch_domain`, `aws_sqs_queue` and `aws_sns_topic` ``` SQS Queue Tests: %make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSSQSQueue' 2 ↵ ✹ ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/05 09:46:04 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSQSQueue -timeout 120m === RUN TestAccAWSSQSQueue_importBasic --- PASS: TestAccAWSSQSQueue_importBasic (18.99s) === RUN TestAccAWSSQSQueue_basic --- PASS: TestAccAWSSQSQueue_basic (44.31s) === RUN TestAccAWSSQSQueue_policy --- PASS: TestAccAWSSQSQueue_policy (32.76s) === RUN TestAccAWSSQSQueue_redrivePolicy --- PASS: TestAccAWSSQSQueue_redrivePolicy (66.42s) === RUN TestAccAWSSQSQueue_Policybasic --- PASS: TestAccAWSSQSQueue_Policybasic (32.40s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 194.895s ``` SNS Topic Tests: % make testacc TEST=./builtin/providers/aws % TESTARGS='-run=TestAccAWSSNSTopic_' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/04 22:56:26 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSNSTopic_ -timeout 120m === RUN TestAccAWSSNSTopic_importBasic --- PASS: TestAccAWSSNSTopic_importBasic (17.67s) === RUN TestAccAWSSNSTopic_basic --- PASS: TestAccAWSSNSTopic_basic (17.92s) === RUN TestAccAWSSNSTopic_policy --- PASS: TestAccAWSSNSTopic_policy (20.99s) === RUN TestAccAWSSNSTopic_withIAMRole --- PASS: TestAccAWSSNSTopic_withIAMRole (26.51s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 83.112s ```
2016-09-04 11:04:10 +02:00
func testAccAWSSQSConfig_PolicyFormat(queue, topic string) string {
return fmt.Sprintf(`
variable "sns_name" {
provider/aws: Add DiffSupressionFunc to `aws_elasticsearch_domain`, `aws_sqs_queue` and `aws_sns_topic` ``` SQS Queue Tests: %make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSSQSQueue' 2 ↵ ✹ ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/05 09:46:04 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSQSQueue -timeout 120m === RUN TestAccAWSSQSQueue_importBasic --- PASS: TestAccAWSSQSQueue_importBasic (18.99s) === RUN TestAccAWSSQSQueue_basic --- PASS: TestAccAWSSQSQueue_basic (44.31s) === RUN TestAccAWSSQSQueue_policy --- PASS: TestAccAWSSQSQueue_policy (32.76s) === RUN TestAccAWSSQSQueue_redrivePolicy --- PASS: TestAccAWSSQSQueue_redrivePolicy (66.42s) === RUN TestAccAWSSQSQueue_Policybasic --- PASS: TestAccAWSSQSQueue_Policybasic (32.40s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 194.895s ``` SNS Topic Tests: % make testacc TEST=./builtin/providers/aws % TESTARGS='-run=TestAccAWSSNSTopic_' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/04 22:56:26 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSNSTopic_ -timeout 120m === RUN TestAccAWSSNSTopic_importBasic --- PASS: TestAccAWSSNSTopic_importBasic (17.67s) === RUN TestAccAWSSNSTopic_basic --- PASS: TestAccAWSSNSTopic_basic (17.92s) === RUN TestAccAWSSNSTopic_policy --- PASS: TestAccAWSSNSTopic_policy (20.99s) === RUN TestAccAWSSNSTopic_withIAMRole --- PASS: TestAccAWSSNSTopic_withIAMRole (26.51s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 83.112s ```
2016-09-04 11:04:10 +02:00
default = "%s"
}
variable "sqs_name" {
provider/aws: Add DiffSupressionFunc to `aws_elasticsearch_domain`, `aws_sqs_queue` and `aws_sns_topic` ``` SQS Queue Tests: %make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSSQSQueue' 2 ↵ ✹ ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/05 09:46:04 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSQSQueue -timeout 120m === RUN TestAccAWSSQSQueue_importBasic --- PASS: TestAccAWSSQSQueue_importBasic (18.99s) === RUN TestAccAWSSQSQueue_basic --- PASS: TestAccAWSSQSQueue_basic (44.31s) === RUN TestAccAWSSQSQueue_policy --- PASS: TestAccAWSSQSQueue_policy (32.76s) === RUN TestAccAWSSQSQueue_redrivePolicy --- PASS: TestAccAWSSQSQueue_redrivePolicy (66.42s) === RUN TestAccAWSSQSQueue_Policybasic --- PASS: TestAccAWSSQSQueue_Policybasic (32.40s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 194.895s ``` SNS Topic Tests: % make testacc TEST=./builtin/providers/aws % TESTARGS='-run=TestAccAWSSNSTopic_' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/04 22:56:26 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSNSTopic_ -timeout 120m === RUN TestAccAWSSNSTopic_importBasic --- PASS: TestAccAWSSNSTopic_importBasic (17.67s) === RUN TestAccAWSSNSTopic_basic --- PASS: TestAccAWSSNSTopic_basic (17.92s) === RUN TestAccAWSSNSTopic_policy --- PASS: TestAccAWSSNSTopic_policy (20.99s) === RUN TestAccAWSSNSTopic_withIAMRole --- PASS: TestAccAWSSNSTopic_withIAMRole (26.51s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 83.112s ```
2016-09-04 11:04:10 +02:00
default = "%s"
}
resource "aws_sns_topic" "test_topic" {
name = "${var.sns_name}"
}
resource "aws_sqs_queue" "test-email-events" {
name = "${var.sqs_name}"
depends_on = ["aws_sns_topic.test_topic"]
delay_seconds = 90
max_message_size = 2048
message_retention_seconds = 86400
receive_wait_time_seconds = 10
visibility_timeout_seconds = 60
policy = <<EOF
{
"Version": "2012-10-17",
"Id": "sqspolicy",
"Statement": [
{
"Sid": "Stmt1451501026839",
"Effect": "Allow",
"Principal": "*",
"Action": "sqs:SendMessage",
"Resource": "arn:aws:sqs:us-west-2:470663696735:${var.sqs_name}",
"Condition": {
"ArnEquals": {
"aws:SourceArn": "arn:aws:sns:us-west-2:470663696735:${var.sns_name}"
}
}
}
]
}
EOF
}
resource "aws_sns_topic_subscription" "test_queue_target" {
topic_arn = "${aws_sns_topic.test_topic.arn}"
protocol = "sqs"
endpoint = "${aws_sqs_queue.test-email-events.arn}"
}
provider/aws: Add DiffSupressionFunc to `aws_elasticsearch_domain`, `aws_sqs_queue` and `aws_sns_topic` ``` SQS Queue Tests: %make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSSQSQueue' 2 ↵ ✹ ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/05 09:46:04 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSQSQueue -timeout 120m === RUN TestAccAWSSQSQueue_importBasic --- PASS: TestAccAWSSQSQueue_importBasic (18.99s) === RUN TestAccAWSSQSQueue_basic --- PASS: TestAccAWSSQSQueue_basic (44.31s) === RUN TestAccAWSSQSQueue_policy --- PASS: TestAccAWSSQSQueue_policy (32.76s) === RUN TestAccAWSSQSQueue_redrivePolicy --- PASS: TestAccAWSSQSQueue_redrivePolicy (66.42s) === RUN TestAccAWSSQSQueue_Policybasic --- PASS: TestAccAWSSQSQueue_Policybasic (32.40s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 194.895s ``` SNS Topic Tests: % make testacc TEST=./builtin/providers/aws % TESTARGS='-run=TestAccAWSSNSTopic_' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/09/04 22:56:26 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSNSTopic_ -timeout 120m === RUN TestAccAWSSNSTopic_importBasic --- PASS: TestAccAWSSNSTopic_importBasic (17.67s) === RUN TestAccAWSSNSTopic_basic --- PASS: TestAccAWSSNSTopic_basic (17.92s) === RUN TestAccAWSSNSTopic_policy --- PASS: TestAccAWSSNSTopic_policy (20.99s) === RUN TestAccAWSSNSTopic_withIAMRole --- PASS: TestAccAWSSNSTopic_withIAMRole (26.51s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 83.112s ```
2016-09-04 11:04:10 +02:00
`, topic, queue)
}