update casing for dynamoDb
This commit is contained in:
parent
91e0fed333
commit
dacc765a5e
|
@ -591,7 +591,7 @@ func resourceAwsDynamoDbTableUpdate(d *schema.ResourceData, meta interface{}) er
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update tags
|
// Update tags
|
||||||
if err := setTagsDynamoDB(dynamodbconn, d); err != nil {
|
if err := setTagsDynamoDb(dynamodbconn, d); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -923,7 +923,7 @@ func createTableTags(d *schema.ResourceData, meta interface{}) error {
|
||||||
dynamodbconn := meta.(*AWSClient).dynamodbconn
|
dynamodbconn := meta.(*AWSClient).dynamodbconn
|
||||||
req := &dynamodb.TagResourceInput{
|
req := &dynamodb.TagResourceInput{
|
||||||
ResourceArn: aws.String(arn),
|
ResourceArn: aws.String(arn),
|
||||||
Tags: tagsFromMapDynamoDB(tags),
|
Tags: tagsFromMapDynamoDb(tags),
|
||||||
}
|
}
|
||||||
_, err := dynamodbconn.TagResource(req)
|
_, err := dynamodbconn.TagResource(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -948,7 +948,7 @@ func readTableTags(d *schema.ResourceData, meta interface{}) (map[string]string,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Error reading tags from dynamodb resource: %s", err)
|
return nil, fmt.Errorf("Error reading tags from dynamodb resource: %s", err)
|
||||||
}
|
}
|
||||||
result := tagsToMapDynamoDB(output.Tags)
|
result := tagsToMapDynamoDb(output.Tags)
|
||||||
// TODO Read NextToken if avail
|
// TODO Read NextToken if avail
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ func TestAccAWSDynamoDbTable_streamSpecification(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccAWSDynamoDBTable_tags(t *testing.T) {
|
func TestAccAWSDynamoDbTable_tags(t *testing.T) {
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
|
|
|
@ -249,8 +249,8 @@ func tagIgnoredELBv2(t *elbv2.Tag) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// tagsToMapDynamoDB turns the list of tags into a map for dynamoDB
|
// tagsToMapDynamoDb turns the list of tags into a map for dynamoDB
|
||||||
func tagsToMapDynamoDB(ts []*dynamodb.Tag) map[string]string {
|
func tagsToMapDynamoDb(ts []*dynamodb.Tag) map[string]string {
|
||||||
result := make(map[string]string)
|
result := make(map[string]string)
|
||||||
for _, t := range ts {
|
for _, t := range ts {
|
||||||
result[*t.Key] = *t.Value
|
result[*t.Key] = *t.Value
|
||||||
|
@ -258,8 +258,8 @@ func tagsToMapDynamoDB(ts []*dynamodb.Tag) map[string]string {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// tagsFromMapDynamoDB returns the tags for a given map
|
// tagsFromMapDynamoDb returns the tags for a given map
|
||||||
func tagsFromMapDynamoDB(m map[string]interface{}) []*dynamodb.Tag {
|
func tagsFromMapDynamoDb(m map[string]interface{}) []*dynamodb.Tag {
|
||||||
result := make([]*dynamodb.Tag, 0, len(m))
|
result := make([]*dynamodb.Tag, 0, len(m))
|
||||||
for k, v := range m {
|
for k, v := range m {
|
||||||
t := &dynamodb.Tag{
|
t := &dynamodb.Tag{
|
||||||
|
@ -271,17 +271,17 @@ func tagsFromMapDynamoDB(m map[string]interface{}) []*dynamodb.Tag {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// setTagsDynamoDB is a helper to set the tags for a dynamoDB resource
|
// setTagsDynamoDb is a helper to set the tags for a dynamoDB resource
|
||||||
// This is needed because dynamodb requires a completely different set and delete
|
// This is needed because dynamodb requires a completely different set and delete
|
||||||
// method from the ec2 tag resource handling. Also the `UntagResource` method
|
// method from the ec2 tag resource handling. Also the `UntagResource` method
|
||||||
// for dynamoDB only requires a list of tag keys, instead of the full map of keys.
|
// for dynamoDB only requires a list of tag keys, instead of the full map of keys.
|
||||||
func setTagsDynamoDB(conn *dynamodb.DynamoDB, d *schema.ResourceData) error {
|
func setTagsDynamoDb(conn *dynamodb.DynamoDB, d *schema.ResourceData) error {
|
||||||
if d.HasChange("tags") {
|
if d.HasChange("tags") {
|
||||||
arn := d.Get("arn").(string)
|
arn := d.Get("arn").(string)
|
||||||
oraw, nraw := d.GetChange("tags")
|
oraw, nraw := d.GetChange("tags")
|
||||||
o := oraw.(map[string]interface{})
|
o := oraw.(map[string]interface{})
|
||||||
n := nraw.(map[string]interface{})
|
n := nraw.(map[string]interface{})
|
||||||
create, remove := diffTagsDynamoDB(tagsFromMapDynamoDB(o), tagsFromMapDynamoDB(n))
|
create, remove := diffTagsDynamoDb(tagsFromMapDynamoDb(o), tagsFromMapDynamoDb(n))
|
||||||
|
|
||||||
// Set tags
|
// Set tags
|
||||||
if len(remove) > 0 {
|
if len(remove) > 0 {
|
||||||
|
@ -329,10 +329,10 @@ func setTagsDynamoDB(conn *dynamodb.DynamoDB, d *schema.ResourceData) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// diffTagsDynamoDB takes a local set of dynamodb tags and the ones found remotely
|
// diffTagsDynamoDb takes a local set of dynamodb tags and the ones found remotely
|
||||||
// and returns the set of tags that must be created as a map, and returns a list of tag keys
|
// and returns the set of tags that must be created as a map, and returns a list of tag keys
|
||||||
// that must be destroyed.
|
// that must be destroyed.
|
||||||
func diffTagsDynamoDB(oldTags, newTags []*dynamodb.Tag) ([]*dynamodb.Tag, []*string) {
|
func diffTagsDynamoDb(oldTags, newTags []*dynamodb.Tag) ([]*dynamodb.Tag, []*string) {
|
||||||
create := make(map[string]interface{})
|
create := make(map[string]interface{})
|
||||||
for _, t := range newTags {
|
for _, t := range newTags {
|
||||||
create[*t.Key] = *t.Value
|
create[*t.Key] = *t.Value
|
||||||
|
@ -346,5 +346,5 @@ func diffTagsDynamoDB(oldTags, newTags []*dynamodb.Tag) ([]*dynamodb.Tag, []*str
|
||||||
remove = append(remove, t.Key)
|
remove = append(remove, t.Key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tagsFromMapDynamoDB(create), remove
|
return tagsFromMapDynamoDb(create), remove
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue