Merge pull request #21068 from hashicorp/jbardin/get-ok-exists
delete unknown values from apply config altogether
This commit is contained in:
commit
3d46c04e28
|
@ -141,6 +141,13 @@ func testResource() *schema.Resource {
|
||||||
Computed: true,
|
Computed: true,
|
||||||
Description: "copied the required field during apply, and plans computed when changed",
|
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{}{})
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ func removeConfigUnknowns(cfg map[string]interface{}) {
|
||||||
switch v := v.(type) {
|
switch v := v.(type) {
|
||||||
case string:
|
case string:
|
||||||
if v == config.UnknownVariableValue {
|
if v == config.UnknownVariableValue {
|
||||||
cfg[k] = ""
|
delete(cfg, k)
|
||||||
}
|
}
|
||||||
case []interface{}:
|
case []interface{}:
|
||||||
for _, i := range v {
|
for _, i := range v {
|
||||||
|
|
|
@ -3643,22 +3643,17 @@ func TestRemoveConfigUnknowns(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
expect := map[string]interface{}{
|
expect := map[string]interface{}{
|
||||||
"id": "",
|
|
||||||
"route_rules": []interface{}{
|
"route_rules": []interface{}{
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"cidr_block": "",
|
|
||||||
"destination": "0.0.0.0/0",
|
"destination": "0.0.0.0/0",
|
||||||
"destination_type": "CIDR_BLOCK",
|
"destination_type": "CIDR_BLOCK",
|
||||||
"network_entity_id": "1",
|
"network_entity_id": "1",
|
||||||
},
|
},
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"cidr_block": "",
|
|
||||||
"destination": "0.0.0.0/0",
|
"destination": "0.0.0.0/0",
|
||||||
"destination_type": "CIDR_BLOCK",
|
"destination_type": "CIDR_BLOCK",
|
||||||
"sub_block": []interface{}{
|
"sub_block": []interface{}{
|
||||||
map[string]interface{}{
|
map[string]interface{}{},
|
||||||
"computed": "",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -3667,6 +3662,6 @@ func TestRemoveConfigUnknowns(t *testing.T) {
|
||||||
removeConfigUnknowns(cfg)
|
removeConfigUnknowns(cfg)
|
||||||
|
|
||||||
if !reflect.DeepEqual(cfg, expect) {
|
if !reflect.DeepEqual(cfg, expect) {
|
||||||
t.Fatalf("\nexpected: %#v\ngot: %#v", expect, cfg)
|
t.Fatalf("\nexpected: %#v\ngot: %#v", expect, cfg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue