diff --git a/aws/data_source_aws_ebs_volume.go b/aws/data_source_aws_ebs_volume.go index 72322ea7847..df47570a16a 100644 --- a/aws/data_source_aws_ebs_volume.go +++ b/aws/data_source_aws_ebs_volume.go @@ -8,6 +8,7 @@ import ( "github.com/aws/aws-sdk-go/aws/arn" "github.com/aws/aws-sdk-go/service/ec2" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" ) func dataSourceAwsEbsVolume() *schema.Resource { @@ -141,6 +142,9 @@ func volumeDescriptionAttributes(d *schema.ResourceData, client *AWSClient, volu d.Set("snapshot_id", volume.SnapshotId) d.Set("volume_type", volume.VolumeType) - err := d.Set("tags", tagsToMap(volume.Tags)) - return err + if err := d.Set("tags", keyvaluetags.Ec2KeyValueTags(volume.Tags).IgnoreAws().Map()); err != nil { + return fmt.Errorf("error setting tags: %s", err) + } + + return nil } diff --git a/aws/resource_aws_ebs_volume.go b/aws/resource_aws_ebs_volume.go index 76ae339aef7..89add9e1a8b 100644 --- a/aws/resource_aws_ebs_volume.go +++ b/aws/resource_aws_ebs_volume.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" ) func resourceAwsEbsVolume() *schema.Resource { @@ -80,7 +81,8 @@ func resourceAwsEbsVolumeCreate(d *schema.ResourceData, meta interface{}) error conn := meta.(*AWSClient).ec2conn request := &ec2.CreateVolumeInput{ - AvailabilityZone: aws.String(d.Get("availability_zone").(string)), + AvailabilityZone: aws.String(d.Get("availability_zone").(string)), + TagSpecifications: ec2TagSpecificationsFromMap(d.Get("tags").(map[string]interface{}), ec2.ResourceTypeVolume), } if value, ok := d.GetOk("encrypted"); ok { request.Encrypted = aws.Bool(value.(bool)) @@ -94,14 +96,6 @@ func resourceAwsEbsVolumeCreate(d *schema.ResourceData, meta interface{}) error if value, ok := d.GetOk("snapshot_id"); ok { request.SnapshotId = aws.String(value.(string)) } - if value, ok := d.GetOk("tags"); ok { - request.TagSpecifications = []*ec2.TagSpecification{ - { - ResourceType: aws.String(ec2.ResourceTypeVolume), - Tags: tagsFromMap(value.(map[string]interface{})), - }, - } - } // IOPs are only valid, and required for, storage type io1. The current minimu // is 100. Instead of a hard validation we we only apply the IOPs to the @@ -154,11 +148,6 @@ func resourceAwsEbsVolumeCreate(d *schema.ResourceData, meta interface{}) error func resourceAWSEbsVolumeUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).ec2conn - if _, ok := d.GetOk("tags"); ok { - if err := setTags(conn, d); err != nil { - return fmt.Errorf("Error updating tags for EBS Volume: %s", err) - } - } requestUpdate := false params := &ec2.ModifyVolumeInput{ @@ -203,6 +192,14 @@ func resourceAWSEbsVolumeUpdate(d *schema.ResourceData, meta interface{}) error } } + if d.HasChange("tags") { + o, n := d.GetChange("tags") + + if err := keyvaluetags.Ec2UpdateTags(conn, d.Id(), o, n); err != nil { + return fmt.Errorf("error updating tags: %s", err) + } + } + return resourceAwsEbsVolumeRead(d, meta) } @@ -268,7 +265,7 @@ func resourceAwsEbsVolumeRead(d *schema.ResourceData, meta interface{}) error { d.Set("size", aws.Int64Value(volume.Size)) d.Set("snapshot_id", aws.StringValue(volume.SnapshotId)) - if err := d.Set("tags", tagsToMap(volume.Tags)); err != nil { + if err := d.Set("tags", keyvaluetags.Ec2KeyValueTags(volume.Tags).IgnoreAws().Map()); err != nil { return fmt.Errorf("error setting tags: %s", err) }