Skip to content

Commit

Permalink
Merge pull request #12335 from InventiveDesigners/replace-dynamo-tabl…
Browse files Browse the repository at this point in the history
…e-for-lsi-change

Replace DyanmoDB table when local secondary index changes (#12334)
  • Loading branch information
anGie44 authored Sep 18, 2020
2 parents 51ad60b + 558a103 commit 7670a78
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 @@ -158,18 +158,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 @@ -1145,6 +1145,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 @@ -2218,3 +2249,36 @@ resource "aws_dynamodb_table" "test" {
}
`, rName))
}

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 7670a78

Please sign in to comment.