Merge pull request #21879 from hashicorp/jbardin/sdk-panics
prevent sdk panics in 2 specific cases
This commit is contained in:
commit
0d9f84414a
|
@ -137,6 +137,11 @@ func testResourceList() *schema.Resource {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"map_list": {
|
||||||
|
Type: schema.TypeList,
|
||||||
|
Optional: true,
|
||||||
|
Elem: &schema.Schema{Type: schema.TypeMap},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,6 +103,37 @@ resource "test_resource_list" "foo" {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestResourceList_mapList(t *testing.T) {
|
||||||
|
resource.UnitTest(t, resource.TestCase{
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckResourceDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: strings.TrimSpace(`
|
||||||
|
variable "map" {
|
||||||
|
type = map(string)
|
||||||
|
default = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "test_resource_list" "foo" {
|
||||||
|
map_list = [
|
||||||
|
{
|
||||||
|
a = "1"
|
||||||
|
},
|
||||||
|
var.map
|
||||||
|
]
|
||||||
|
}
|
||||||
|
`),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"test_resource_list.foo", "map_list.1", "",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestResourceList_sublist(t *testing.T) {
|
func TestResourceList_sublist(t *testing.T) {
|
||||||
resource.UnitTest(t, resource.TestCase{
|
resource.UnitTest(t, resource.TestCase{
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
|
|
|
@ -219,6 +219,9 @@ func (r *ConfigFieldReader) readMap(k string, schema *Schema) (FieldReadResult,
|
||||||
v, _ := r.Config.Get(key)
|
v, _ := r.Config.Get(key)
|
||||||
result[ik] = v
|
result[ik] = v
|
||||||
}
|
}
|
||||||
|
case nil:
|
||||||
|
// the map may have been empty on the configuration, so we leave the
|
||||||
|
// empty result
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("unknown type: %#v", mraw))
|
panic(fmt.Sprintf("unknown type: %#v", mraw))
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,9 @@ func (r *DiffFieldReader) readMap(
|
||||||
return FieldReadResult{}, err
|
return FieldReadResult{}, err
|
||||||
}
|
}
|
||||||
if source.Exists {
|
if source.Exists {
|
||||||
result = source.Value.(map[string]interface{})
|
// readMap may return a nil value, or an unknown value placeholder in
|
||||||
|
// some cases, causing the type assertion to panic if we don't assign the ok value
|
||||||
|
result, _ = source.Value.(map[string]interface{})
|
||||||
resultSet = true
|
resultSet = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue