Skip to content

Commit

Permalink
resource/aws_dynamodb_table: Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Jan 25, 2018
1 parent 2971785 commit 428dd94
Show file tree
Hide file tree
Showing 5 changed files with 1,100 additions and 830 deletions.
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

0 comments on commit 428dd94

Please sign in to comment.