wrong operation during destroy plan walk
The destroy plan walk was identifying itself as a normal plan, and causing providers to be configured when they were not needed. Since the provider configuration may not be complete during the minimal destroy plan walk, validation or configuration may fail.
This commit is contained in:
parent
6839170274
commit
877348c031
|
@ -633,7 +633,7 @@ func (c *Context) destroyPlan() (*plans.Plan, tfdiags.Diagnostics) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do the walk
|
// Do the walk
|
||||||
walker, walkDiags := c.walk(graph, walkPlan)
|
walker, walkDiags := c.walk(graph, walkPlanDestroy)
|
||||||
diags = diags.Append(walker.NonFatalDiagnostics)
|
diags = diags.Append(walker.NonFatalDiagnostics)
|
||||||
diags = diags.Append(walkDiags)
|
diags = diags.Append(walkDiags)
|
||||||
if walkDiags.HasErrors() {
|
if walkDiags.HasErrors() {
|
||||||
|
|
|
@ -439,3 +439,49 @@ output "result" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContext2Plan_destroyNoProviderConfig(t *testing.T) {
|
||||||
|
// providers do not need to be configured during a destroy plan
|
||||||
|
p := simpleMockProvider()
|
||||||
|
p.ValidateProviderConfigFn = func(req providers.ValidateProviderConfigRequest) (resp providers.ValidateProviderConfigResponse) {
|
||||||
|
v := req.Config.GetAttr("test_string")
|
||||||
|
if v.IsNull() || !v.IsKnown() || v.AsString() != "ok" {
|
||||||
|
resp.Diagnostics = resp.Diagnostics.Append(errors.New("invalid provider configuration"))
|
||||||
|
}
|
||||||
|
return resp
|
||||||
|
}
|
||||||
|
|
||||||
|
m := testModuleInline(t, map[string]string{
|
||||||
|
"main.tf": `
|
||||||
|
locals {
|
||||||
|
value = "ok"
|
||||||
|
}
|
||||||
|
|
||||||
|
provider "test" {
|
||||||
|
test_string = local.value
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
})
|
||||||
|
|
||||||
|
addr := mustResourceInstanceAddr("test_object.a")
|
||||||
|
state := states.BuildState(func(s *states.SyncState) {
|
||||||
|
s.SetResourceInstanceCurrent(addr, &states.ResourceInstanceObjectSrc{
|
||||||
|
AttrsJSON: []byte(`{"test_string":"foo"}`),
|
||||||
|
Status: states.ObjectReady,
|
||||||
|
}, mustProviderConfig(`provider["registry.terraform.io/hashicorp/test"]`))
|
||||||
|
})
|
||||||
|
|
||||||
|
ctx := testContext2(t, &ContextOpts{
|
||||||
|
Config: m,
|
||||||
|
State: state,
|
||||||
|
Providers: map[addrs.Provider]providers.Factory{
|
||||||
|
addrs.NewDefaultProvider("test"): testProviderFuncFixed(p),
|
||||||
|
},
|
||||||
|
Destroy: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
_, diags := ctx.Plan()
|
||||||
|
if diags.HasErrors() {
|
||||||
|
t.Fatal(diags.Err())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue