Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/aws_ db_cluster: add read replica to domain on create #39448

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/39448.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_db_instance: Allow replica database to be added to domain on create
```
24 changes: 24 additions & 0 deletions internal/service/rds/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,30 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, meta in
input.DedicatedLogVolume = aws.Bool(v.(bool))
}

if v, ok := d.GetOk(names.AttrDomain); ok {
input.Domain = aws.String(v.(string))
}

if v, ok := d.GetOk("domain_auth_secret_arn"); ok {
input.DomainAuthSecretArn = aws.String(v.(string))
}

if v, ok := d.GetOk("domain_dns_ips"); ok && len(v.([]interface{})) > 0 {
input.DomainDnsIps = flex.ExpandStringValueList(v.([]interface{}))
}

if v, ok := d.GetOk("domain_fqdn"); ok {
input.DomainFqdn = aws.String(v.(string))
}

if v, ok := d.GetOk("domain_iam_role_name"); ok {
input.DomainIAMRoleName = aws.String(v.(string))
}

if v, ok := d.GetOk("domain_ou"); ok {
input.DomainOu = aws.String(v.(string))
}

if v, ok := d.GetOk("enabled_cloudwatch_logs_exports"); ok && v.(*schema.Set).Len() > 0 {
input.EnableCloudwatchLogsExports = flex.ExpandStringValueSet(v.(*schema.Set))
}
Expand Down
123 changes: 123 additions & 0 deletions internal/service/rds/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2374,6 +2374,51 @@ func TestAccRDSInstance_ReplicateSourceDB_CrossRegion_characterSet(t *testing.T)
})
}

func TestAccRDSInstance_ReplicateSourceDB_mssqlDomain(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

var dbInstance, sourceDbInstance types.DBInstance

rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
sourceResourceName := "aws_db_instance.source"
resourceName := "aws_db_instance.test"

domain := acctest.RandomDomain().String()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.RDSServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDBInstanceDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccInstanceConfig_ReplicateSourceDB_mssqlDomain(rName, domain),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckDBInstanceExists(ctx, sourceResourceName, &sourceDbInstance),
testAccCheckDBInstanceExists(ctx, resourceName, &dbInstance),
resource.TestCheckResourceAttr(resourceName, names.AttrIdentifier, rName),
testAccCheckInstanceReplicaAttributes(&sourceDbInstance, &dbInstance),
resource.TestCheckResourceAttrPair(resourceName, "replicate_source_db", sourceResourceName, names.AttrIdentifier),
resource.TestCheckResourceAttrPair(resourceName, names.AttrUsername, sourceResourceName, names.AttrUsername),
resource.TestCheckResourceAttrPair(resourceName, names.AttrDomain, sourceResourceName, names.AttrDomain),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
names.AttrApplyImmediately,
names.AttrPassword,
},
},
},
})
}

func TestAccRDSInstance_s3Import(t *testing.T) {
acctest.Skip(t, "RestoreDBInstanceFromS3 cannot restore from MySQL version 5.6")

Expand Down Expand Up @@ -6707,6 +6752,9 @@ func testAccInstanceConfig_orderableClassSQLServerExGP3() string {
func testAccInstanceConfig_orderableClassSQLServerSe() string {
return testAccInstanceConfig_orderableClass(tfrds.InstanceEngineSQLServerStandard, "license-included", "standard")
}
func testAccInstanceConfig_orderableClassSQLServerEE() string {
return testAccInstanceConfig_orderableClass(tfrds.InstanceEngineSQLServerEnterprise, "license-included", "standard")
}

func testAccInstanceConfig_orderableClassCustomSQLServerWeb() string {
return testAccInstanceConfig_orderableClass("custom-sqlserver-web", "", "gp2")
Expand Down Expand Up @@ -9214,6 +9262,81 @@ resource "aws_db_instance" "test" {
`, rName, tfrds.InstanceEngineMySQL, mainInstanceClasses))
}

func testAccInstanceConfig_baseMSSQLEnterpriseDomain(rName, domain string) string {
return acctest.ConfigCompose(
testAccInstanceConfig_orderableClassSQLServerEE(),
testAccInstanceConfig_baseVPC(rName),
testAccInstanceConfig_ServiceRole(rName),
fmt.Sprintf(`
resource "aws_security_group" "test" {
name = %[1]q
vpc_id = aws_vpc.test.id

tags = {
Name = %[1]q
}
}

resource "aws_security_group_rule" "test" {
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]

security_group_id = aws_security_group.test.id
}

resource "aws_directory_service_directory" "directory" {
name = %[2]q
password = "SuperSecretPassw0rd"
type = "MicrosoftAD"
edition = "Standard"

vpc_settings {
vpc_id = aws_vpc.test.id
subnet_ids = aws_subnet.test[*].id
}
}

data "aws_partition" "current" {}
`, rName, domain))
}

func testAccInstanceConfig_ReplicateSourceDB_mssqlDomain(rName, domain string) string {
return acctest.ConfigCompose(
testAccInstanceConfig_baseMSSQLEnterpriseDomain(rName, domain),
fmt.Sprintf(`
resource "aws_db_instance" "source" {
allocated_storage = 20
backup_retention_period = 1
db_subnet_group_name = aws_db_subnet_group.test.name
engine = data.aws_rds_orderable_db_instance.test.engine
engine_version = data.aws_rds_orderable_db_instance.test.engine_version
identifier = "%[1]s-source"
instance_class = data.aws_rds_orderable_db_instance.test.instance_class
license_model = "license-included"
skip_final_snapshot = true
password = "avoid-plaintext-passwords"
username = "tfacctest"

domain = aws_directory_service_directory.directory.id
domain_iam_role_name = aws_iam_role.role.name
}

resource "aws_db_instance" "test" {
identifier = %[1]q
instance_class = aws_db_instance.source.instance_class
replicate_source_db = aws_db_instance.source.identifier
license_model = "license-included"
skip_final_snapshot = true

domain = aws_directory_service_directory.directory.id
domain_iam_role_name = aws_iam_role.role.name
}
`, rName))
}

// When testing needs to distinguish a second region and second account in the same region
// e.g. cross-region functionality with RAM shared subnets
func testAccAlternateAccountAndAlternateRegionProviderConfig() string {
Expand Down
Loading