mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-24 23:46:26 -06:00
e81751c4ee
Had to change the way that the tests were working to include a random sqs-queue name due to this error: ``` `aws_sqs_queue.test_queue: Error creating SQS queue: AWS.SimpleQueueService.QueueDeletedRecently: You must wait 60 seconds after deleting a queue before you can create another with the same name. status code: 400, request id: b58e800a-ae27-556e-b6de-cfe1bbf9dc09`` ``` make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSSNSTopicSubscription_' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /vendor/) TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSSNSTopicSubscription_ -timeout 120m === RUN TestAccAWSSNSTopicSubscription_importBasic --- PASS: TestAccAWSSNSTopicSubscription_importBasic (24.44s) === RUN TestAccAWSSNSTopicSubscription_basic --- PASS: TestAccAWSSNSTopicSubscription_basic (25.26s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 49.722s ```
106 lines
2.5 KiB
Go
106 lines
2.5 KiB
Go
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/sns"
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func TestAccAWSSNSTopicSubscription_basic(t *testing.T) {
|
|
ri := acctest.RandInt()
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckAWSSNSTopicSubscriptionDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: testAccAWSSNSTopicSubscriptionConfig(ri),
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckAWSSNSTopicExists("aws_sns_topic.test_topic"),
|
|
testAccCheckAWSSNSTopicSubscriptionExists("aws_sns_topic_subscription.test_subscription"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccCheckAWSSNSTopicSubscriptionDestroy(s *terraform.State) error {
|
|
conn := testAccProvider.Meta().(*AWSClient).snsconn
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
if rs.Type != "aws_sns_topic" {
|
|
continue
|
|
}
|
|
|
|
// Try to find key pair
|
|
req := &sns.GetSubscriptionAttributesInput{
|
|
SubscriptionArn: aws.String(rs.Primary.ID),
|
|
}
|
|
|
|
_, err := conn.GetSubscriptionAttributes(req)
|
|
|
|
if err == nil {
|
|
return fmt.Errorf("Subscription still exists, can't continue.")
|
|
}
|
|
|
|
// Verify the error is an API error, not something else
|
|
_, ok := err.(awserr.Error)
|
|
if !ok {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func testAccCheckAWSSNSTopicSubscriptionExists(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 SNS subscription with that ARN exists")
|
|
}
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).snsconn
|
|
|
|
params := &sns.GetSubscriptionAttributesInput{
|
|
SubscriptionArn: aws.String(rs.Primary.ID),
|
|
}
|
|
_, err := conn.GetSubscriptionAttributes(params)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testAccAWSSNSTopicSubscriptionConfig(i int) string {
|
|
return fmt.Sprintf(`
|
|
resource "aws_sns_topic" "test_topic" {
|
|
name = "terraform-test-topic"
|
|
}
|
|
|
|
resource "aws_sqs_queue" "test_queue" {
|
|
name = "terraform-subscription-test-queue-%d"
|
|
}
|
|
|
|
resource "aws_sns_topic_subscription" "test_subscription" {
|
|
topic_arn = "${aws_sns_topic.test_topic.arn}"
|
|
protocol = "sqs"
|
|
endpoint = "${aws_sqs_queue.test_queue.arn}"
|
|
}
|
|
`, i)
|
|
}
|