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

service/elasticache: Refactor to use keyvaluetags package, add arn attribute to aws_elasticache_cluster resource #11243

Merged
merged 1 commit into from
Jan 9, 2020
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
13 changes: 5 additions & 8 deletions aws/data_source_aws_elasticache_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/service/elasticache"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

func dataSourceAwsElastiCacheCluster() *schema.Resource {
Expand Down Expand Up @@ -222,19 +223,15 @@ func dataSourceAwsElastiCacheClusterRead(d *schema.ResourceData, meta interface{
}.String()
d.Set("arn", arn)

tagResp, err := conn.ListTagsForResource(&elasticache.ListTagsForResourceInput{
ResourceName: aws.String(arn),
})
tags, err := keyvaluetags.ElasticacheListTags(conn, arn)

if err != nil {
log.Printf("[DEBUG] Error retrieving tags for ARN: %s", arn)
return fmt.Errorf("error listing tags for Elasticache Cluster (%s): %s", arn, err)
}

var et []*elasticache.Tag
if len(tagResp.TagList) > 0 {
et = tagResp.TagList
if err := d.Set("tags", tags.IgnoreAws().Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
}
d.Set("tags", tagsToMapEC(et))

return nil

Expand Down
40 changes: 20 additions & 20 deletions aws/resource_aws_elasticache_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

func resourceAwsElasticacheCluster() *schema.Resource {
Expand All @@ -35,6 +36,10 @@ func resourceAwsElasticacheCluster() *schema.Resource {
Optional: true,
Computed: true,
},
"arn": {
Type: schema.TypeString,
Computed: true,
},
"availability_zone": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -315,7 +320,7 @@ func resourceAwsElasticacheClusterCreate(d *schema.ResourceData, meta interface{
securityIdSet := d.Get("security_group_ids").(*schema.Set)
securityNames := expandStringList(securityNameSet.List())
securityIds := expandStringList(securityIdSet.List())
tags := tagsFromMapEC(d.Get("tags").(map[string]interface{}))
tags := keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().ElasticacheTags()

req.CacheSecurityGroupNames = securityNames
req.SecurityGroupIds = securityIds
Expand Down Expand Up @@ -470,28 +475,26 @@ func resourceAwsElasticacheClusterRead(d *schema.ResourceData, meta interface{})
if err := setCacheNodeData(d, c); err != nil {
return err
}
// list tags for resource
// set tags

arn := arn.ARN{
Partition: meta.(*AWSClient).partition,
Service: "elasticache",
Region: meta.(*AWSClient).region,
AccountID: meta.(*AWSClient).accountid,
Resource: fmt.Sprintf("cluster:%s", d.Id()),
}.String()
resp, err := conn.ListTagsForResource(&elasticache.ListTagsForResourceInput{
ResourceName: aws.String(arn),
})

d.Set("arn", arn)

tags, err := keyvaluetags.ElasticacheListTags(conn, arn)

if err != nil {
log.Printf("[DEBUG] Error retrieving tags for ARN: %s", arn)
return fmt.Errorf("error listing tags for Elasticache Cluster (%s): %s", arn, err)
}

var et []*elasticache.Tag
if len(resp.TagList) > 0 {
et = resp.TagList
if err := d.Set("tags", tags.IgnoreAws().Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
}
d.Set("tags", tagsToMapEC(et))
}

return nil
Expand All @@ -500,15 +503,12 @@ func resourceAwsElasticacheClusterRead(d *schema.ResourceData, meta interface{})
func resourceAwsElasticacheClusterUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).elasticacheconn

arn := arn.ARN{
Partition: meta.(*AWSClient).partition,
Service: "elasticache",
Region: meta.(*AWSClient).region,
AccountID: meta.(*AWSClient).accountid,
Resource: fmt.Sprintf("cluster:%s", d.Id()),
}.String()
if err := setTagsEC(conn, d, arn); err != nil {
return err
if d.HasChange("tags") {
o, n := d.GetChange("tags")

if err := keyvaluetags.ElasticacheUpdateTags(conn, d.Get("arn").(string), o, n); err != nil {
return fmt.Errorf("error updating Elasticache Cluster (%s) tags: %s", d.Get("arn").(string), err)
}
}

req := &elasticache.ModifyCacheClusterInput{
Expand Down
3 changes: 2 additions & 1 deletion aws/resource_aws_elasticache_replication_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

func resourceAwsElasticacheReplicationGroup() *schema.Resource {
Expand Down Expand Up @@ -255,7 +256,7 @@ func resourceAwsElasticacheReplicationGroup() *schema.Resource {
func resourceAwsElasticacheReplicationGroupCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).elasticacheconn

tags := tagsFromMapEC(d.Get("tags").(map[string]interface{}))
tags := keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().ElasticacheTags()
params := &elasticache.CreateReplicationGroupInput{
ReplicationGroupId: aws.String(d.Get("replication_group_id").(string)),
ReplicationGroupDescription: aws.String(d.Get("replication_group_description").(string)),
Expand Down
116 changes: 0 additions & 116 deletions aws/tagsEC.go

This file was deleted.

77 changes: 0 additions & 77 deletions aws/tagsEC_test.go

This file was deleted.