Skip to content

Commit

Permalink
r/aws_route53_domain: Fix tagging for aws_route53_domain
Browse files Browse the repository at this point in the history
  • Loading branch information
gazoakley committed Apr 25, 2020
1 parent e8f9732 commit 97aae10
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 27 deletions.
2 changes: 1 addition & 1 deletion aws/resource_aws_route53_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func resourceAwsRoute53Domain() *schema.Resource {
Computed: true,
},

"tags": tagsSchema(),
"tags": tagsSchemaComputed(),

"tech_contact": resourceAwsRoute53DomainContactDetail(),

Expand Down
62 changes: 36 additions & 26 deletions aws/tags_route53domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,24 @@ func setTagsRoute53Domains(conn *route53domains.Route53Domains, d *schema.Resour
oraw, nraw := d.GetChange("tags")
o := oraw.(map[string]interface{})
n := nraw.(map[string]interface{})
create, remove := diffTagsRoute53Domains(tagsFromMapRoute53Domains(o), tagsFromMapRoute53Domains(n))
updateTags, deleteTags := diffTagsRoute53Domains(o, n)

// Set tags
if len(remove) > 0 {
log.Printf("[DEBUG] Removing tags: %#v", remove)
keys := make([]*string, 0, len(remove))
// for k := range remove {
// keys = append(keys, aws.String(k))
// }
if len(deleteTags) > 0 {
log.Printf("[DEBUG] Removing tags: %#v", deleteTags)
_, err := conn.DeleteTagsForDomain(&route53domains.DeleteTagsForDomainInput{
DomainName: aws.String(d.Id()),
TagsToDelete: keys,
TagsToDelete: deleteTags,
})
if err != nil {
return err
}
}
if len(create) > 0 {
log.Printf("[DEBUG] Creating tags: %#v", create)
if len(updateTags) > 0 {
log.Printf("[DEBUG] Updating tags: %#v", updateTags)
_, err := conn.UpdateTagsForDomain(&route53domains.UpdateTagsForDomainInput{
DomainName: aws.String(d.Id()),
TagsToUpdate: create,
TagsToUpdate: updateTags,
})
if err != nil {
return err
Expand All @@ -49,26 +45,40 @@ func setTagsRoute53Domains(conn *route53domains.Route53Domains, d *schema.Resour
}

// diffTags takes our tags locally and the ones remotely and returns
// the set of tags that must be created, and the set of tags that must
// be destroyed.
func diffTagsRoute53Domains(oldTags, newTags []*route53domains.Tag) ([]*route53domains.Tag, []*route53domains.Tag) {
// First, we're creating everything we have
create := make(map[string]interface{})
for _, t := range newTags {
create[*t.Key] = *t.Value
// the set of tags that must be updated, and the set of tags that must
// be deleted.
func diffTagsRoute53Domains(oldTags, newTags map[string]interface{}) ([]*route53domains.Tag, []*string) {
// Is the key from newTags in oldTags
// No - it's a creation
// Yes - if it's differnet, it's an update
updateTags := make(map[string]interface{})
for k, v := range newTags {
old, ok := oldTags[k]
if !ok || old != v {
updateTags[k] = v
}
}
log.Printf("[DEBUG] Route 53 Domain tags to update: %#v", updateTags)

// Build the list of what to remove
var remove []*route53domains.Tag
for _, t := range oldTags {
old, ok := create[*t.Key]
if !ok || old != *t.Value {
// Delete it!
remove = append(remove, t)
// Is the key from oldTags in newTags
// No - it's a deletion
var deleteTags []*string
for k, _ := range oldTags {
_, ok := newTags[k]
if !ok {
deleteTags = append(deleteTags, aws.String(k))
}
}
log.Printf("[DEBUG] Route 53 Domain tags to delete: %#v", deleteTags)

// aws/tags_route53domains.go:56:22: invalid indirect of k (type string)
// aws/tags_route53domains.go:57:20: invalid indirect of v (type interface {})
// aws/tags_route53domains.go:58:15: invalid indirect of k (type string)
// aws/tags_route53domains.go:58:21: invalid indirect of v (type interface {})
// aws/tags_route53domains.go:66:20: invalid indirect of k (type string)
// aws/tags_route53domains.go:68:23: cannot use k (type string) as type *string in append

return tagsFromMapRoute53Domains(create), remove
return tagsFromMapRoute53Domains(updateTags), deleteTags
}

// tagsFromMap returns the tags for the given map of data.
Expand Down

0 comments on commit 97aae10

Please sign in to comment.