From b793dfecda718be584c0a6ad425cdeedec7aeace Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Tue, 3 Mar 2020 09:14:23 -0500 Subject: [PATCH] resource/aws_vpc_peering_connection: Refactor to use keyvaluetags package (#11935) Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/10688 Output from acceptance testing: ``` --- PASS: TestAccAWSVPCPeeringConnection_peerRegionAutoAccept (18.18s) --- PASS: TestAccAWSVPCPeeringConnection_failedState (18.90s) --- PASS: TestAccAWSVPCPeeringConnection_optionsNoAutoAccept (22.54s) --- PASS: TestAccAWSVPCPeeringConnection_plan (30.03s) --- PASS: TestAccAWSVPCPeeringConnection_basic (32.13s) --- PASS: TestAccAWSVPCPeeringConnection_tags (33.94s) --- PASS: TestAccAWSVPCPeeringConnection_region (35.88s) --- PASS: TestAccAWSVPCPeeringConnection_options (57.71s) --- PASS: TestAccAWSVPCPeeringConnection_accept (68.21s) ``` --- aws/resource_aws_vpc_peering_connection.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/aws/resource_aws_vpc_peering_connection.go b/aws/resource_aws_vpc_peering_connection.go index d0c48dc89e9..d0de5abcd90 100644 --- a/aws/resource_aws_vpc_peering_connection.go +++ b/aws/resource_aws_vpc_peering_connection.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go/service/ec2" "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 resourceAwsVpcPeeringConnection() *schema.Resource { @@ -161,7 +162,7 @@ func resourceAwsVPCPeeringRead(d *schema.ResourceData, meta interface{}) error { return fmt.Errorf("Error setting VPC Peering Connection requester information: %s", err) } - err = d.Set("tags", tagsToMap(pc.Tags)) + err = d.Set("tags", keyvaluetags.Ec2KeyValueTags(pc.Tags).IgnoreAws().Map()) if err != nil { return fmt.Errorf("Error setting VPC Peering Connection tags: %s", err) } @@ -202,10 +203,12 @@ func resourceAwsVpcPeeringConnectionModifyOptions(d *schema.ResourceData, meta i func resourceAwsVPCPeeringUpdate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).ec2conn - if err := setTags(conn, d); err != nil { - return err - } else { - d.SetPartial("tags") + 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 EC2 VPC Peering Connection (%s) tags: %s", d.Id(), err) + } } pcRaw, statusCode, err := vpcPeeringConnectionRefreshState(conn, d.Id())()