Skip to content

Commit

Permalink
add required attr to import test
Browse files Browse the repository at this point in the history
Missing required attributes should not prevent importing
  • Loading branch information
jbardin committed Jun 22, 2022
1 parent 4981942 commit c43df00
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions internal/terraform/context_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
m := testModuleInline(t, map[string]string{
"main.tf": `
Expand Down Expand Up @@ -824,6 +824,7 @@ variable "y" {
resource "test_resource" "unused" {
value = var.y
// missing required, but should not error
}
`,
})
Expand All @@ -837,7 +838,8 @@ resource "test_resource" "unused" {
ResourceTypes: map[string]*configschema.Block{
"test_resource": {
Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Computed: true},
"id": {Type: cty.String, Computed: true},
"required": {Type: cty.String, Required: true},
},
},
},
Expand All @@ -848,17 +850,8 @@ resource "test_resource" "unused" {
{
TypeName: "test_resource",
State: cty.ObjectVal(map[string]cty.Value{
"id": cty.StringVal("test"),
}),
},
},
}
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
ImportedResources: []providers.ImportedResource{
{
TypeName: "test_resource",
State: cty.ObjectVal(map[string]cty.Value{
"id": cty.StringVal("test"),
"id": cty.StringVal("test"),
"required": cty.StringVal("value"),
}),
},
},
Expand All @@ -885,7 +878,7 @@ resource "test_resource" "unused" {
}

ri := state.ResourceInstance(mustResourceInstanceAddr("test_resource.test"))
expected := `{"id":"test"}`
expected := `{"id":"test","required":"value"}`
if ri == nil || ri.Current == nil {
t.Fatal("no state is recorded for resource instance test_resource.test")
}
Expand Down

0 comments on commit c43df00

Please sign in to comment.