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

Replace DyanmoDB table when local secondary index changes (#12334) #12335

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
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)
}