Skip to content

Commit

Permalink
Merge pull request #15195 from terraform-providers/b-dynamodb-table-n…
Browse files Browse the repository at this point in the history
…on-key-attributes

resource/dynamodb_table: re-add logic to expand non_key_attributes configured in a TypeList
  • Loading branch information
anGie44 authored Sep 18, 2020
2 parents 019cdae + 068e368 commit cafbe02
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
68 changes: 68 additions & 0 deletions aws/resource_aws_dynamodb_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,40 @@ func TestAccAWSDynamoDbTable_gsiUpdateOtherAttributes(t *testing.T) {
})
}

// Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/15115
func TestAccAWSDynamoDbTable_lsiNonKeyAttributes(t *testing.T) {
var conf dynamodb.DescribeTableOutput
resourceName := "aws_dynamodb_table.test"
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDynamoDbTableDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSDynamoDbConfigLsiNonKeyAttributes(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckInitialAWSDynamoDbTableExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "local_secondary_index.#", "1"),
tfawsresource.TestCheckTypeSetElemNestedAttrs(resourceName, "local_secondary_index.*", map[string]string{
"name": "TestTableLSI",
"non_key_attributes.#": "1",
"non_key_attributes.0": "TestNonKeyAttribute",
"projection_type": "INCLUDE",
"range_key": "TestLSIRangeKey",
}),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

// https://github.com/terraform-providers/terraform-provider-aws/issues/566
func TestAccAWSDynamoDbTable_gsiUpdateNonKeyAttributes(t *testing.T) {
var conf dynamodb.DescribeTableOutput
Expand Down Expand Up @@ -2084,6 +2118,40 @@ resource "aws_dynamodb_table" "test" {
`, name, attributes)
}

func testAccAWSDynamoDbConfigLsiNonKeyAttributes(name string) string {
return fmt.Sprintf(`
resource "aws_dynamodb_table" "test" {
name = "%s"
hash_key = "TestTableHashKey"
range_key = "TestTableRangeKey"
write_capacity = 1
read_capacity = 1
attribute {
name = "TestTableHashKey"
type = "S"
}
attribute {
name = "TestTableRangeKey"
type = "S"
}
attribute {
name = "TestLSIRangeKey"
type = "N"
}
local_secondary_index {
name = "TestTableLSI"
range_key = "TestLSIRangeKey"
projection_type = "INCLUDE"
non_key_attributes = ["TestNonKeyAttribute"]
}
}
`, name)
}

func testAccAWSDynamoDbConfigTimeToLive(rName string, ttlEnabled bool) string {
return fmt.Sprintf(`
resource "aws_dynamodb_table" "test" {
Expand Down
4 changes: 4 additions & 0 deletions aws/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -4247,6 +4247,10 @@ func expandDynamoDbProjection(data map[string]interface{}) *dynamodb.Projection
ProjectionType: aws.String(data["projection_type"].(string)),
}

if v, ok := data["non_key_attributes"].([]interface{}); ok && len(v) > 0 {
projection.NonKeyAttributes = expandStringList(v)
}

if v, ok := data["non_key_attributes"].(*schema.Set); ok && v.Len() > 0 {
projection.NonKeyAttributes = expandStringList(v.List())
}
Expand Down

0 comments on commit cafbe02

Please sign in to comment.