From ff7b58f032b6551c1cb10d4c0967d8957578a3a8 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 20 Apr 2016 12:19:21 -0700 Subject: [PATCH] providers/aws: peering connection id-only test settings --- .../aws/resource_aws_vpc_peering_connection.go | 2 -- .../resource_aws_vpc_peering_connection_test.go | 14 +++++++++++++- helper/resource/testing.go | 13 +++++++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/builtin/providers/aws/resource_aws_vpc_peering_connection.go b/builtin/providers/aws/resource_aws_vpc_peering_connection.go index a8ae86dce..8c48b0e96 100644 --- a/builtin/providers/aws/resource_aws_vpc_peering_connection.go +++ b/builtin/providers/aws/resource_aws_vpc_peering_connection.go @@ -147,7 +147,6 @@ func resourceAwsVPCPeeringUpdate(d *schema.ResourceData, meta interface{}) error } if _, ok := d.GetOk("auto_accept"); ok { - pcRaw, _, err := resourceAwsVPCPeeringConnectionStateRefreshFunc(conn, d.Id())() if err != nil { @@ -160,7 +159,6 @@ func resourceAwsVPCPeeringUpdate(d *schema.ResourceData, meta interface{}) error pc := pcRaw.(*ec2.VpcPeeringConnection) if pc.Status != nil && *pc.Status.Code == "pending-acceptance" { - status, err := resourceVPCPeeringConnectionAccept(conn, d.Id()) if err != nil { return err diff --git a/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go b/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go index 4318bda68..da92ff549 100644 --- a/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go +++ b/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go @@ -22,6 +22,10 @@ func TestAccAWSVPCPeeringConnection_basic(t *testing.T) { t.Fatal("AWS_ACCOUNT_ID must be set") } }, + + IDRefreshName: "aws_vpc_peering_connection.foo", + IDRefreshIgnore: []string{"auto_accept"}, + Providers: testAccProviders, CheckDestroy: testAccCheckAWSVpcPeeringConnectionDestroy, Steps: []resource.TestStep{ @@ -59,6 +63,10 @@ func TestAccAWSVPCPeeringConnection_plan(t *testing.T) { t.Fatal("AWS_ACCOUNT_ID must be set") } }, + + IDRefreshName: "aws_vpc_peering_connection.foo", + IDRefreshIgnore: []string{"auto_accept"}, + Providers: testAccProviders, CheckDestroy: testAccCheckAWSVpcPeeringConnectionDestroy, Steps: []resource.TestStep{ @@ -82,7 +90,11 @@ func TestAccAWSVPCPeeringConnection_tags(t *testing.T) { } resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, + PreCheck: func() { testAccPreCheck(t) }, + + IDRefreshName: "aws_vpc_peering_connection.foo", + IDRefreshIgnore: []string{"auto_accept"}, + Providers: testAccProviders, CheckDestroy: testAccCheckVpcDestroy, Steps: []resource.TestStep{ diff --git a/helper/resource/testing.go b/helper/resource/testing.go index b98254033..3d10158d5 100644 --- a/helper/resource/testing.go +++ b/helper/resource/testing.go @@ -70,8 +70,11 @@ type TestCase struct { // // IDRefreshName is the name of the resource to check. This will // default to the first non-nil primary resource in the state. + // + // IDRefreshIgnore is a list of configuration keys that will be ignored. DisableIDRefresh bool IDRefreshName string + IDRefreshIgnore []string } // TestStep is a single apply sequence of a test, done within the @@ -205,7 +208,7 @@ func Test(t TestT, c TestCase) { log.Printf( "[WARN] Test: Running ID-only refresh check on %s", idRefreshCheck.Primary.ID) - if err := testIDOnlyRefresh(opts, step, idRefreshCheck); err != nil { + if err := testIDOnlyRefresh(c, opts, step, idRefreshCheck); err != nil { log.Printf("[ERROR] Test: ID-only test failed: %s", err) t.Error(fmt.Sprintf( "ID-Only refresh test failure: %s", err)) @@ -261,7 +264,7 @@ func UnitTest(t TestT, c TestCase) { Test(t, c) } -func testIDOnlyRefresh(opts terraform.ContextOpts, step TestStep, r *terraform.ResourceState) error { +func testIDOnlyRefresh(c TestCase, opts terraform.ContextOpts, step TestStep, r *terraform.ResourceState) error { // TODO: We guard by this right now so master doesn't explode. We // need to remove this eventually to make this part of the normal tests. if os.Getenv("TF_ACC_IDONLY") == "" { @@ -323,6 +326,12 @@ func testIDOnlyRefresh(opts terraform.ContextOpts, step TestStep, r *terraform.R } actual := actualR.Primary.Attributes expected := r.Primary.Attributes + // Remove fields we're ignoring + for _, v := range c.IDRefreshIgnore { + delete(actual, v) + delete(expected, v) + } + if !reflect.DeepEqual(actual, expected) { // Determine only the different attributes for k, v := range expected {