mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-24 23:46:26 -06:00
9cb1dffb4d
* provider/aws: Allow `source_ids` in `aws_db_event_subscription` to be Updatable Fixes #7809 This commit adds support for `source_ids` to be updated rather than forcing new each time. Unfortunately, it must range over the difference in the source_ids and add and remove them 1 at a time. AWS does not support batch updating source_ids ``` % make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSDBEventSubscription_' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSDBEventSubscription_ -timeout 120m === RUN TestAccAWSDBEventSubscription_basicUpdate --- PASS: TestAccAWSDBEventSubscription_basicUpdate (1277.87s) === RUN TestAccAWSDBEventSubscription_withSourceIds --- PASS: TestAccAWSDBEventSubscription_withSourceIds (1012.96s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 2290.844s ``` * Update resource_aws_db_event_subscription.go
259 lines
7.2 KiB
Go
259 lines
7.2 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/rds"
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func TestAccAWSDBEventSubscription_basicUpdate(t *testing.T) {
|
|
var v rds.EventSubscription
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckAWSDBEventSubscriptionDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: testAccAWSDBEventSubscriptionConfig,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckAWSDBEventSubscriptionExists("aws_db_event_subscription.bar", &v),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_db_event_subscription.bar", "enabled", "true"),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_db_event_subscription.bar", "source_type", "db-instance"),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_db_event_subscription.bar", "name", "tf-acc-test-rds-event-subs"),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_db_event_subscription.bar", "tags.Name", "name"),
|
|
),
|
|
},
|
|
resource.TestStep{
|
|
Config: testAccAWSDBEventSubscriptionConfigUpdate,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckAWSDBEventSubscriptionExists("aws_db_event_subscription.bar", &v),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_db_event_subscription.bar", "enabled", "false"),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_db_event_subscription.bar", "source_type", "db-parameter-group"),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_db_event_subscription.bar", "tags.Name", "new-name"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func TestAccAWSDBEventSubscription_withSourceIds(t *testing.T) {
|
|
var v rds.EventSubscription
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckAWSDBEventSubscriptionDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: testAccAWSDBEventSubscriptionConfigWithSourceIds,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckAWSDBEventSubscriptionExists("aws_db_event_subscription.bar", &v),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_db_event_subscription.bar", "enabled", "true"),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_db_event_subscription.bar", "source_type", "db-parameter-group"),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_db_event_subscription.bar", "name", "tf-acc-test-rds-event-subs-with-ids"),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_db_event_subscription.bar", "source_ids.#", "1"),
|
|
),
|
|
},
|
|
resource.TestStep{
|
|
Config: testAccAWSDBEventSubscriptionConfigUpdateSourceIds,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckAWSDBEventSubscriptionExists("aws_db_event_subscription.bar", &v),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_db_event_subscription.bar", "enabled", "true"),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_db_event_subscription.bar", "source_type", "db-parameter-group"),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_db_event_subscription.bar", "name", "tf-acc-test-rds-event-subs-with-ids"),
|
|
resource.TestCheckResourceAttr(
|
|
"aws_db_event_subscription.bar", "source_ids.#", "2"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func testAccCheckAWSDBEventSubscriptionExists(n string, v *rds.EventSubscription) 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 RDS Event Subscription is set")
|
|
}
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).rdsconn
|
|
|
|
opts := rds.DescribeEventSubscriptionsInput{
|
|
SubscriptionName: aws.String(rs.Primary.ID),
|
|
}
|
|
|
|
resp, err := conn.DescribeEventSubscriptions(&opts)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if len(resp.EventSubscriptionsList) != 1 ||
|
|
*resp.EventSubscriptionsList[0].CustSubscriptionId != rs.Primary.ID {
|
|
return fmt.Errorf("RDS Event Subscription not found")
|
|
}
|
|
|
|
*v = *resp.EventSubscriptionsList[0]
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func testAccCheckAWSDBEventSubscriptionDestroy(s *terraform.State) error {
|
|
conn := testAccProvider.Meta().(*AWSClient).rdsconn
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
if rs.Type != "aws_db_event_subscription" {
|
|
continue
|
|
}
|
|
|
|
var err error
|
|
resp, err := conn.DescribeEventSubscriptions(
|
|
&rds.DescribeEventSubscriptionsInput{
|
|
SubscriptionName: aws.String(rs.Primary.ID),
|
|
})
|
|
|
|
if ae, ok := err.(awserr.Error); ok && ae.Code() == "SubscriptionNotFound" {
|
|
continue
|
|
}
|
|
|
|
if err == nil {
|
|
if len(resp.EventSubscriptionsList) != 0 &&
|
|
*resp.EventSubscriptionsList[0].CustSubscriptionId == rs.Primary.ID {
|
|
return fmt.Errorf("Event Subscription still exists")
|
|
}
|
|
}
|
|
|
|
// Verify the error
|
|
newerr, ok := err.(awserr.Error)
|
|
if !ok {
|
|
return err
|
|
}
|
|
if newerr.Code() != "SubscriptionNotFound" {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
var testAccAWSDBEventSubscriptionConfig = `
|
|
resource "aws_sns_topic" "aws_sns_topic" {
|
|
name = "tf-acc-test-rds-event-subs-sns-topic"
|
|
}
|
|
|
|
resource "aws_db_event_subscription" "bar" {
|
|
name = "tf-acc-test-rds-event-subs"
|
|
sns_topic = "${aws_sns_topic.aws_sns_topic.arn}"
|
|
source_type = "db-instance"
|
|
event_categories = [
|
|
"availability",
|
|
"backup",
|
|
"creation",
|
|
"deletion",
|
|
"maintenance"
|
|
]
|
|
tags {
|
|
Name = "name"
|
|
}
|
|
}
|
|
`
|
|
|
|
var testAccAWSDBEventSubscriptionConfigUpdate = `
|
|
resource "aws_sns_topic" "aws_sns_topic" {
|
|
name = "tf-acc-test-rds-event-subs-sns-topic"
|
|
}
|
|
|
|
resource "aws_db_event_subscription" "bar" {
|
|
name = "tf-acc-test-rds-event-subs"
|
|
sns_topic = "${aws_sns_topic.aws_sns_topic.arn}"
|
|
enabled = false
|
|
source_type = "db-parameter-group"
|
|
event_categories = [
|
|
"configuration change"
|
|
]
|
|
tags {
|
|
Name = "new-name"
|
|
}
|
|
}
|
|
`
|
|
|
|
var testAccAWSDBEventSubscriptionConfigWithSourceIds = `
|
|
resource "aws_sns_topic" "aws_sns_topic" {
|
|
name = "tf-acc-test-rds-event-subs-sns-topic"
|
|
}
|
|
|
|
resource "aws_db_parameter_group" "bar" {
|
|
name = "db-parameter-group-event-1"
|
|
family = "mysql5.6"
|
|
description = "Test parameter group for terraform"
|
|
}
|
|
|
|
resource "aws_db_event_subscription" "bar" {
|
|
name = "tf-acc-test-rds-event-subs-with-ids"
|
|
sns_topic = "${aws_sns_topic.aws_sns_topic.arn}"
|
|
source_type = "db-parameter-group"
|
|
source_ids = ["${aws_db_parameter_group.bar.id}"]
|
|
event_categories = [
|
|
"configuration change"
|
|
]
|
|
tags {
|
|
Name = "name"
|
|
}
|
|
}
|
|
`
|
|
|
|
var testAccAWSDBEventSubscriptionConfigUpdateSourceIds = `
|
|
resource "aws_sns_topic" "aws_sns_topic" {
|
|
name = "tf-acc-test-rds-event-subs-sns-topic"
|
|
}
|
|
|
|
resource "aws_db_parameter_group" "bar" {
|
|
name = "db-parameter-group-event-1"
|
|
family = "mysql5.6"
|
|
description = "Test parameter group for terraform"
|
|
}
|
|
|
|
resource "aws_db_parameter_group" "foo" {
|
|
name = "db-parameter-group-event-2"
|
|
family = "mysql5.6"
|
|
description = "Test parameter group for terraform"
|
|
}
|
|
|
|
resource "aws_db_event_subscription" "bar" {
|
|
name = "tf-acc-test-rds-event-subs-with-ids"
|
|
sns_topic = "${aws_sns_topic.aws_sns_topic.arn}"
|
|
source_type = "db-parameter-group"
|
|
source_ids = ["${aws_db_parameter_group.bar.id}","${aws_db_parameter_group.foo.id}"]
|
|
event_categories = [
|
|
"configuration change"
|
|
]
|
|
tags {
|
|
Name = "name"
|
|
}
|
|
}
|
|
`
|