Skip to content

Commit 51aaf7a

Browse files
authored
Merge branch 'main' into tidy
2 parents 456fde3 + ae29586 commit 51aaf7a

File tree

4 files changed

+43
-25
lines changed

4 files changed

+43
-25
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: ENHANCEMENTS
2+
body: Adds `AdditionalCLIOptions.PlanOptions.NoRefresh` to test `terraform plan -refresh=false`
3+
time: 2025-04-21T14:50:39.764057-04:00
4+
custom:
5+
Issue: "490"

helper/resource/additional_cli_options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ type ApplyOptions struct {
2323
type PlanOptions struct {
2424
// AllowDeferral will pass the experimental `-allow-deferral` flag to the plan command.
2525
AllowDeferral bool
26+
27+
// NoRefresh will pass the `-refresh=false` flag to the plan command.
28+
NoRefresh bool
2629
}

helper/resource/testing_new_config.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,13 @@ func testStepNewConfig(ctx context.Context, t testing.T, c TestCase, wd *plugint
108108
opts = append(opts, tfexec.Destroy(true))
109109
}
110110

111-
if c.AdditionalCLIOptions != nil && c.AdditionalCLIOptions.Plan.AllowDeferral {
112-
opts = append(opts, tfexec.AllowDeferral(true))
111+
if c.AdditionalCLIOptions != nil {
112+
if c.AdditionalCLIOptions.Plan.AllowDeferral {
113+
opts = append(opts, tfexec.AllowDeferral(true))
114+
}
115+
if c.AdditionalCLIOptions.Plan.NoRefresh {
116+
opts = append(opts, tfexec.Refresh(false))
117+
}
113118
}
114119

115120
return wd.CreatePlan(ctx, opts...)
@@ -250,8 +255,13 @@ func testStepNewConfig(ctx context.Context, t testing.T, c TestCase, wd *plugint
250255
opts = append(opts, tfexec.Destroy(true))
251256
}
252257

253-
if c.AdditionalCLIOptions != nil && c.AdditionalCLIOptions.Plan.AllowDeferral {
254-
opts = append(opts, tfexec.AllowDeferral(true))
258+
if c.AdditionalCLIOptions != nil {
259+
if c.AdditionalCLIOptions.Plan.AllowDeferral {
260+
opts = append(opts, tfexec.AllowDeferral(true))
261+
}
262+
if c.AdditionalCLIOptions.Plan.NoRefresh {
263+
opts = append(opts, tfexec.Refresh(false))
264+
}
255265
}
256266

257267
return wd.CreatePlan(ctx, opts...)
@@ -319,8 +329,13 @@ func testStepNewConfig(ctx context.Context, t testing.T, c TestCase, wd *plugint
319329
}
320330
}
321331

322-
if c.AdditionalCLIOptions != nil && c.AdditionalCLIOptions.Plan.AllowDeferral {
323-
opts = append(opts, tfexec.AllowDeferral(true))
332+
if c.AdditionalCLIOptions != nil {
333+
if c.AdditionalCLIOptions.Plan.AllowDeferral {
334+
opts = append(opts, tfexec.AllowDeferral(true))
335+
}
336+
if c.AdditionalCLIOptions.Plan.NoRefresh {
337+
opts = append(opts, tfexec.Refresh(false))
338+
}
324339
}
325340

326341
return wd.CreatePlan(ctx, opts...)

helper/resource/teststep_providers_test.go

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3360,37 +3360,32 @@ func TestTest_TestStep_ProviderFactories_Import_External_With_Data_Source(t *tes
33603360

33613361
Test(t, TestCase{
33623362
ExternalProviders: map[string]ExternalProvider{
3363-
"http": {
3364-
Source: "registry.terraform.io/hashicorp/http",
3363+
"null": {
3364+
Source: "registry.terraform.io/hashicorp/null",
33653365
},
33663366
"random": {
33673367
Source: "registry.terraform.io/hashicorp/random",
33683368
},
33693369
},
33703370
Steps: []TestStep{
33713371
{
3372-
Config: `data "http" "example" {
3373-
url = "https://checkpoint-api.hashicorp.com/v1/check/terraform"
3372+
Config: `
3373+
data "null_data_source" "values" {
3374+
inputs = {
3375+
length = 12
33743376
}
3377+
}
33753378
3376-
resource "random_string" "example" {
3377-
length = length(data.http.example.response_headers)
3378-
}`,
3379+
resource "random_string" "example" {
3380+
length = data.null_data_source.values.outputs["length"]
3381+
}
3382+
`,
33793383
Check: extractResourceAttr("random_string.example", "id", &id),
33803384
},
33813385
{
3382-
Config: `data "http" "example" {
3383-
url = "https://checkpoint-api.hashicorp.com/v1/check/terraform"
3384-
}
3385-
3386-
resource "random_string" "example" {
3387-
length = length(data.http.example.response_headers)
3388-
}`,
3389-
ResourceName: "random_string.example",
3390-
ImportState: true,
3391-
ImportStateCheck: composeImportStateCheck(
3392-
testCheckResourceAttrInstanceState(&id, "length", "12"),
3393-
),
3386+
ResourceName: "random_string.example",
3387+
ImportState: true,
3388+
ImportStateCheck: testCheckResourceAttrInstanceState(&id, "length", "12"),
33943389
ImportStateVerify: true,
33953390
},
33963391
},

0 commit comments

Comments
 (0)