Bumps [github.com/hashicorp/terraform-plugin-sdk/v2](https://github.com/hashicorp/terraform-plugin-sdk) from 2.26.1 to 2.27.0. - [Release notes](https://github.com/hashicorp/terraform-plugin-sdk/releases) - [Changelog](https://github.com/hashicorp/terraform-plugin-sdk/blob/main/CHANGELOG.md) - [Commits](https://github.com/hashicorp/terraform-plugin-sdk/compare/v2.26.1...v2.27.0) --- updated-dependencies: - dependency-name: github.com/hashicorp/terraform-plugin-sdk/v2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
97 lines
2.4 KiB
Go
97 lines
2.4 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package resource
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
tfjson "github.com/hashicorp/terraform-json"
|
|
"github.com/mitchellh/go-testing-interface"
|
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/internal/logging"
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/internal/plugintest"
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
|
|
)
|
|
|
|
func testStepNewRefreshState(ctx context.Context, t testing.T, wd *plugintest.WorkingDir, step TestStep, providers *providerFactories) error {
|
|
t.Helper()
|
|
|
|
var err error
|
|
// Explicitly ensure prior state exists before refresh.
|
|
err = runProviderCommand(ctx, t, func() error {
|
|
_, err = getState(ctx, t, wd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}, wd, providers)
|
|
if err != nil {
|
|
t.Fatalf("Error getting state: %s", err)
|
|
}
|
|
|
|
err = runProviderCommand(ctx, t, func() error {
|
|
return wd.Refresh(ctx)
|
|
}, wd, providers)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var refreshState *terraform.State
|
|
err = runProviderCommand(ctx, t, func() error {
|
|
refreshState, err = getState(ctx, t, wd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}, wd, providers)
|
|
if err != nil {
|
|
t.Fatalf("Error getting state: %s", err)
|
|
}
|
|
|
|
// Go through the refreshed state and verify
|
|
if step.Check != nil {
|
|
logging.HelperResourceDebug(ctx, "Calling TestStep Check for RefreshState")
|
|
|
|
if err := step.Check(refreshState); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
logging.HelperResourceDebug(ctx, "Called TestStep Check for RefreshState")
|
|
}
|
|
|
|
// do a plan
|
|
err = runProviderCommand(ctx, t, func() error {
|
|
return wd.CreatePlan(ctx)
|
|
}, wd, providers)
|
|
if err != nil {
|
|
return fmt.Errorf("Error running post-apply plan: %w", err)
|
|
}
|
|
|
|
var plan *tfjson.Plan
|
|
err = runProviderCommand(ctx, t, func() error {
|
|
var err error
|
|
plan, err = wd.SavedPlan(ctx)
|
|
return err
|
|
}, wd, providers)
|
|
if err != nil {
|
|
return fmt.Errorf("Error retrieving post-apply plan: %w", err)
|
|
}
|
|
|
|
if !planIsEmpty(plan) && !step.ExpectNonEmptyPlan {
|
|
var stdout string
|
|
err = runProviderCommand(ctx, t, func() error {
|
|
var err error
|
|
stdout, err = wd.SavedPlanRawStdout(ctx)
|
|
return err
|
|
}, wd, providers)
|
|
if err != nil {
|
|
return fmt.Errorf("Error retrieving formatted plan output: %w", err)
|
|
}
|
|
return fmt.Errorf("After refreshing state during this test step, a followup plan was not empty.\nstdout:\n\n%s", stdout)
|
|
}
|
|
|
|
return nil
|
|
}
|