Merge pull request #17531 from hashicorp/jbardin/null-output

filter null output values from state
This commit is contained in:
James Bardin 2018-03-08 13:29:02 -05:00 committed by GitHub
commit 5727d33352
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 1 deletions

View File

@ -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
}
}
}

View File

@ -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"

View File

@ -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
}
}
}
]
}