Skip to content

Commit

Permalink
minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dsa0x committed Dec 19, 2024
1 parent 5031c9d commit 3cdb84a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ mock_provider "test" {
}
}


override_resource {
target = test_resource.secondary[0]
override_computed = true
values = {
id = "ssss"
}
}


variables {
instances = 2
child_instances = 1
Expand All @@ -37,4 +47,9 @@ run "test" {
error_message = "plan should override the value when override_computed is true"
}

assert {
condition = test_resource.secondary[0].id == "ssss"
error_message = "plan should override the value when override_computed is true"
}

}
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.",
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_computed = true` in the `override_` block.",
Subject: rule.Condition.Range().Ptr(),
Expression: rule.Condition,
EvalContext: hclCtx,
Expand Down
4 changes: 2 additions & 2 deletions internal/providers/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ func (m *Mock) PlanResourceChange(request PlanResourceChangeRequest) PlanResourc
panic(fmt.Errorf("failed to retrieve schema for resource %s", request.TypeName))
}

// If the provider was overriden in the test (via override_*), the mock provider is not called at all,
// so we can be certain that this provider is not mocked.
// If the provider was overriden via override_* blocks, the mock provider is not called at all,
// so we can continue to make computed values as unknown here (until mock defaults support plan command).
value, diags := mocking.PlanComputedValuesForResource(request.ProposedNewState, &mocking.MockedData{
ComputedAsUnknown: true,
}, resource.Block)
Expand Down

0 comments on commit 3cdb84a

Please sign in to comment.