helper/resource: ignore data resource diffs during destroy
When testing destroy, the test harness calls Refresh followed by Plan, with the expectation that the resulting diff will be empty. Data resources challenge this expectation, because they will always be instantiated during refresh if their configuration isn't computed, and so the subsequent diff will want to destroy what was instantiated. To work around this, we make an exception that data resource destroy diffs may appear in the plan but nothing else. This fixes #6713.
This commit is contained in:
parent
18803d9b93
commit
031b561ef0
|
@ -3,6 +3,7 @@ package resource
|
|||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
@ -108,7 +109,32 @@ func testStep(
|
|||
if p, err = ctx.Plan(); err != nil {
|
||||
return state, fmt.Errorf("Error on second follow-up plan: %s", err)
|
||||
}
|
||||
if p.Diff != nil && !p.Diff.Empty() {
|
||||
empty := p.Diff == nil || p.Diff.Empty()
|
||||
|
||||
// Data resources are tricky because they legitimately get instantiated
|
||||
// during refresh so that they will be already populated during the
|
||||
// plan walk. Because of this, if we have any data resources in the
|
||||
// config we'll end up wanting to destroy them again here. This is
|
||||
// acceptable and expected, and we'll treat it as "empty" for the
|
||||
// sake of this testing.
|
||||
if step.Destroy {
|
||||
empty = true
|
||||
|
||||
for _, moduleDiff := range p.Diff.Modules {
|
||||
for k, instanceDiff := range moduleDiff.Resources {
|
||||
if !strings.HasPrefix(k, "data.") {
|
||||
empty = false
|
||||
break
|
||||
}
|
||||
|
||||
if !instanceDiff.Destroy {
|
||||
empty = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !empty {
|
||||
if step.ExpectNonEmptyPlan {
|
||||
log.Printf("[INFO] Got non-empty plan, as expected:\n\n%s", p)
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue