|
|
|
|
@ -2163,6 +2163,86 @@ import {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestContext2Apply_destroySkipsVariableValidations(t *testing.T) {
|
|
|
|
|
m := testModuleInline(t, map[string]string{
|
|
|
|
|
"main.tf": `
|
|
|
|
|
variable "input" {
|
|
|
|
|
type = string
|
|
|
|
|
|
|
|
|
|
validation {
|
|
|
|
|
condition = var.input == "foo"
|
|
|
|
|
error_message = "bad input"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "test_object" "a" {
|
|
|
|
|
test_string = var.input
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
p := simpleMockProvider()
|
|
|
|
|
ctx := testContext2(t, &ContextOpts{
|
|
|
|
|
Providers: map[addrs.Provider]providers.Factory{
|
|
|
|
|
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
plan, diags := ctx.Plan(m, states.BuildState(func(state *states.SyncState) {
|
|
|
|
|
state.SetResourceInstanceCurrent(
|
|
|
|
|
mustResourceInstanceAddr("test_object.a"),
|
|
|
|
|
&states.ResourceInstanceObjectSrc{
|
|
|
|
|
Status: states.ObjectReady,
|
|
|
|
|
AttrsJSON: []byte(`{"test_string":"foo"}`),
|
|
|
|
|
},
|
|
|
|
|
mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`),
|
|
|
|
|
)
|
|
|
|
|
}), &PlanOpts{
|
|
|
|
|
Mode: plans.DestroyMode,
|
|
|
|
|
SetVariables: InputValues{
|
|
|
|
|
"input": {
|
|
|
|
|
Value: cty.StringVal("foo"),
|
|
|
|
|
SourceType: ValueFromCLIArg,
|
|
|
|
|
SourceRange: tfdiags.SourceRange{},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
if diags.HasErrors() {
|
|
|
|
|
t.Errorf("expected no errors, but got %s", diags)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
planResult := plan.Checks.GetObjectResult(addrs.AbsInputVariableInstance{
|
|
|
|
|
Variable: addrs.InputVariable{
|
|
|
|
|
Name: "input",
|
|
|
|
|
},
|
|
|
|
|
Module: addrs.RootModuleInstance,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if planResult.Status != checks.StatusPass {
|
|
|
|
|
// Should have passed during the planning stage indicating that it did
|
|
|
|
|
// actually execute.
|
|
|
|
|
t.Errorf("expected checks to be pass but was %s", planResult.Status)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
state, diags := ctx.Apply(plan, m)
|
|
|
|
|
if diags.HasErrors() {
|
|
|
|
|
t.Errorf("expected no errors, but got %s", diags)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
applyResult := state.CheckResults.GetObjectResult(addrs.AbsInputVariableInstance{
|
|
|
|
|
Variable: addrs.InputVariable{
|
|
|
|
|
Name: "input",
|
|
|
|
|
},
|
|
|
|
|
Module: addrs.RootModuleInstance,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if applyResult.Status != checks.StatusUnknown {
|
|
|
|
|
// Shouldn't have made any validations here, so result should have
|
|
|
|
|
// stayed as unknown.
|
|
|
|
|
t.Errorf("expected checks to be unknown but was %s", applyResult.Status)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestContext2Apply_noExternalReferences(t *testing.T) {
|
|
|
|
|
m := testModuleInline(t, map[string]string{
|
|
|
|
|
"main.tf": `
|
|
|
|
|
|