Skip to content

Commit

Permalink
resource/aws_vpc: Implement provider ignore_tags support
Browse files Browse the repository at this point in the history
Reference: #7926

Output from acceptance testing:

```
--- PASS: TestAccAWSVpc_ignoreTags (31.81s)
--- PASS: TestAccAWSVpc_tags (43.32s)
```
  • Loading branch information
bflad committed Oct 7, 2019
1 parent 636c088 commit 99a6e3b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion aws/resource_aws_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ func resourceAwsVpcCreate(d *schema.ResourceData, meta interface{}) error {

func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).ec2conn
ignoreTags := meta.(*AWSClient).ignoreTags

// Refresh the VPC state
vpcRaw, _, err := VPCStateRefreshFunc(conn, d.Id())()
Expand Down Expand Up @@ -294,7 +295,7 @@ func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error {
}.String()
d.Set("arn", arn)

if err := d.Set("tags", keyvaluetags.Ec2KeyValueTags(vpc.Tags).IgnoreAws().Map()); err != nil {
if err := d.Set("tags", keyvaluetags.Ec2KeyValueTags(vpc.Tags).IgnoreAws().Ignore(ignoreTags).Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
}

Expand Down
36 changes: 36 additions & 0 deletions aws/resource_aws_vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
"github.com/aws/aws-sdk-go/aws/awserr"
"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/hashicorp/terraform-plugin-sdk/terraform"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

// add sweeper to delete known test vpcs
Expand Down Expand Up @@ -142,6 +144,32 @@ func TestAccAWSVpc_disappears(t *testing.T) {
})
}

func TestAccAWSVpc_ignoreTags(t *testing.T) {
var providers []*schema.Provider
var vpc ec2.Vpc
resourceName := "aws_vpc.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories(&providers),
CheckDestroy: testAccCheckVpcDestroy,
Steps: []resource.TestStep{
{
Config: testAccVpcConfigTags,
Check: resource.ComposeTestCheckFunc(
testAccCheckVpcExists(resourceName, &vpc),
testAccCheckEc2UpdateTags(&vpc, nil, map[string]string{"ignorekey1": "ignorevalue1"}),
),
ExpectNonEmptyPlan: true,
},
{
Config: testAccProviderConfigIgnoreTags1("ignorekey1") + testAccVpcConfigTags,
PlanOnly: true,
},
},
})
}

func TestAccAWSVpc_AssignGeneratedIpv6CidrBlock(t *testing.T) {
var vpc ec2.Vpc
resourceName := "aws_vpc.test"
Expand Down Expand Up @@ -332,6 +360,14 @@ func testAccCheckVpcDestroy(s *terraform.State) error {
return nil
}

func testAccCheckEc2UpdateTags(vpc *ec2.Vpc, oldTags, newTags map[string]string) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn

return keyvaluetags.Ec2UpdateTags(conn, aws.StringValue(vpc.VpcId), oldTags, newTags)
}
}

func testAccCheckVpcCidr(vpc *ec2.Vpc, expected string) resource.TestCheckFunc {
return func(s *terraform.State) error {
if aws.StringValue(vpc.CidrBlock) != expected {
Expand Down

0 comments on commit 99a6e3b

Please sign in to comment.