From 4bc42378c7b4cf67f9f148809409284faa6d0e63 Mon Sep 17 00:00:00 2001 From: Paddy Carver Date: Mon, 21 Sep 2020 23:59:45 -0700 Subject: [PATCH] Backport remaining fixes from v2.0.3. Backport #580 to restore pre-binary ExpectNonEmptyPlan behavior when testing. Backport #584 to use the latest terraform-exec and terraform-plugin-test to take advantage of the fixed diff output. Backport #581 to check the error on post-test destroy, warning there may be dangling resources and surfacing the error. This should bring the v1-maint branch in line with 2.0.3 in terms of functionality and bug fixes. --- go.mod | 4 ++-- go.sum | 8 ++++---- helper/resource/testing_new.go | 5 ++++- helper/resource/testing_new_config.go | 2 -- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index fac164f896..02045576a4 100644 --- a/go.mod +++ b/go.mod @@ -28,9 +28,9 @@ require ( github.com/hashicorp/hcl/v2 v2.3.0 github.com/hashicorp/logutils v1.0.0 github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8 - github.com/hashicorp/terraform-exec v0.9.0 + github.com/hashicorp/terraform-exec v0.10.0 github.com/hashicorp/terraform-json v0.5.0 - github.com/hashicorp/terraform-plugin-test/v2 v2.1.1 + github.com/hashicorp/terraform-plugin-test/v2 v2.1.2 github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596 github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect github.com/keybase/go-crypto v0.0.0-20161004153544-93f5b35093ba diff --git a/go.sum b/go.sum index ad71f3196f..9396f47519 100644 --- a/go.sum +++ b/go.sum @@ -203,12 +203,12 @@ github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8 h1:+RyjwU+Gnd/aTJBPZVDNm903eXVjjqhbaR4Ypx3xYyY= github.com/hashicorp/terraform-config-inspect v0.0.0-20191115094559-17f92b0546e8/go.mod h1:p+ivJws3dpqbp1iP84+npOyAmTTOLMgCzrXd3GSdn/A= -github.com/hashicorp/terraform-exec v0.9.0 h1:NmCtcsnmPBU6P3cDeKD26bD72evsMhmuDLvuNRgrTHc= -github.com/hashicorp/terraform-exec v0.9.0/go.mod h1:tOT8j1J8rP05bZBGWXfMyU3HkLi1LWyqL3Bzsc3CJjo= +github.com/hashicorp/terraform-exec v0.10.0 h1:3nh/1e3u9gYRUQGOKWp/8wPR7ABlL2F14sZMZBrp+dM= +github.com/hashicorp/terraform-exec v0.10.0/go.mod h1:tOT8j1J8rP05bZBGWXfMyU3HkLi1LWyqL3Bzsc3CJjo= github.com/hashicorp/terraform-json v0.5.0 h1:7TV3/F3y7QVSuN4r9BEXqnWqrAyeOtON8f0wvREtyzs= github.com/hashicorp/terraform-json v0.5.0/go.mod h1:eAbqb4w0pSlRmdvl8fOyHAi/+8jnkVYN28gJkSJrLhU= -github.com/hashicorp/terraform-plugin-test/v2 v2.1.1 h1:aATRyyPlEKkFYUweD2Hld9eep77qzJVu8wg0mgyUE50= -github.com/hashicorp/terraform-plugin-test/v2 v2.1.1/go.mod h1:HaW2G5cDTVyiEKt7PHC85YSM5BwvYl/rIko1g8Lg7qE= +github.com/hashicorp/terraform-plugin-test/v2 v2.1.2 h1:p96IIn+XpvVjw7AtN8y9MKxn0x69S7wtbGf7JgDJoIk= +github.com/hashicorp/terraform-plugin-test/v2 v2.1.2/go.mod h1:jerO5mrd+jVNALy8aiq+VZOg/CR8T2T1QR3jd6JKGOI= github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596 h1:hjyO2JsNZUKT1ym+FAdlBEkGPevazYsmVgIMw7dVELg= github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg= github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= diff --git a/helper/resource/testing_new.go b/helper/resource/testing_new.go index 6dcb240681..c2a6582255 100644 --- a/helper/resource/testing_new.go +++ b/helper/resource/testing_new.go @@ -62,7 +62,10 @@ func RunNewTest(t *testing.T, c TestCase, providers map[string]terraform.Resourc } if !stateIsEmpty(statePreDestroy) { - runPostTestDestroy(t, c, wd, c.ProviderFactories) + err := runPostTestDestroy(t, c, wd, c.ProviderFactories) + if err != nil { + t.Fatalf("Error running post-test destroy, there may be dangling resources: %s", err.Error()) + } } wd.Close() diff --git a/helper/resource/testing_new_config.go b/helper/resource/testing_new_config.go index ef4f5f70b3..7b0f7455eb 100644 --- a/helper/resource/testing_new_config.go +++ b/helper/resource/testing_new_config.go @@ -137,8 +137,6 @@ func testStepNewConfig(t *testing.T, c TestCase, wd *tftest.WorkingDir, step Tes return fmt.Errorf("Error retrieving formatted plan output: %s", err) } return fmt.Errorf("After applying this test step, the plan was not empty.\nstdout:\n\n%s", stdout) - } else if step.ExpectNonEmptyPlan && planIsEmpty(plan) { - return fmt.Errorf("Expected a non-empty plan, but got an empty plan!") } // do a refresh