Skip to content

Commit

Permalink
resource/aws_lightsail_instance: Refactor tagging logic to keyvalueta…
Browse files Browse the repository at this point in the history
…gs package. (#11378)

Output from acceptance testing:

```
--- PASS: TestAccAWSLightsailInstance_disapear (45.07s)
--- PASS: TestAccAWSLightsailInstance_basic (54.59s)
--- PASS: TestAccAWSLightsailInstance_Tags (61.51s)
--- PASS: TestAccAWSLightsailInstance_Name (94.04s)
```
  • Loading branch information
Kit Ewbank authored and bflad committed Dec 20, 2019
1 parent 61d14fd commit cd08718
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 197 deletions.
18 changes: 9 additions & 9 deletions aws/resource_aws_lightsail_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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 resourceAwsLightsailInstance() *schema.Resource {
Expand Down Expand Up @@ -135,10 +136,8 @@ func resourceAwsLightsailInstanceCreate(d *schema.ResourceData, meta interface{}
req.UserData = aws.String(v.(string))
}

tags := tagsFromMapLightsail(d.Get("tags").(map[string]interface{}))

if len(tags) != 0 {
req.Tags = tags
if v := d.Get("tags").(map[string]interface{}); len(v) > 0 {
req.Tags = keyvaluetags.New(v).IgnoreAws().LightsailTags()
}

resp, err := conn.CreateInstances(&req)
Expand Down Expand Up @@ -214,8 +213,8 @@ func resourceAwsLightsailInstanceRead(d *schema.ResourceData, meta interface{})
d.Set("private_ip_address", i.PrivateIpAddress)
d.Set("public_ip_address", i.PublicIpAddress)

if err := d.Set("tags", tagsToMapLightsail(i.Tags)); err != nil {
return fmt.Errorf("Error setting tags: %s", err)
if err := d.Set("tags", keyvaluetags.LightsailKeyValueTags(i.Tags).IgnoreAws().Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
}

return nil
Expand Down Expand Up @@ -256,10 +255,11 @@ func resourceAwsLightsailInstanceUpdate(d *schema.ResourceData, meta interface{}
conn := meta.(*AWSClient).lightsailconn

if d.HasChange("tags") {
if err := setTagsLightsail(conn, d); err != nil {
return err
o, n := d.GetChange("tags")

if err := keyvaluetags.LightsailUpdateTags(conn, d.Id(), o, n); err != nil {
return fmt.Errorf("error updating Lightsail Instance (%s) tags: %s", d.Id(), err)
}
d.SetPartial("tags")
}

return resourceAwsLightsailInstanceRead(d, meta)
Expand Down
97 changes: 0 additions & 97 deletions aws/tagsLightsail.go

This file was deleted.

91 changes: 0 additions & 91 deletions aws/tagsLightsail_test.go

This file was deleted.

0 comments on commit cd08718

Please sign in to comment.