Merge pull request #21764 from hashicorp/jbardin/normalize-import-blocks
normalize empty blocks during import
This commit is contained in:
commit
c7058eaa52
|
@ -30,6 +30,46 @@ resource "test_resource_nested_set" "foo" {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestResourceNestedSet_basicImport(t *testing.T) {
|
||||||
|
resource.UnitTest(t, resource.TestCase{
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckResourceDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: strings.TrimSpace(`
|
||||||
|
resource "test_resource_nested_set" "foo" {
|
||||||
|
single {
|
||||||
|
value = "bar"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`),
|
||||||
|
},
|
||||||
|
resource.TestStep{
|
||||||
|
ImportState: true,
|
||||||
|
ResourceName: "test_resource_nested_set.foo",
|
||||||
|
Config: strings.TrimSpace(`
|
||||||
|
resource "test_resource_nested_set" "foo" {
|
||||||
|
single {
|
||||||
|
value = "bar"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`),
|
||||||
|
ImportStateCheck: func(ss []*terraform.InstanceState) error {
|
||||||
|
for _, s := range ss {
|
||||||
|
if s.Attributes["multi.#"] != "0" ||
|
||||||
|
s.Attributes["single.#"] != "0" ||
|
||||||
|
s.Attributes["type_list.#"] != "0" ||
|
||||||
|
s.Attributes["with_list.#"] != "0" {
|
||||||
|
return fmt.Errorf("missing blocks in imported state:\n%s", s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// The set should not be generated because of it's computed value
|
// The set should not be generated because of it's computed value
|
||||||
func TestResourceNestedSet_noSet(t *testing.T) {
|
func TestResourceNestedSet_noSet(t *testing.T) {
|
||||||
checkFunc := func(s *terraform.State) error {
|
checkFunc := func(s *terraform.State) error {
|
||||||
|
|
|
@ -967,6 +967,9 @@ func (s *GRPCProviderServer) ImportResourceState(_ context.Context, req *proto.I
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Normalize the value and fill in any missing blocks.
|
||||||
|
newStateVal = objchange.NormalizeObjectFromLegacySDK(newStateVal, schemaBlock)
|
||||||
|
|
||||||
newStateMP, err := msgpack.Marshal(newStateVal, schemaBlock.ImpliedType())
|
newStateMP, err := msgpack.Marshal(newStateVal, schemaBlock.ImpliedType())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, err)
|
||||||
|
|
Loading…
Reference in New Issue