Skip to content

Commit

Permalink
rename to override_during
Browse files Browse the repository at this point in the history
  • Loading branch information
dsa0x committed Jan 7, 2025
1 parent 2f014ac commit 0cdeaa9
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions internal/command/test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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 =\nplan`", "`override_`"),
},
"unknown_value_in_vars": {
code: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

}
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mock_provider "test" {

override_resource {
target = test_resource.primary
override_target = plan
override_during = plan
values = {
id = "bbbb"
}
Expand All @@ -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"
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mock_provider "test" {
alias = "secondary"
override_target = plan
override_during = plan

mock_resource "test_resource" {
defaults = {
Expand All @@ -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"
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mock_provider "test" {
alias = "primary"
override_target = plan
override_during = plan

mock_resource "test_resource" {
defaults = {
Expand All @@ -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"
}
Expand All @@ -27,7 +27,7 @@ mock_provider "test" {

override_resource {
target = test_resource.secondary[0]
override_target = plan
override_during = plan
values = {
id = "ssss"
}
Expand All @@ -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"
}

}
20 changes: 10 additions & 10 deletions internal/configs/mock_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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(),
})
}
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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},
},
})
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"}},
Expand Down
2 changes: 1 addition & 1 deletion internal/moduletest/eval_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0cdeaa9

Please sign in to comment.