From 068e368949cc9570d972b19d52f1ac2be8781c28 Mon Sep 17 00:00:00 2001 From: Angie Pinilla Date: Wed, 16 Sep 2020 23:18:25 -0400 Subject: [PATCH] re-add logic to expand non_key_attributes configured in a TypeList --- aws/resource_aws_dynamodb_table_test.go | 68 +++++++++++++++++++++++++ aws/structure.go | 4 ++ 2 files changed, 72 insertions(+) diff --git a/aws/resource_aws_dynamodb_table_test.go b/aws/resource_aws_dynamodb_table_test.go index 3856c431aac2..ad6f564f0957 100644 --- a/aws/resource_aws_dynamodb_table_test.go +++ b/aws/resource_aws_dynamodb_table_test.go @@ -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 @@ -2053,6 +2087,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" { diff --git a/aws/structure.go b/aws/structure.go index c28ba23e1662..585ef1a7b645 100644 --- a/aws/structure.go +++ b/aws/structure.go @@ -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()) }