Skip to content

Commit 7bba6bf

Browse files
authored
Merge pull request #43236 from shawnaws/f/ddb-mrsc
feat: Add support for DynamoDB Multi-Region Strong Consistency
2 parents d5c0e21 + e421c7f commit 7bba6bf

File tree

9 files changed

+2255
-110
lines changed

9 files changed

+2255
-110
lines changed

.changelog/43236.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/aws_dynamodb_table: Add `replica.consistency_mode` argument in support of [multi-Region strong consistency](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/V2globaltables_HowItWorks.html#V2globaltables_HowItWorks.choosing-consistency-mode) for Amazon DynamoDB global tables
3+
```

internal/acctest/acctest.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ const (
9797
// Provider name for third configuration testing
9898
ProviderNameThird = "awsthird"
9999

100+
// Provider name for fourth configuration testing
101+
ProviderNameFourth = "awsfourth"
102+
100103
ResourcePrefix = "tf-acc-test"
101104

102105
CertificateIssueTimeout = 5 * time.Minute
@@ -284,6 +287,8 @@ func ProtoV5FactoriesMultipleRegions(ctx context.Context, t *testing.T, n int) m
284287
return protoV5ProviderFactoriesInit(ctx, ProviderName, ProviderNameAlternate)
285288
case 3:
286289
return protoV5ProviderFactoriesInit(ctx, ProviderName, ProviderNameAlternate, ProviderNameThird)
290+
case 4:
291+
return protoV5ProviderFactoriesInit(ctx, ProviderName, ProviderNameAlternate, ProviderNameThird, ProviderNameFourth)
287292
default:
288293
t.Fatalf("invalid number of Region configurations: %d", n)
289294
}
@@ -917,6 +922,10 @@ func ThirdRegion() string {
917922
return envvar.GetWithDefault(envvar.ThirdRegion, endpoints.UsEast2RegionID)
918923
}
919924

925+
func FourthRegion() string {
926+
return envvar.GetWithDefault(envvar.FourthRegion, endpoints.UsWest1RegionID)
927+
}
928+
920929
func Partition() string {
921930
return names.PartitionForRegion(Region()).ID()
922931
}
@@ -941,6 +950,10 @@ func thirdRegionPartition() string {
941950
return names.PartitionForRegion(ThirdRegion()).ID()
942951
}
943952

953+
func fourthRegionPartition() string {
954+
return names.PartitionForRegion(FourthRegion()).ID()
955+
}
956+
944957
func PreCheckAlternateAccount(t *testing.T) {
945958
t.Helper()
946959

@@ -961,6 +974,17 @@ func PreCheckThirdAccount(t *testing.T) {
961974
}
962975
}
963976

977+
// add fourth region
978+
func PreCheckFourthAccount(t *testing.T) {
979+
t.Helper()
980+
981+
envvar.SkipIfAllEmpty(t, []string{envvar.FourthProfile, envvar.FourthAccessKeyId}, "credentials for running acceptance testing in fourth AWS account")
982+
983+
if os.Getenv(envvar.FourthAccessKeyId) != "" {
984+
envvar.SkipIfEmpty(t, envvar.FourthSecretAccessKey, "static credentials value when using "+envvar.FourthAccessKeyId)
985+
}
986+
}
987+
964988
func PreCheckPartitionHasService(t *testing.T, serviceID string) {
965989
t.Helper()
966990

@@ -1002,6 +1026,28 @@ func PreCheckMultipleRegion(t *testing.T, regions int) {
10021026
if Partition() != thirdRegionPartition() {
10031027
t.Fatalf("%s partition (%s) does not match %s partition (%s)", envvar.ThirdRegion, thirdRegionPartition(), envvar.DefaultRegion, Partition())
10041028
}
1029+
1030+
if regions == 4 {
1031+
if fourthRegionPartition() == endpoints.AwsUsGovPartitionID || Partition() == endpoints.AwsUsGovPartitionID {
1032+
t.Skipf("wanted %d regions, partition (%s) only has 2 regions", regions, Partition())
1033+
}
1034+
1035+
if Region() == FourthRegion() {
1036+
t.Fatalf("%s and %s must be set to different values for acceptance tests", envvar.DefaultRegion, envvar.FourthRegion)
1037+
}
1038+
1039+
if AlternateRegion() == FourthRegion() {
1040+
t.Fatalf("%s and %s must be set to different values for acceptance tests", envvar.AlternateRegion, envvar.FourthRegion)
1041+
}
1042+
1043+
if ThirdRegion() == FourthRegion() {
1044+
t.Fatalf("%s and %s must be set to different values for acceptance tests", envvar.ThirdRegion, envvar.FourthRegion)
1045+
}
1046+
1047+
if Partition() != fourthRegionPartition() {
1048+
t.Fatalf("%s partition (%s) does not match %s partition (%s)", envvar.FourthRegion, fourthRegionPartition(), envvar.DefaultRegion, Partition())
1049+
}
1050+
}
10051051
}
10061052

10071053
if partition, ok := endpoints.PartitionForRegion(endpoints.DefaultPartitions(), Region()); ok {
@@ -1047,6 +1093,15 @@ func PreCheckThirdRegion(t *testing.T, regions ...string) {
10471093
}
10481094
}
10491095

1096+
// PreCheckFourthRegion checks that the fourth test region is one of the specified AWS Regions.
1097+
func PreCheckFourthRegion(t *testing.T, regions ...string) {
1098+
t.Helper()
1099+
1100+
if curr := FourthRegion(); !slices.Contains(regions, curr) {
1101+
t.Skipf("skipping tests; %s (%s) not supported. Supported: [%s]", envvar.FourthRegion, curr, strings.Join(regions, ", "))
1102+
}
1103+
}
1104+
10501105
// PreCheckPartition checks that the test partition is the specified partition.
10511106
func PreCheckPartition(t *testing.T, partition string) {
10521107
t.Helper()

internal/acctest/configs.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ func ConfigMultipleAccountProvider(t *testing.T, accounts int) string {
6767
),
6868
)
6969
}
70+
if accounts == 4 {
71+
config.WriteString(
72+
ConfigNamedAccountProvider(
73+
ProviderNameFourth,
74+
os.Getenv(envvar.FourthAccessKeyId),
75+
os.Getenv(envvar.FourthProfile),
76+
os.Getenv(envvar.FourthSecretAccessKey),
77+
),
78+
)
79+
}
7080

7181
return config.String()
7282
}
@@ -95,10 +105,14 @@ func ConfigMultipleRegionProvider(regions int) string {
95105

96106
config.WriteString(ConfigNamedRegionalProvider(ProviderNameAlternate, AlternateRegion()))
97107

98-
if regions >= 3 {
108+
if regions == 3 {
99109
config.WriteString(ConfigNamedRegionalProvider(ProviderNameThird, ThirdRegion()))
100110
}
101111

112+
if regions == 4 {
113+
config.WriteString(ConfigNamedRegionalProvider(ProviderNameFourth, FourthRegion()))
114+
}
115+
102116
return config.String()
103117
}
104118

internal/acctest/knownvalue/regional_arn_exact.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,14 @@ func RegionalARNThirdRegionExact(service, resource string) knownvalue.Check {
7979
resource: resource,
8080
}
8181
}
82+
83+
// RegionalARNExact is a known value check that ensures the value is a string
84+
// that matches the expected ARN for the given service and resource.
85+
func RegionalARNFourthExact(service, resource string) knownvalue.Check {
86+
return regionalARNExact{
87+
check: "RegionalARNFourthRegionExact",
88+
region: acctest.FourthRegion(),
89+
service: service,
90+
resource: resource,
91+
}
92+
}

internal/acctest/knownvalue/regional_arn_regexp.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ func RegionalARNThirdRegionRegexp(service string, resource *regexp.Regexp) known
8686
}
8787
}
8888

89+
// RegionalARNFourthRegionRegexp
90+
func RegionalARNFourthRegionRegexp(service string, resource *regexp.Regexp) knownvalue.Check {
91+
return regionalARNRegexp{
92+
check: "RegionalARNFourthRegionRegexp",
93+
region: acctest.FourthRegion(),
94+
service: service,
95+
resourceRegexp: resource,
96+
}
97+
}
98+
8999
func RegionalARNRegexpRegion(service, region string, resource *regexp.Regexp) knownvalue.Check {
90100
return regionalARNRegexp{
91101
check: "RegionalARNRegexp",

internal/envvar/envvar.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ const (
6060
// For tests using a third AWS account, the equivalent of AWS_SECRET_ACCESS_KEY for that account
6161
ThirdSecretAccessKey = "AWS_THIRD_SECRET_ACCESS_KEY"
6262

63+
// For tests using a fourth AWS account, the equivalent of AWS_ACCESS_KEY_ID for that account
64+
FourthAccessKeyId = "AWS_FOURTH_ACCESS_KEY_ID"
65+
66+
// For tests using a fourth AWS account, the equivalent of AWS_PROFILE for that account
67+
FourthProfile = "AWS_FOURTH_PROFILE"
68+
69+
// For tests using a fourth AWS region, the equivalent of AWS_DEFAULT_REGION for that region
70+
FourthRegion = "AWS_FOURTH_REGION"
71+
72+
// For tests using a fourth AWS account, the equivalent of AWS_SECRET_ACCESS_KEY for that account
73+
FourthSecretAccessKey = "AWS_FOURTH_SECRET_ACCESS_KEY"
74+
6375
// For tests requiring GitHub permissions
6476
GithubToken = "GITHUB_TOKEN"
6577

0 commit comments

Comments
 (0)