Skip to content

Commit

Permalink
Merge pull request #25796 from bschaatsbergen/e/add-custom-timeout-bl…
Browse files Browse the repository at this point in the history
…ock-to-automated-instance-backups-rds-25776

Add custom timeout block to `aws_db_instance_automated_backups_replication`
  • Loading branch information
ewbankkit committed Jul 15, 2022
2 parents 518f833 + 03d4e71 commit 162887a
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 36 deletions.
3 changes: 3 additions & 0 deletions .changelog/25796.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_db_instance_automated_backups_replication: Add support for custom timeouts (create and delete)
```
11 changes: 11 additions & 0 deletions internal/service/rds/instance_automated_backups_replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
},
Expand Down
92 changes: 56 additions & 36 deletions internal/service/rds/instance_automated_backups_replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.,
Expand Down

0 comments on commit 162887a

Please sign in to comment.