From a4850a86dec870fd92ac6b33db542060d4e1034d Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 21 Apr 2025 11:45:36 -0400 Subject: [PATCH 1/2] Add 'AdditionalCLIOptions.PlanOptions.NoRefresh' to test 'terraform plan -refresh=false'. --- helper/resource/additional_cli_options.go | 3 +++ helper/resource/testing_new_config.go | 27 ++++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/helper/resource/additional_cli_options.go b/helper/resource/additional_cli_options.go index 62578edef..36dc0f89a 100644 --- a/helper/resource/additional_cli_options.go +++ b/helper/resource/additional_cli_options.go @@ -23,4 +23,7 @@ type ApplyOptions struct { type PlanOptions struct { // AllowDeferral will pass the experimental `-allow-deferral` flag to the plan command. AllowDeferral bool + + // NoRefresh will pass the `-refresh=false` flag to the plan command. + NoRefresh bool } diff --git a/helper/resource/testing_new_config.go b/helper/resource/testing_new_config.go index 29995af6e..babaf8410 100644 --- a/helper/resource/testing_new_config.go +++ b/helper/resource/testing_new_config.go @@ -108,8 +108,13 @@ func testStepNewConfig(ctx context.Context, t testing.T, c TestCase, wd *plugint opts = append(opts, tfexec.Destroy(true)) } - if c.AdditionalCLIOptions != nil && c.AdditionalCLIOptions.Plan.AllowDeferral { - opts = append(opts, tfexec.AllowDeferral(true)) + if c.AdditionalCLIOptions != nil { + if c.AdditionalCLIOptions.Plan.AllowDeferral { + opts = append(opts, tfexec.AllowDeferral(true)) + } + if c.AdditionalCLIOptions.Plan.NoRefresh { + opts = append(opts, tfexec.Refresh(false)) + } } return wd.CreatePlan(ctx, opts...) @@ -250,8 +255,13 @@ func testStepNewConfig(ctx context.Context, t testing.T, c TestCase, wd *plugint opts = append(opts, tfexec.Destroy(true)) } - if c.AdditionalCLIOptions != nil && c.AdditionalCLIOptions.Plan.AllowDeferral { - opts = append(opts, tfexec.AllowDeferral(true)) + if c.AdditionalCLIOptions != nil { + if c.AdditionalCLIOptions.Plan.AllowDeferral { + opts = append(opts, tfexec.AllowDeferral(true)) + } + if c.AdditionalCLIOptions.Plan.NoRefresh { + opts = append(opts, tfexec.Refresh(false)) + } } return wd.CreatePlan(ctx, opts...) @@ -319,8 +329,13 @@ func testStepNewConfig(ctx context.Context, t testing.T, c TestCase, wd *plugint } } - if c.AdditionalCLIOptions != nil && c.AdditionalCLIOptions.Plan.AllowDeferral { - opts = append(opts, tfexec.AllowDeferral(true)) + if c.AdditionalCLIOptions != nil { + if c.AdditionalCLIOptions.Plan.AllowDeferral { + opts = append(opts, tfexec.AllowDeferral(true)) + } + if c.AdditionalCLIOptions.Plan.NoRefresh { + opts = append(opts, tfexec.Refresh(false)) + } } return wd.CreatePlan(ctx, opts...) From 0809152ce16cc76a6efe574d4f8002720ed18d4e Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 21 Apr 2025 14:50:59 -0400 Subject: [PATCH 2/2] Add CHANGELOG entry. --- .changes/unreleased/ENHANCEMENTS-20250421-145039.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changes/unreleased/ENHANCEMENTS-20250421-145039.yaml diff --git a/.changes/unreleased/ENHANCEMENTS-20250421-145039.yaml b/.changes/unreleased/ENHANCEMENTS-20250421-145039.yaml new file mode 100644 index 000000000..fa562bad3 --- /dev/null +++ b/.changes/unreleased/ENHANCEMENTS-20250421-145039.yaml @@ -0,0 +1,5 @@ +kind: ENHANCEMENTS +body: Adds `AdditionalCLIOptions.PlanOptions.NoRefresh` to test `terraform plan -refresh=false` +time: 2025-04-21T14:50:39.764057-04:00 +custom: + Issue: "490"