Skip to content

Commit

Permalink
r/aws_dynamodb_table: Ensure ttl is properly read (#2452)
Browse files Browse the repository at this point in the history
* r/aws_dynamodb_table: Ensure ttl is properly read

* r/aws_dynamodb_table: #2452 review updates

* Add timeToLiveOutput.TimeToLiveDescription nil check
* Simplify logic to d.Set ttl
  • Loading branch information
bflad authored and radeksimko committed Dec 12, 2017
1 parent 6eb922a commit edb26df
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
22 changes: 22 additions & 0 deletions aws/import_aws_dynamodb_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,25 @@ func TestAccAWSDynamoDbTable_importTags(t *testing.T) {
},
})
}

func TestAccAWSDynamoDbTable_importTimeToLive(t *testing.T) {
resourceName := "aws_dynamodb_table.basic-dynamodb-table"
rName := acctest.RandomWithPrefix("TerraformTestTable-")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDynamoDbTableDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSDynamoDbConfigAddTimeToLive(rName),
},

{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
22 changes: 14 additions & 8 deletions aws/resource_aws_dynamodb_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,15 +816,21 @@ func flattenAwsDynamoDbTableResource(d *schema.ResourceData, meta interface{}, t
if err != nil {
return err
}
timeToLive := []interface{}{}
attribute := map[string]*string{
"name": timeToLiveOutput.TimeToLiveDescription.AttributeName,
"type": timeToLiveOutput.TimeToLiveDescription.TimeToLiveStatus,
}
timeToLive = append(timeToLive, attribute)
d.Set("timeToLive", timeToLive)

log.Printf("[DEBUG] Loaded TimeToLive data for DynamoDB table '%s'", d.Id())
if timeToLiveOutput.TimeToLiveDescription != nil && timeToLiveOutput.TimeToLiveDescription.AttributeName != nil {
timeToLiveList := []interface{}{
map[string]interface{}{
"attribute_name": *timeToLiveOutput.TimeToLiveDescription.AttributeName,
"enabled": (*timeToLiveOutput.TimeToLiveDescription.TimeToLiveStatus == dynamodb.TimeToLiveStatusEnabled),
},
}
err := d.Set("ttl", timeToLiveList)
if err != nil {
return err
}

log.Printf("[DEBUG] Loaded TimeToLive data for DynamoDB table '%s'", d.Id())
}

tags, err := readTableTags(d, meta)
if err != nil {
Expand Down

0 comments on commit edb26df

Please sign in to comment.