Merge pull request #21068 from hashicorp/jbardin/get-ok-exists

delete unknown values from apply config altogether
This commit is contained in:
James Bardin 2019-04-23 08:58:38 -04:00 committed by GitHub
commit 3d46c04e28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 8 deletions

View File

@ -141,6 +141,13 @@ func testResource() *schema.Resource {
Computed: true,
Description: "copied the required field during apply, and plans computed when changed",
},
// this should return unset from GetOkExists
"get_ok_exists_false": {
Type: schema.TypeBool,
Computed: true,
Optional: true,
Description: "do not set in config",
},
},
}
}
@ -186,6 +193,12 @@ func testResourceRead(d *schema.ResourceData, meta interface{}) error {
d.Set("set", []interface{}{})
}
// This should not show as set unless it's set in the config
_, ok := d.GetOkExists("get_ok_exists_false")
if ok {
return errors.New("get_ok_exists_false should not be set")
}
return nil
}

View File

@ -973,3 +973,22 @@ resource "test_resource" "bar" {
},
})
}
func TestResource_optionalComputedBool(t *testing.T) {
resource.UnitTest(t, resource.TestCase{
Providers: testAccProviders,
CheckDestroy: testAccCheckResourceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: strings.TrimSpace(`
resource "test_resource" "foo" {
required = "yep"
required_map = {
key = "value"
}
}
`),
},
},
})
}

View File

@ -51,7 +51,7 @@ func removeConfigUnknowns(cfg map[string]interface{}) {
switch v := v.(type) {
case string:
if v == config.UnknownVariableValue {
cfg[k] = ""
delete(cfg, k)
}
case []interface{}:
for _, i := range v {

View File

@ -3643,22 +3643,17 @@ func TestRemoveConfigUnknowns(t *testing.T) {
}
expect := map[string]interface{}{
"id": "",
"route_rules": []interface{}{
map[string]interface{}{
"cidr_block": "",
"destination": "0.0.0.0/0",
"destination_type": "CIDR_BLOCK",
"network_entity_id": "1",
},
map[string]interface{}{
"cidr_block": "",
"destination": "0.0.0.0/0",
"destination_type": "CIDR_BLOCK",
"sub_block": []interface{}{
map[string]interface{}{
"computed": "",
},
map[string]interface{}{},
},
},
},