Skip to content

Commit cafbe02

Browse files
authored
Merge pull request #15195 from terraform-providers/b-dynamodb-table-non-key-attributes
resource/dynamodb_table: re-add logic to expand non_key_attributes configured in a TypeList
2 parents 019cdae + 068e368 commit cafbe02

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

aws/resource_aws_dynamodb_table_test.go

+68
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,40 @@ func TestAccAWSDynamoDbTable_gsiUpdateOtherAttributes(t *testing.T) {
902902
})
903903
}
904904

905+
// Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/15115
906+
func TestAccAWSDynamoDbTable_lsiNonKeyAttributes(t *testing.T) {
907+
var conf dynamodb.DescribeTableOutput
908+
resourceName := "aws_dynamodb_table.test"
909+
rName := acctest.RandomWithPrefix("tf-acc-test")
910+
911+
resource.ParallelTest(t, resource.TestCase{
912+
PreCheck: func() { testAccPreCheck(t) },
913+
Providers: testAccProviders,
914+
CheckDestroy: testAccCheckAWSDynamoDbTableDestroy,
915+
Steps: []resource.TestStep{
916+
{
917+
Config: testAccAWSDynamoDbConfigLsiNonKeyAttributes(rName),
918+
Check: resource.ComposeTestCheckFunc(
919+
testAccCheckInitialAWSDynamoDbTableExists(resourceName, &conf),
920+
resource.TestCheckResourceAttr(resourceName, "local_secondary_index.#", "1"),
921+
tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "local_secondary_index.*", map[string]string{
922+
"name": "TestTableLSI",
923+
"non_key_attributes.#": "1",
924+
"non_key_attributes.0": "TestNonKeyAttribute",
925+
"projection_type": "INCLUDE",
926+
"range_key": "TestLSIRangeKey",
927+
}),
928+
),
929+
},
930+
{
931+
ResourceName: resourceName,
932+
ImportState: true,
933+
ImportStateVerify: true,
934+
},
935+
},
936+
})
937+
}
938+
905939
// https://github.com/terraform-providers/terraform-provider-aws/issues/566
906940
func TestAccAWSDynamoDbTable_gsiUpdateNonKeyAttributes(t *testing.T) {
907941
var conf dynamodb.DescribeTableOutput
@@ -2084,6 +2118,40 @@ resource "aws_dynamodb_table" "test" {
20842118
`, name, attributes)
20852119
}
20862120

2121+
func testAccAWSDynamoDbConfigLsiNonKeyAttributes(name string) string {
2122+
return fmt.Sprintf(`
2123+
resource "aws_dynamodb_table" "test" {
2124+
name = "%s"
2125+
hash_key = "TestTableHashKey"
2126+
range_key = "TestTableRangeKey"
2127+
write_capacity = 1
2128+
read_capacity = 1
2129+
2130+
attribute {
2131+
name = "TestTableHashKey"
2132+
type = "S"
2133+
}
2134+
2135+
attribute {
2136+
name = "TestTableRangeKey"
2137+
type = "S"
2138+
}
2139+
2140+
attribute {
2141+
name = "TestLSIRangeKey"
2142+
type = "N"
2143+
}
2144+
2145+
local_secondary_index {
2146+
name = "TestTableLSI"
2147+
range_key = "TestLSIRangeKey"
2148+
projection_type = "INCLUDE"
2149+
non_key_attributes = ["TestNonKeyAttribute"]
2150+
}
2151+
}
2152+
`, name)
2153+
}
2154+
20872155
func testAccAWSDynamoDbConfigTimeToLive(rName string, ttlEnabled bool) string {
20882156
return fmt.Sprintf(`
20892157
resource "aws_dynamodb_table" "test" {

aws/structure.go

+4
Original file line numberDiff line numberDiff line change
@@ -4247,6 +4247,10 @@ func expandDynamoDbProjection(data map[string]interface{}) *dynamodb.Projection
42474247
ProjectionType: aws.String(data["projection_type"].(string)),
42484248
}
42494249

4250+
if v, ok := data["non_key_attributes"].([]interface{}); ok && len(v) > 0 {
4251+
projection.NonKeyAttributes = expandStringList(v)
4252+
}
4253+
42504254
if v, ok := data["non_key_attributes"].(*schema.Set); ok && v.Len() > 0 {
42514255
projection.NonKeyAttributes = expandStringList(v.List())
42524256
}

0 commit comments

Comments
 (0)