diff --git a/aws/data_source_aws_db_instance_test.go b/aws/data_source_aws_db_instance_test.go index 4c33b5add96..17a7ac50e06 100644 --- a/aws/data_source_aws_db_instance_test.go +++ b/aws/data_source_aws_db_instance_test.go @@ -42,8 +42,11 @@ func TestAccAWSDbInstanceDataSource_basic(t *testing.T) { } func TestAccAWSDbInstanceDataSource_ec2Classic(t *testing.T) { + hardcodedRegion := "us-east-1" // lintignore:AWSAT003 + testAccReachableRegionPreCheck(hardcodedRegion, t) + oldvar := os.Getenv("AWS_DEFAULT_REGION") - os.Setenv("AWS_DEFAULT_REGION", "us-east-1") + os.Setenv("AWS_DEFAULT_REGION", hardcodedRegion) defer os.Setenv("AWS_DEFAULT_REGION", oldvar) rInt := acctest.RandInt() diff --git a/aws/provider_test.go b/aws/provider_test.go index 763afb1c7eb..0ee2611ca17 100644 --- a/aws/provider_test.go +++ b/aws/provider_test.go @@ -528,6 +528,15 @@ func testAccEC2ClassicPreCheck(t *testing.T) { } } +// testAccReachableRegionPreCheck checks whether the partition of the current region includes the given region +func testAccReachableRegionPreCheck(region string, t *testing.T) { + if partition, ok := endpoints.PartitionForRegion(endpoints.DefaultPartitions(), testAccGetRegion()); ok { + if _, ok := partition.Regions()[region]; !ok { + t.Skip(fmt.Sprintf("skipping test; partition %s does not have %s region", partition.ID(), region)) + } + } +} + func testAccEC2VPCOnlyPreCheck(t *testing.T) { client := testAccProvider.Meta().(*AWSClient) platforms := client.supportedplatforms diff --git a/aws/resource_aws_db_instance_test.go b/aws/resource_aws_db_instance_test.go index 8e1e0fb4730..87304fffb9d 100644 --- a/aws/resource_aws_db_instance_test.go +++ b/aws/resource_aws_db_instance_test.go @@ -2234,12 +2234,14 @@ func TestAccAWSDBInstance_MinorVersion(t *testing.T) { } func TestAccAWSDBInstance_ec2Classic(t *testing.T) { - var v rds.DBInstance + hardcodedRegion := "us-east-1" // lintignore:AWSAT003 + testAccReachableRegionPreCheck(hardcodedRegion, t) oldvar := os.Getenv("AWS_DEFAULT_REGION") - os.Setenv("AWS_DEFAULT_REGION", "us-east-1") + os.Setenv("AWS_DEFAULT_REGION", hardcodedRegion) defer os.Setenv("AWS_DEFAULT_REGION", oldvar) + var v rds.DBInstance rInt := acctest.RandInt() resource.ParallelTest(t, resource.TestCase{ @@ -3239,6 +3241,8 @@ resource "aws_s3_bucket_object" "xtrabackup_db" { etag = filemd5("./testdata/mysql-5-6-xtrabackup.tar.gz") } +data "aws_partition" "current" {} + resource "aws_iam_role" "rds_s3_access_role" { name = "%[3]s-role" @@ -3250,7 +3254,7 @@ resource "aws_iam_role" "rds_s3_access_role" { "Sid": "", "Effect": "Allow", "Principal": { - "Service": "rds.amazonaws.com" + "Service": "rds.${data.aws_partition.current.dns_suffix}" }, "Action": "sts:AssumeRole" } @@ -3399,8 +3403,7 @@ resource "aws_db_instance" "snapshot" { func testAccAWSDbInstanceConfig_MonitoringInterval(rName string, monitoringInterval int) string { return fmt.Sprintf(` -data "aws_partition" "current" { -} +data "aws_partition" "current" {} resource "aws_iam_role" "test" { name = %[1]q @@ -3413,7 +3416,7 @@ resource "aws_iam_role" "test" { "Sid": "", "Effect": "Allow", "Principal": { - "Service": "monitoring.rds.amazonaws.com" + "Service": "monitoring.rds.${data.aws_partition.current.dns_suffix}" }, "Action": "sts:AssumeRole" } @@ -3491,8 +3494,7 @@ resource "aws_db_instance" "test" { func testAccAWSDbInstanceConfig_MonitoringRoleArn(rName string) string { return fmt.Sprintf(` -data "aws_partition" "current" { -} +data "aws_partition" "current" {} resource "aws_iam_role" "test" { name = %[1]q @@ -3505,7 +3507,7 @@ resource "aws_iam_role" "test" { "Sid": "", "Effect": "Allow", "Principal": { - "Service": "monitoring.rds.amazonaws.com" + "Service": "monitoring.rds.${data.aws_partition.current.dns_suffix}" }, "Action": "sts:AssumeRole" } @@ -4047,6 +4049,8 @@ resource "aws_directory_service_directory" "bar" { } } +data "aws_partition" "current" {} + resource "aws_iam_role" "role" { name = "tf-acc-db-instance-mssql-domain-role-%[1]d" @@ -4057,7 +4061,7 @@ resource "aws_iam_role" "role" { { "Action": "sts:AssumeRole", "Principal": { - "Service": "rds.amazonaws.com" + "Service": "rds.${data.aws_partition.current.dns_suffix}" }, "Effect": "Allow", "Sid": "" @@ -4069,7 +4073,7 @@ EOF resource "aws_iam_role_policy_attachment" "attatch-policy" { role = aws_iam_role.role.name - policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonRDSDirectoryServiceAccess" + policy_arn = "arn:${data.aws_partition.current.partition}:iam::aws:policy/service-role/AmazonRDSDirectoryServiceAccess" } `, rInt)) } @@ -4176,6 +4180,8 @@ resource "aws_directory_service_directory" "bar" { } } +data "aws_partition" "current" {} + resource "aws_iam_role" "role" { name = "tf-acc-db-instance-mssql-domain-role-%[1]d" @@ -4186,7 +4192,7 @@ resource "aws_iam_role" "role" { { "Action": "sts:AssumeRole", "Principal": { - "Service": "rds.amazonaws.com" + "Service": "rds.${data.aws_partition.current.dns_suffix}" }, "Effect": "Allow", "Sid": "" @@ -4198,7 +4204,7 @@ EOF resource "aws_iam_role_policy_attachment" "attatch-policy" { role = aws_iam_role.role.name - policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonRDSDirectoryServiceAccess" + policy_arn = "arn:${data.aws_partition.current.partition}:iam::aws:policy/service-role/AmazonRDSDirectoryServiceAccess" } `, rInt)) } @@ -4309,6 +4315,8 @@ resource "aws_directory_service_directory" "foo" { } } +data "aws_partition" "current" {} + resource "aws_iam_role" "role" { name = "tf-acc-db-instance-mssql-domain-role-%[1]d" @@ -4319,7 +4327,7 @@ resource "aws_iam_role" "role" { { "Action": "sts:AssumeRole", "Principal": { - "Service": "rds.amazonaws.com" + "Service": "rds.${data.aws_partition.current.dns_suffix}" }, "Effect": "Allow", "Sid": "" @@ -4331,7 +4339,7 @@ EOF resource "aws_iam_role_policy_attachment" "attatch-policy" { role = aws_iam_role.role.name - policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonRDSDirectoryServiceAccess" + policy_arn = "arn:${data.aws_partition.current.partition}:iam::aws:policy/service-role/AmazonRDSDirectoryServiceAccess" } `, rInt)) } @@ -5673,8 +5681,7 @@ resource "aws_db_instance" "test" { func testAccAWSDBInstanceConfig_ReplicateSourceDb_Monitoring(rName string, monitoringInterval int) string { return composeConfig(testAccAWSDBInstanceConfig_orderableClassMysql(), fmt.Sprintf(` -data "aws_partition" "current" { -} +data "aws_partition" "current" {} resource "aws_iam_role" "test" { name = %[1]q @@ -5687,7 +5694,7 @@ resource "aws_iam_role" "test" { "Sid": "", "Effect": "Allow", "Principal": { - "Service": "monitoring.rds.amazonaws.com" + "Service": "monitoring.rds.${data.aws_partition.current.dns_suffix}" }, "Action": "sts:AssumeRole" } @@ -6472,8 +6479,7 @@ resource "aws_db_instance" "test" { func testAccAWSDBInstanceConfig_SnapshotIdentifier_Monitoring(rName string, monitoringInterval int) string { return composeConfig(testAccAWSDBInstanceConfig_orderableClassMariadb(), fmt.Sprintf(` -data "aws_partition" "current" { -} +data "aws_partition" "current" {} resource "aws_iam_role" "test" { name = %[1]q @@ -6486,7 +6492,7 @@ resource "aws_iam_role" "test" { "Sid": "", "Effect": "Allow", "Principal": { - "Service": "monitoring.rds.amazonaws.com" + "Service": "monitoring.rds.${data.aws_partition.current.dns_suffix}" }, "Action": "sts:AssumeRole" } diff --git a/aws/resource_aws_db_option_group_test.go b/aws/resource_aws_db_option_group_test.go index a7b9d506e09..12f70cec257 100644 --- a/aws/resource_aws_db_option_group_test.go +++ b/aws/resource_aws_db_option_group_test.go @@ -360,14 +360,14 @@ func TestAccAWSDBOptionGroup_OracleOptionsUpdate(t *testing.T) { CheckDestroy: testAccCheckAWSDBOptionGroupDestroy, Steps: []resource.TestStep{ { - Config: testAccAWSDBOptionGroupOracleEEOptionSettings(rName, "12.1.0.4.v1"), + Config: testAccAWSDBOptionGroupOracleEEOptionSettings(rName, "13.2.0.0.v2"), Check: resource.ComposeTestCheckFunc( testAccCheckAWSDBOptionGroupExists("aws_db_option_group.bar", &v), resource.TestCheckResourceAttr( "aws_db_option_group.bar", "name", rName), resource.TestCheckResourceAttr( "aws_db_option_group.bar", "option.#", "1"), - testAccCheckAWSDBOptionGroupOptionVersionAttribute(&v, "12.1.0.4.v1"), + testAccCheckAWSDBOptionGroupOptionVersionAttribute(&v, "13.2.0.0.v2"), ), }, { @@ -378,14 +378,14 @@ func TestAccAWSDBOptionGroup_OracleOptionsUpdate(t *testing.T) { ImportStateVerifyIgnore: []string{"name_prefix", "option"}, }, { - Config: testAccAWSDBOptionGroupOracleEEOptionSettings(rName, "12.1.0.5.v1"), + Config: testAccAWSDBOptionGroupOracleEEOptionSettings(rName, "13.3.0.0.v2"), Check: resource.ComposeTestCheckFunc( testAccCheckAWSDBOptionGroupExists("aws_db_option_group.bar", &v), resource.TestCheckResourceAttr( "aws_db_option_group.bar", "name", rName), resource.TestCheckResourceAttr( "aws_db_option_group.bar", "option.#", "1"), - testAccCheckAWSDBOptionGroupOptionVersionAttribute(&v, "12.1.0.5.v1"), + testAccCheckAWSDBOptionGroupOptionVersionAttribute(&v, "13.3.0.0.v2"), ), }, }, @@ -568,7 +568,7 @@ func testAccCheckAWSDBOptionGroupOptionSettingsIAMRole(optionGroup *rds.OptionGr } settingValue := aws.StringValue(optionGroup.Options[0].OptionSettings[0].Value) - iamArnRegExp := regexp.MustCompile(`^arn:aws:iam::\d{12}:role/.+`) + iamArnRegExp := regexp.MustCompile(fmt.Sprintf(`^arn:%s:iam::\d{12}:role/.+`, testAccGetPartition())) if !iamArnRegExp.MatchString(settingValue) { return fmt.Errorf("Expected option setting to be a valid IAM role but received %s", settingValue) } @@ -733,24 +733,26 @@ resource "aws_db_option_group" "bar" { func testAccAWSDBOptionGroupOptionSettingsIAMRole(r string) string { return fmt.Sprintf(` +data "aws_partition" "current" {} + data "aws_iam_policy_document" "rds_assume_role" { statement { actions = ["sts:AssumeRole"] principals { type = "Service" - identifiers = ["rds.amazonaws.com"] + identifiers = ["rds.${data.aws_partition.current.dns_suffix}"] } } } resource "aws_iam_role" "sql_server_backup" { - name = "rds-backup-%s" + name = "rds-backup-%[1]s" assume_role_policy = data.aws_iam_policy_document.rds_assume_role.json } resource "aws_db_option_group" "bar" { - name = "%s" + name = "%[1]s" option_group_description = "Test option group for terraform" engine_name = "sqlserver-ex" major_engine_version = "14.00" @@ -764,7 +766,7 @@ resource "aws_db_option_group" "bar" { } } } -`, r, r) +`, r) } func testAccAWSDBOptionGroupOptionSettings_update(r string) string { diff --git a/aws/resource_aws_db_security_group_test.go b/aws/resource_aws_db_security_group_test.go index d82871b1e5b..e4899eae86f 100644 --- a/aws/resource_aws_db_security_group_test.go +++ b/aws/resource_aws_db_security_group_test.go @@ -16,11 +16,14 @@ import ( ) func TestAccAWSDBSecurityGroup_basic(t *testing.T) { - var v rds.DBSecurityGroup + hardcodedRegion := "us-east-1" // lintignore:AWSAT003 + testAccReachableRegionPreCheck(hardcodedRegion, t) oldvar := os.Getenv("AWS_DEFAULT_REGION") - os.Setenv("AWS_DEFAULT_REGION", "us-east-1") + os.Setenv("AWS_DEFAULT_REGION", hardcodedRegion) defer os.Setenv("AWS_DEFAULT_REGION", oldvar) + + var v rds.DBSecurityGroup resourceName := "aws_db_security_group.test" rName := fmt.Sprintf("tf-acc-%s", acctest.RandString(5))