filter null output values from state
While null values should not normally appear in a state file, we should filter the values rather than crash.
This commit is contained in:
parent
ea50f455ed
commit
13433687cb
|
@ -118,7 +118,9 @@ func dataSourceRemoteStateRead(d *schema.ResourceData, meta interface{}) error {
|
|||
log.Println("[DEBUG] empty remote state")
|
||||
} else {
|
||||
for key, val := range remoteState.RootModule().Outputs {
|
||||
outputMap[key] = val.Value
|
||||
if val.Value != nil {
|
||||
outputMap[key] = val.Value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,6 +63,20 @@ func TestState_complexOutputs(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
// outputs should never have a null value, but don't crash if we ever encounter
|
||||
// them.
|
||||
func TestState_nullOutputs(t *testing.T) {
|
||||
resource.UnitTest(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccState_nullOutputs,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestEmptyState_defaults(t *testing.T) {
|
||||
resource.UnitTest(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
|
@ -142,6 +156,15 @@ resource "terraform_remote_state" "foo" {
|
|||
}
|
||||
}`
|
||||
|
||||
const testAccState_nullOutputs = `
|
||||
resource "terraform_remote_state" "foo" {
|
||||
backend = "local"
|
||||
|
||||
config {
|
||||
path = "./test-fixtures/null_outputs.tfstate"
|
||||
}
|
||||
}`
|
||||
|
||||
const testAccEmptyState_defaults = `
|
||||
data "terraform_remote_state" "foo" {
|
||||
backend = "local"
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"version": 3,
|
||||
"terraform_version": "0.7.0",
|
||||
"serial": 3,
|
||||
"modules": [
|
||||
{
|
||||
"path": [
|
||||
"root"
|
||||
],
|
||||
"outputs": {
|
||||
"map": {
|
||||
"sensitive": false,
|
||||
"type": "map",
|
||||
"value": null
|
||||
},
|
||||
"list": {
|
||||
"sensitive": false,
|
||||
"type": "list",
|
||||
"value": null
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue