From dd3f79195a3a290078639d05b4010ee592675c2a Mon Sep 17 00:00:00 2001 From: Samsondeen Dare Date: Tue, 7 Jan 2025 12:28:18 +0100 Subject: [PATCH] rename to override_during --- internal/command/test_test.go | 4 ++-- .../tests/plan_mocked_provider.tftest.hcl | 2 +- ...erride_computed_invalid_boolean.tftest.hcl | 2 +- .../tests/plan_mocked_overridden.tftest.hcl | 4 ++-- .../tests/plan_mocked_provider.tftest.hcl | 4 ++-- ...plan_mocked_provider_overridden.tftest.hcl | 10 +++++----- internal/configs/mock_provider.go | 20 +++++++++---------- internal/configs/parser_config_dir_test.go | 18 ++++++++--------- internal/moduletest/eval_context.go | 2 +- 9 files changed, 33 insertions(+), 33 deletions(-) diff --git a/internal/command/test_test.go b/internal/command/test_test.go index a41a39a9dede..71708bfaf576 100644 --- a/internal/command/test_test.go +++ b/internal/command/test_test.go @@ -225,7 +225,7 @@ func TestTest_Runs(t *testing.T) { "mocking-invalid": { expectedErr: []string{ "Invalid outputs attribute", - "The override_target attribute must be a value of plan or apply.", + "The override_during attribute must be a value of plan or apply.", }, initCode: 1, }, @@ -1763,7 +1763,7 @@ condition depended on is not known until after the plan has been applied. Either remove this value from your condition, or execute an %s command from this %s block. Alternatively, if there is an override for this value, you can make it available during the plan phase by setting %s in the %s block. -`, "`run`", "`command = plan`", "`apply`", "`run`", "`override_target\n= plan`", "`override_`"), +`, "`run`", "`command = plan`", "`apply`", "`run`", "`override_during\n= plan`", "`override_`"), }, "unknown_value_in_vars": { code: 1, diff --git a/internal/command/testdata/test/mocking-error/tests/plan_mocked_provider.tftest.hcl b/internal/command/testdata/test/mocking-error/tests/plan_mocked_provider.tftest.hcl index f1cd355ca98a..ed387c5be822 100644 --- a/internal/command/testdata/test/mocking-error/tests/plan_mocked_provider.tftest.hcl +++ b/internal/command/testdata/test/mocking-error/tests/plan_mocked_provider.tftest.hcl @@ -19,7 +19,7 @@ run "test" { assert { condition = test_resource.secondary[0].id == "ffff" - error_message = "plan should use the mocked provider value when override_target is plan" + error_message = "plan should use the mocked provider value when override_during is plan" } } diff --git a/internal/command/testdata/test/mocking-invalid/tests/override_computed_invalid_boolean.tftest.hcl b/internal/command/testdata/test/mocking-invalid/tests/override_computed_invalid_boolean.tftest.hcl index d35a7eecfff3..ce346c6d5476 100644 --- a/internal/command/testdata/test/mocking-invalid/tests/override_computed_invalid_boolean.tftest.hcl +++ b/internal/command/testdata/test/mocking-invalid/tests/override_computed_invalid_boolean.tftest.hcl @@ -1,6 +1,6 @@ mock_provider "test" { alias = "primary" - override_target = baz // This should either be plan or apply, therefore this test should fail + override_during = baz // This should either be plan or apply, therefore this test should fail mock_resource "test_resource" { defaults = { diff --git a/internal/command/testdata/test/mocking/tests/plan_mocked_overridden.tftest.hcl b/internal/command/testdata/test/mocking/tests/plan_mocked_overridden.tftest.hcl index 2e2372894817..f5dd295096a0 100644 --- a/internal/command/testdata/test/mocking/tests/plan_mocked_overridden.tftest.hcl +++ b/internal/command/testdata/test/mocking/tests/plan_mocked_overridden.tftest.hcl @@ -9,7 +9,7 @@ mock_provider "test" { override_resource { target = test_resource.primary - override_target = plan + override_during = plan values = { id = "bbbb" } @@ -26,7 +26,7 @@ run "test" { assert { condition = test_resource.primary[0].id == "bbbb" - error_message = "plan should override the value when override_target is plan" + error_message = "plan should override the value when override_during is plan" } } diff --git a/internal/command/testdata/test/mocking/tests/plan_mocked_provider.tftest.hcl b/internal/command/testdata/test/mocking/tests/plan_mocked_provider.tftest.hcl index d293d4248581..c47755d4b577 100644 --- a/internal/command/testdata/test/mocking/tests/plan_mocked_provider.tftest.hcl +++ b/internal/command/testdata/test/mocking/tests/plan_mocked_provider.tftest.hcl @@ -1,6 +1,6 @@ mock_provider "test" { alias = "secondary" - override_target = plan + override_during = plan mock_resource "test_resource" { defaults = { @@ -20,7 +20,7 @@ run "test" { assert { condition = test_resource.secondary[0].id == "ffff" - error_message = "plan should use the mocked provider value when override_target is plan" + error_message = "plan should use the mocked provider value when override_during is plan" } } diff --git a/internal/command/testdata/test/mocking/tests/plan_mocked_provider_overridden.tftest.hcl b/internal/command/testdata/test/mocking/tests/plan_mocked_provider_overridden.tftest.hcl index 847438b47b48..9c553deda2a2 100644 --- a/internal/command/testdata/test/mocking/tests/plan_mocked_provider_overridden.tftest.hcl +++ b/internal/command/testdata/test/mocking/tests/plan_mocked_provider_overridden.tftest.hcl @@ -1,6 +1,6 @@ mock_provider "test" { alias = "primary" - override_target = plan + override_during = plan mock_resource "test_resource" { defaults = { @@ -17,7 +17,7 @@ mock_provider "test" { override_resource { target = test_resource.primary[1] - override_target = apply // this should take precedence over the provider-level override_target + override_during = apply // this should take precedence over the provider-level override_during values = { id = "bbbb" } @@ -27,7 +27,7 @@ mock_provider "test" { override_resource { target = test_resource.secondary[0] - override_target = plan + override_during = plan values = { id = "ssss" } @@ -44,12 +44,12 @@ run "test" { assert { condition = test_resource.primary[0].id == "bbbb" - error_message = "plan should override the value when override_target is plan" + error_message = "plan should override the value when override_during is plan" } assert { condition = test_resource.secondary[0].id == "ssss" - error_message = "plan should override the value when override_target is plan" + error_message = "plan should override the value when override_during is plan" } } diff --git a/internal/configs/mock_provider.go b/internal/configs/mock_provider.go index 3cc288c52754..f6d05bfcdcba 100644 --- a/internal/configs/mock_provider.go +++ b/internal/configs/mock_provider.go @@ -16,7 +16,7 @@ var ( // When this attribute is set to plan, the values specified in the override // block will be used for computed attributes even when planning. It defaults // to apply, meaning that the values will only be used during apply. - overrideTargetCommand = "override_target" + overrideDuringCommand = "override_during" ) func decodeMockProviderBlock(block *hcl.Block) (*Provider, hcl.Diagnostics) { @@ -72,16 +72,16 @@ func decodeMockProviderBlock(block *hcl.Block) (*Provider, hcl.Diagnostics) { return provider, diags } -func extractOverrideComputed(content *hcl.BodyContent) (*string, hcl.Diagnostics) { +func extractOverrideDuring(content *hcl.BodyContent) (*string, hcl.Diagnostics) { var diags hcl.Diagnostics - if attr, exists := content.Attributes[overrideTargetCommand]; exists { + if attr, exists := content.Attributes[overrideDuringCommand]; exists { overrideComputedStr := hcl.ExprAsKeyword(attr.Expr) if overrideComputedStr != "plan" && overrideComputedStr != "apply" { diags = diags.Append(&hcl.Diagnostic{ Severity: hcl.DiagError, - Summary: fmt.Sprintf("Invalid %s value", overrideTargetCommand), - Detail: fmt.Sprintf("The %s attribute must be a value of plan or apply.", overrideTargetCommand), + Summary: fmt.Sprintf("Invalid %s value", overrideDuringCommand), + Detail: fmt.Sprintf("The %s attribute must be a value of plan or apply.", overrideDuringCommand), Subject: attr.Range.Ptr(), }) } @@ -235,7 +235,7 @@ func decodeMockDataBody(body hcl.Body, source OverrideSource) (*MockData, hcl.Di diags = append(diags, contentDiags...) // provider-level setting for overrideComputed - providerOverrideComputed, valueDiags := extractOverrideComputed(content) + providerOverrideComputed, valueDiags := extractOverrideDuring(content) diags = append(diags, valueDiags...) useForPlan := providerOverrideComputed != nil && *providerOverrideComputed == "plan" data := &MockData{ @@ -460,7 +460,7 @@ func decodeOverrideBlock(block *hcl.Block, attributeName string, blockName strin content, contentDiags := block.Body.Content(&hcl.BodySchema{ Attributes: []hcl.AttributeSchema{ {Name: "target"}, - {Name: overrideTargetCommand}, + {Name: overrideDuringCommand}, {Name: attributeName}, }, }) @@ -502,8 +502,8 @@ func decodeOverrideBlock(block *hcl.Block, attributeName string, blockName strin override.Values = cty.EmptyObjectVal } - // Override computed values during planning if override_target is plan. - overrideComputedStr, valueDiags := extractOverrideComputed(content) + // Override computed values during planning if override_during is plan. + overrideComputedStr, valueDiags := extractOverrideDuring(content) diags = append(diags, valueDiags...) if overrideComputedStr != nil { useForPlan := *overrideComputedStr == "plan" @@ -544,7 +544,7 @@ var mockProviderSchema = &hcl.BodySchema{ var mockDataSchema = &hcl.BodySchema{ Attributes: []hcl.AttributeSchema{ - {Name: overrideTargetCommand}, + {Name: overrideDuringCommand}, }, Blocks: []hcl.BlockHeaderSchema{ {Type: "mock_resource", LabelNames: []string{"type"}}, diff --git a/internal/configs/parser_config_dir_test.go b/internal/configs/parser_config_dir_test.go index 7f6132fc718e..03c2aeb82318 100644 --- a/internal/configs/parser_config_dir_test.go +++ b/internal/configs/parser_config_dir_test.go @@ -186,9 +186,9 @@ func TestParserLoadTestFiles_Invalid(t *testing.T) { "invalid_data_override": { "invalid_data_override.tftest.hcl:6,1-14: Missing target attribute; override_data blocks must specify a target address.", }, - "invalid_data_override_target": { - "invalid_data_override_target.tftest.hcl:8,3-24: Invalid override target; You can only target data sources from override_data blocks, not module.child.", - "invalid_data_override_target.tftest.hcl:3,3-31: Invalid override target; You can only target data sources from override_data blocks, not aws_instance.target.", + "invalid_data_override_during": { + "invalid_data_override_during.tftest.hcl:8,3-24: Invalid override target; You can only target data sources from override_data blocks, not module.child.", + "invalid_data_override_during.tftest.hcl:3,3-31: Invalid override target; You can only target data sources from override_data blocks, not aws_instance.target.", }, "invalid_mock_data_sources": { "invalid_mock_data_sources.tftest.hcl:7,13-16: Variables not allowed; Variables may not be used here.", @@ -200,16 +200,16 @@ func TestParserLoadTestFiles_Invalid(t *testing.T) { "invalid_module_override.tftest.hcl:5,1-16: Missing target attribute; override_module blocks must specify a target address.", "invalid_module_override.tftest.hcl:11,3-9: Unsupported argument; An argument named \"values\" is not expected here.", }, - "invalid_module_override_target": { - "invalid_module_override_target.tftest.hcl:3,3-31: Invalid override target; You can only target modules from override_module blocks, not aws_instance.target.", - "invalid_module_override_target.tftest.hcl:8,3-36: Invalid override target; You can only target modules from override_module blocks, not data.aws_instance.target.", + "invalid_module_override_during": { + "invalid_module_override_during.tftest.hcl:3,3-31: Invalid override target; You can only target modules from override_module blocks, not aws_instance.target.", + "invalid_module_override_during.tftest.hcl:8,3-36: Invalid override target; You can only target modules from override_module blocks, not data.aws_instance.target.", }, "invalid_resource_override": { "invalid_resource_override.tftest.hcl:6,1-18: Missing target attribute; override_resource blocks must specify a target address.", }, - "invalid_resource_override_target": { - "invalid_resource_override_target.tftest.hcl:3,3-36: Invalid override target; You can only target resources from override_resource blocks, not data.aws_instance.target.", - "invalid_resource_override_target.tftest.hcl:8,3-24: Invalid override target; You can only target resources from override_resource blocks, not module.child.", + "invalid_resource_override_during": { + "invalid_resource_override_during.tftest.hcl:3,3-36: Invalid override target; You can only target resources from override_resource blocks, not data.aws_instance.target.", + "invalid_resource_override_during.tftest.hcl:8,3-24: Invalid override target; You can only target resources from override_resource blocks, not module.child.", }, } diff --git a/internal/moduletest/eval_context.go b/internal/moduletest/eval_context.go index 7a7b8a3fea12..ba627ecf5196 100644 --- a/internal/moduletest/eval_context.go +++ b/internal/moduletest/eval_context.go @@ -141,7 +141,7 @@ func (ec *EvalContext) Evaluate() (Status, cty.Value, tfdiags.Diagnostics) { diags = diags.Append(&hcl.Diagnostic{ Severity: hcl.DiagError, Summary: "Unknown condition value", - Detail: "Condition expression could not be evaluated at this time. This means you have executed a `run` block with `command = plan` and one of the values your condition depended on is not known until after the plan has been applied. Either remove this value from your condition, or execute an `apply` command from this `run` block. Alternatively, if there is an override for this value, you can make it available during the plan phase by setting `override_target = plan` in the `override_` block.", + Detail: "Condition expression could not be evaluated at this time. This means you have executed a `run` block with `command = plan` and one of the values your condition depended on is not known until after the plan has been applied. Either remove this value from your condition, or execute an `apply` command from this `run` block. Alternatively, if there is an override for this value, you can make it available during the plan phase by setting `override_during = plan` in the `override_` block.", Subject: rule.Condition.Range().Ptr(), Expression: rule.Condition, EvalContext: hclCtx,