add required attr to import test

Missing required attributes should not prevent importing
This commit is contained in:
James Bardin 2022-06-22 13:30:42 -04:00
parent 4981942191
commit c43df009db

View File

@ -790,7 +790,7 @@ func TestContextImport_multiStateSame(t *testing.T) {
} }
} }
func TestContextImport_noConfigModuleImport(t *testing.T) { func TestContextImport_nestedModuleImport(t *testing.T) {
p := testProvider("aws") p := testProvider("aws")
m := testModuleInline(t, map[string]string{ m := testModuleInline(t, map[string]string{
"main.tf": ` "main.tf": `
@ -824,6 +824,7 @@ variable "y" {
resource "test_resource" "unused" { resource "test_resource" "unused" {
value = var.y value = var.y
// missing required, but should not error
} }
`, `,
}) })
@ -838,6 +839,7 @@ resource "test_resource" "unused" {
"test_resource": { "test_resource": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Computed: true}, "id": {Type: cty.String, Computed: true},
"required": {Type: cty.String, Required: true},
}, },
}, },
}, },
@ -849,16 +851,7 @@ resource "test_resource" "unused" {
TypeName: "test_resource", TypeName: "test_resource",
State: cty.ObjectVal(map[string]cty.Value{ State: cty.ObjectVal(map[string]cty.Value{
"id": cty.StringVal("test"), "id": cty.StringVal("test"),
}), "required": cty.StringVal("value"),
},
},
}
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
ImportedResources: []providers.ImportedResource{
{
TypeName: "test_resource",
State: cty.ObjectVal(map[string]cty.Value{
"id": cty.StringVal("test"),
}), }),
}, },
}, },
@ -885,7 +878,7 @@ resource "test_resource" "unused" {
} }
ri := state.ResourceInstance(mustResourceInstanceAddr("test_resource.test")) ri := state.ResourceInstance(mustResourceInstanceAddr("test_resource.test"))
expected := `{"id":"test"}` expected := `{"id":"test","required":"value"}`
if ri == nil || ri.Current == nil { if ri == nil || ri.Current == nil {
t.Fatal("no state is recorded for resource instance test_resource.test") t.Fatal("no state is recorded for resource instance test_resource.test")
} }