mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-15 19:22:46 -06:00
bd1a215580
Due to the lossiness of our legacy models for diff and state, shimming a diff and then creating a state from it produces a different result than shimming a state directly. That means that ImportStateVerify no longer works as expected if there are any Computed attributes in the schema where d.Set isn't called during Read. Fixing that for every case would require some risky changes to the shim behavior, so we're instead going to ask provider developers to address it by adding `d.Set` calls where needed, since that is the contract for "Computed" anyway -- a default value should be produced during Create, and thus by extension during Import. However, since a common situation where this occurs is attributes marked as "Removed", since all of the code that deals with them has generally been deleted, we'll avoid problems in that case here by treating Removed attributes as ignored for the purposes of ImportStateVerify. This required exporting some functionality that was formerly unexported in helper/schema, but it's a relatively harmless schema introspection function so shouldn't be a big deal to export it.
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package test
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
)
|
|
|
|
func TestResourceImportRemoved(t *testing.T) {
|
|
resource.UnitTest(t, resource.TestCase{
|
|
Providers: testAccProviders,
|
|
CheckDestroy: testAccCheckResourceDestroy,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: strings.TrimSpace(`
|
|
resource "test_resource_import_removed" "foo" {
|
|
}
|
|
`),
|
|
},
|
|
{
|
|
ImportState: true,
|
|
ResourceName: "test_resource_import_removed.foo",
|
|
|
|
// This is attempting to guard against regressions of:
|
|
// https://github.com/hashicorp/terraform/issues/20985
|
|
//
|
|
// Removed attributes are generally not populated during Create,
|
|
// Update, Read, or Import by provider code but due to our
|
|
// legacy diff format being lossy they end up getting populated
|
|
// with zero values during shimming in all cases except Import,
|
|
// which doesn't go through a diff.
|
|
//
|
|
// This is testing that the shimming inconsistency won't cause
|
|
// ImportStateVerify failures for these, since we now ignore
|
|
// attributes marked as Removed when comparing.
|
|
ImportStateVerify: true,
|
|
},
|
|
},
|
|
})
|
|
}
|