Skip to content

Commit

Permalink
Replace DyanmoDB table when local secondary index changes (hashicorp#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tjoris committed Mar 12, 2020
1 parent 06cf236 commit 863e24d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
4 changes: 4 additions & 0 deletions aws/resource_aws_dynamodb_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,22 @@ func resourceAwsDynamoDbTable() *schema.Resource {
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"range_key": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"projection_type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"non_key_attributes": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
Expand Down
64 changes: 64 additions & 0 deletions aws/resource_aws_dynamodb_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,37 @@ func TestAccAWSDynamoDbTable_attributeUpdate(t *testing.T) {
})
}

func TestAccAWSDynamoDbTable_lsiUpdate(t *testing.T) {
var conf dynamodb.DescribeTableOutput
resourceName := "aws_dynamodb_table.test"
rName := acctest.RandomWithPrefix("TerraformTestTable-")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDynamoDbTableDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSDynamoDbConfigLSI(rName, "lsi-original"),
Check: resource.ComposeTestCheckFunc(
testAccCheckInitialAWSDynamoDbTableExists(resourceName, &conf),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{ // Change name of local secondary index
Config: testAccAWSDynamoDbConfigLSI(rName, "lsi-changed"),
Check: resource.ComposeTestCheckFunc(
testAccCheckInitialAWSDynamoDbTableExists(resourceName, &conf),
),
},
},
})
}

func TestAccAWSDynamoDbTable_attributeUpdateValidation(t *testing.T) {
rName := acctest.RandomWithPrefix("TerraformTestTable-")

Expand Down Expand Up @@ -2083,3 +2114,36 @@ resource "aws_dynamodb_table" "test" {
}
`, rName, attrName1, attrType1, attrName2, attrType2, hashKey, rangeKey)
}

func testAccAWSDynamoDbConfigLSI(rName, lsiName string) string {
return fmt.Sprintf(`
resource "aws_dynamodb_table" "test" {
name = "%s"
read_capacity = 10
write_capacity = 10
hash_key = "staticHashKey"
range_key = "staticRangeKey"
attribute {
name = "staticHashKey"
type = "S"
}
attribute {
name = "staticRangeKey"
type = "S"
}
attribute {
name = "staticLSIRangeKey"
type = "S"
}
local_secondary_index {
name = "%s"
range_key = "staticLSIRangeKey"
projection_type = "KEYS_ONLY"
}
}
`, rName, lsiName)
}

0 comments on commit 863e24d

Please sign in to comment.