Skip to content

Commit 98073e1

Browse files
authored
Merge pull request #41113 from Shion1305/f-aws_dynamodb_table-specify-name-for-gsi-flattenTableGlobalSecondaryIndex
fix(aws_dynamodb_table): Specify "name" for GlobalSecondaryIndex in `flattenTableGlobalSecondaryIndex`
2 parents 854bd97 + 5cde1f4 commit 98073e1

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

.changelog/41113.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/aws_dynamodb_table: Fix perpetual diff on `global_secondary_index` when using `ignore_changes` lifecycle meta-argument
3+
```

internal/service/dynamodb/table.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2608,10 +2608,11 @@ func flattenTableGlobalSecondaryIndex(gsi []awstypes.GlobalSecondaryIndexDescrip
26082608
for _, g := range gsi {
26092609
gsi := make(map[string]any)
26102610

2611+
gsi[names.AttrName] = aws.ToString(g.IndexName)
2612+
26112613
if g.ProvisionedThroughput != nil {
26122614
gsi["write_capacity"] = aws.ToInt64(g.ProvisionedThroughput.WriteCapacityUnits)
26132615
gsi["read_capacity"] = aws.ToInt64(g.ProvisionedThroughput.ReadCapacityUnits)
2614-
gsi[names.AttrName] = aws.ToString(g.IndexName)
26152616
}
26162617

26172618
for _, attribute := range g.KeySchema {

internal/service/dynamodb/table_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,7 @@ func TestAccDynamoDBTable_BillingMode_payPerRequestBasic(t *testing.T) {
11761176
resource.TestCheckResourceAttr(resourceName, "billing_mode", string(awstypes.BillingModePayPerRequest)),
11771177
resource.TestCheckResourceAttr(resourceName, "read_capacity", "0"),
11781178
resource.TestCheckResourceAttr(resourceName, "write_capacity", "0"),
1179+
resource.TestCheckResourceAttr(resourceName, "global_secondary_index.#", "0"),
11791180
),
11801181
},
11811182
{
@@ -1190,6 +1191,10 @@ func TestAccDynamoDBTable_BillingMode_payPerRequestBasic(t *testing.T) {
11901191
resource.TestCheckResourceAttr(resourceName, "billing_mode", string(awstypes.BillingModePayPerRequest)),
11911192
resource.TestCheckResourceAttr(resourceName, "read_capacity", "0"),
11921193
resource.TestCheckResourceAttr(resourceName, "write_capacity", "0"),
1194+
resource.TestCheckResourceAttr(resourceName, "global_secondary_index.#", "1"),
1195+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "global_secondary_index.*", map[string]string{
1196+
names.AttrName: "TestTableGSI",
1197+
}),
11931198
),
11941199
},
11951200
},
@@ -1275,6 +1280,7 @@ func TestAccDynamoDBTable_gsiOnDemandThroughput(t *testing.T) {
12751280
testAccCheckInitialTableExists(ctx, resourceName, &conf),
12761281
resource.TestCheckResourceAttr(resourceName, "billing_mode", string(awstypes.BillingModePayPerRequest)),
12771282
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "global_secondary_index.*", map[string]string{
1283+
names.AttrName: "att1-index",
12781284
"on_demand_throughput.0.max_read_request_units": "5",
12791285
"on_demand_throughput.0.max_write_request_units": "5",
12801286
}),
@@ -1292,6 +1298,7 @@ func TestAccDynamoDBTable_gsiOnDemandThroughput(t *testing.T) {
12921298
resource.TestCheckResourceAttr(resourceName, "billing_mode", string(awstypes.BillingModePayPerRequest)),
12931299
resource.TestCheckResourceAttr(resourceName, "on_demand_throughput.#", "1"),
12941300
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "global_secondary_index.*", map[string]string{
1301+
names.AttrName: "att1-index",
12951302
"on_demand_throughput.0.max_read_request_units": "10",
12961303
"on_demand_throughput.0.max_write_request_units": "10",
12971304
}),

0 commit comments

Comments
 (0)