Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/dynamodb_table: re-add logic to expand non_key_attributes configured in a TypeList #15195

Merged
merged 1 commit into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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" {
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