Merge pull request #26461 from hashicorp/jbardin/refresh-false

always load instance state when -refresh=false
This commit is contained in:
James Bardin 2020-10-02 12:08:10 -04:00 committed by GitHub
commit 804449eda1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 17 deletions

View File

@ -6403,12 +6403,18 @@ resource "test_instance" "a" {
SkipRefresh: true,
})
_, diags := ctx.Plan()
plan, diags := ctx.Plan()
assertNoErrors(t, diags)
if p.ReadResourceCalled {
t.Fatal("Resource should not have been refreshed")
}
for _, c := range plan.Changes.Resources {
if c.Action != plans.NoOp {
t.Fatalf("expected no changes, got %s for %q", c.Action, c.Addr)
}
}
}
func TestContext2Plan_dataInModuleDependsOn(t *testing.T) {

View File

@ -146,24 +146,23 @@ func (n *NodePlannableResourceInstance) managedResourceExecute(ctx EvalContext,
return err
}
instanceRefreshState, err = n.ReadResourceInstanceState(ctx, addr)
if err != nil {
return err
}
refreshLifecycle := &EvalRefreshLifecycle{
Addr: addr,
Config: n.Config,
State: &instanceRefreshState,
ForceCreateBeforeDestroy: n.ForceCreateBeforeDestroy,
}
_, err = refreshLifecycle.Eval(ctx)
if err != nil {
return err
}
// Refresh, maybe
if !skipRefresh {
instanceRefreshState, err = n.ReadResourceInstanceState(ctx, addr)
if err != nil {
return err
}
refreshLifecycle := &EvalRefreshLifecycle{
Addr: addr,
Config: n.Config,
State: &instanceRefreshState,
ForceCreateBeforeDestroy: n.ForceCreateBeforeDestroy,
}
_, err = refreshLifecycle.Eval(ctx)
if err != nil {
return err
}
refresh := &EvalRefresh{
Addr: addr.Resource,
ProviderAddr: n.ResolvedProvider,