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/aws_dynamodb_table: Refactoring #3136

Merged
merged 2 commits into from
Jan 29, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
40 changes: 29 additions & 11 deletions aws/data_source_aws_dynamodb_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package aws
import (
"bytes"
"fmt"
"log"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema"
)
Expand Down Expand Up @@ -174,21 +172,41 @@ func dataSourceAwsDynamoDbTable() *schema.Resource {
}

func dataSourceAwsDynamoDbTableRead(d *schema.ResourceData, meta interface{}) error {
dynamodbconn := meta.(*AWSClient).dynamodbconn
conn := meta.(*AWSClient).dynamodbconn

name := d.Get("name").(string)
req := &dynamodb.DescribeTableInput{
TableName: aws.String(name),
result, err := conn.DescribeTable(&dynamodb.DescribeTableInput{
TableName: aws.String(d.Get("name").(string)),
})

if err != nil {
return fmt.Errorf("Error retrieving DynamoDB table: %s", err)
}

log.Printf("[DEBUG] Reading DynamoDB Table: %s", req)
result, err := dynamodbconn.DescribeTable(req)
d.SetId(*result.Table.TableName)

err = flattenAwsDynamoDbTableResource(d, result.Table)
if err != nil {
return errwrap.Wrapf("Error retrieving DynamoDB table: {{err}}", err)
return err
}

d.SetId(*result.Table.TableName)
ttlOut, err := conn.DescribeTimeToLive(&dynamodb.DescribeTimeToLiveInput{
TableName: aws.String(d.Id()),
})
if err != nil {
return err
}
if ttlOut.TimeToLiveDescription != nil {
err := d.Set("ttl", flattenDynamoDbTtl(ttlOut.TimeToLiveDescription))
if err != nil {
return err
}
}

tags, err := readDynamoDbTableTags(d.Get("arn").(string), conn)
if err != nil {
return err
}
d.Set("tags", tags)

return flattenAwsDynamoDbTableResource(d, meta, result.Table)
return nil
}
Loading