test a nil computed value within an expression

Comparing a nil-computed value was returning unknown, preventing the
data source from being evaluated.
This commit is contained in:
James Bardin 2018-11-28 15:41:25 -05:00
parent 4836dffd81
commit f0e51aca1a
2 changed files with 39 additions and 0 deletions

View File

@ -26,6 +26,11 @@ func testDataSource() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
// this attribute is computed, but never set by the provider
"nil": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

View File

@ -155,3 +155,37 @@ data "test_data_source" "baz" {
input = "${data.test_data_source.bar.*.output[count.index]}"
}
`
func TestDataSource_nilComputedValues(t *testing.T) {
check := func(s *terraform.State) error {
return nil
}
resource.UnitTest(t, resource.TestCase{
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Check: check,
Config: `
variable "index" {
default = "d"
}
locals {
name = {
a = "something"
b = "else"
}
}
data "test_data_source" "x" {
input = "${lookup(local.name, var.index, local.name["a"])}"
}
data "test_data_source" "y" {
input = data.test_data_source.x.nil == "something" ? "something" : "else"
}`,
},
},
})
}