diff --git a/.changelog/25796.txt b/.changelog/25796.txt new file mode 100644 index 000000000000..5cd5349582db --- /dev/null +++ b/.changelog/25796.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_db_instance_automated_backups_replication: Add support for custom timeouts (create and delete) +``` diff --git a/internal/service/rds/instance_automated_backups_replication.go b/internal/service/rds/instance_automated_backups_replication.go index 2e1840eeae4f..5aa39532035e 100644 --- a/internal/service/rds/instance_automated_backups_replication.go +++ b/internal/service/rds/instance_automated_backups_replication.go @@ -3,6 +3,7 @@ package rds import ( "fmt" "log" + "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/arn" @@ -13,12 +14,22 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/verify" ) +const ( + InstanceAutomatedBackupsReplicationCreateTimeout = 75 * time.Minute + InstanceAutomatedBackupsReplicationDeleteTimeout = 75 * time.Minute +) + func ResourceInstanceAutomatedBackupsReplication() *schema.Resource { return &schema.Resource{ Create: resourceInstanceAutomatedBackupsReplicationCreate, Read: resourceInstanceAutomatedBackupsReplicationRead, Delete: resourceInstanceAutomatedBackupsReplicationDelete, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(InstanceAutomatedBackupsReplicationCreateTimeout), + Delete: schema.DefaultTimeout(InstanceAutomatedBackupsReplicationDeleteTimeout), + }, + Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, diff --git a/internal/service/rds/instance_automated_backups_replication_test.go b/internal/service/rds/instance_automated_backups_replication_test.go index 73e11092d987..735eee2b0441 100644 --- a/internal/service/rds/instance_automated_backups_replication_test.go +++ b/internal/service/rds/instance_automated_backups_replication_test.go @@ -119,32 +119,54 @@ func TestAccRDSInstanceAutomatedBackupsReplication_kmsEncrypted(t *testing.T) { }, }) } - -func testAccInstanceAutomatedBackupsReplicationConfig_basic(rName string) string { +func testAccInstanceAutomatedBackupsReplicationConfig_base(rName string, storageEncrypted bool) string { return acctest.ConfigCompose(acctest.ConfigMultipleRegionProvider(2), fmt.Sprintf(` -resource "aws_db_instance" "test" { - allocated_storage = 10 - identifier = %[1]q - engine = "postgres" - engine_version = "13.4" - instance_class = "db.t3.micro" - name = "mydb" - username = "masterusername" - password = "mustbeeightcharacters" - backup_retention_period = 7 - skip_final_snapshot = true +data "aws_availability_zones" "available" { + state = "available" + + filter { + name = "opt-in-status" + values = ["opt-in-not-required"] + } provider = "awsalternate" } -resource "aws_db_instance_automated_backups_replication" "test" { - source_db_instance_arn = aws_db_instance.test.arn +resource "aws_vpc" "test" { + cidr_block = "10.1.0.0/16" + + tags = { + Name = %[1]q + } + + provider = "awsalternate" } -`, rName)) + +resource "aws_subnet" "test" { + count = 2 + + cidr_block = "10.1.${count.index}.0/24" + availability_zone = data.aws_availability_zones.available.names[count.index] + vpc_id = aws_vpc.test.id + + tags = { + Name = %[1]q + } + + provider = "awsalternate" +} + +resource "aws_db_subnet_group" "test" { + name = %[1]q + subnet_ids = aws_subnet.test[*].id + + tags = { + Name = %[1]q + } + + provider = "awsalternate" } -func testAccInstanceAutomatedBackupsReplicationConfig_retentionPeriod(rName string) string { - return acctest.ConfigCompose(acctest.ConfigMultipleRegionProvider(2), fmt.Sprintf(` resource "aws_db_instance" "test" { allocated_storage = 10 identifier = %[1]q @@ -156,39 +178,37 @@ resource "aws_db_instance" "test" { password = "mustbeeightcharacters" backup_retention_period = 7 skip_final_snapshot = true + storage_encrypted = %[2]t + db_subnet_group_name = aws_db_subnet_group.test.name provider = "awsalternate" } +`, rName, storageEncrypted)) +} + +func testAccInstanceAutomatedBackupsReplicationConfig_basic(rName string) string { + return acctest.ConfigCompose(testAccInstanceAutomatedBackupsReplicationConfig_base(rName, false), ` +resource "aws_db_instance_automated_backups_replication" "test" { + source_db_instance_arn = aws_db_instance.test.arn +} +`) +} +func testAccInstanceAutomatedBackupsReplicationConfig_retentionPeriod(rName string) string { + return acctest.ConfigCompose(testAccInstanceAutomatedBackupsReplicationConfig_base(rName, false), ` resource "aws_db_instance_automated_backups_replication" "test" { source_db_instance_arn = aws_db_instance.test.arn retention_period = 14 } -`, rName)) +`) } func testAccInstanceAutomatedBackupsReplicationConfig_kmsEncrypted(rName string) string { - return acctest.ConfigCompose(acctest.ConfigMultipleRegionProvider(2), fmt.Sprintf(` + return acctest.ConfigCompose(testAccInstanceAutomatedBackupsReplicationConfig_base(rName, true), fmt.Sprintf(` resource "aws_kms_key" "test" { description = %[1]q } -resource "aws_db_instance" "test" { - allocated_storage = 10 - identifier = %[1]q - engine = "postgres" - engine_version = "13.4" - instance_class = "db.t3.micro" - name = "mydb" - username = "masterusername" - password = "mustbeeightcharacters" - backup_retention_period = 7 - storage_encrypted = true - skip_final_snapshot = true - - provider = "awsalternate" -} - resource "aws_db_instance_automated_backups_replication" "test" { source_db_instance_arn = aws_db_instance.test.arn kms_key_id = aws_kms_key.test.arn diff --git a/website/docs/r/db_instance_automated_backups_replication.markdown b/website/docs/r/db_instance_automated_backups_replication.markdown index 20f9129972e4..3c7b913b5273 100644 --- a/website/docs/r/db_instance_automated_backups_replication.markdown +++ b/website/docs/r/db_instance_automated_backups_replication.markdown @@ -87,6 +87,14 @@ In addition to all arguments above, the following attributes are exported: * `id` - The Amazon Resource Name (ARN) of the replicated automated backups. +## Timeouts + +`aws_db_instance_automated_backups_replication` provides the following [Timeouts](https://www.terraform.io/docs/configuration/blocks/resources/syntax.html#operation-timeouts) +configuration options: + +- `create` - (Default `75m`) How long to wait before RDS successfully starts replication of automated backups to a different AWS Region. +- `delete` - (Default `75m`) How long to wait before RDS stops automated backup replication for a DB instance. + ## Import RDS instance automated backups replication can be imported using the `arn`, e.g.,