Merge pull request #21223 from hashicorp/jbardin/unknown-computed
restrict the ComputedKeys usage to containers
This commit is contained in:
commit
02781206ff
|
@ -54,6 +54,11 @@ func testResource() *schema.Resource {
|
||||||
Computed: true,
|
Computed: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
"optional_computed": {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
"computed_read_only": {
|
"computed_read_only": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
|
|
|
@ -992,3 +992,40 @@ resource "test_resource" "foo" {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestResource_replacedOptionalComputed(t *testing.T) {
|
||||||
|
resource.UnitTest(t, resource.TestCase{
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckResourceDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: strings.TrimSpace(`
|
||||||
|
resource "test_resource_nested" "a" {
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "test_resource" "foo" {
|
||||||
|
required = "yep"
|
||||||
|
required_map = {
|
||||||
|
key = "value"
|
||||||
|
}
|
||||||
|
optional_computed = test_resource_nested.a.id
|
||||||
|
}
|
||||||
|
`),
|
||||||
|
},
|
||||||
|
resource.TestStep{
|
||||||
|
Config: strings.TrimSpace(`
|
||||||
|
resource "test_resource_nested" "b" {
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "test_resource" "foo" {
|
||||||
|
required = "yep"
|
||||||
|
required_map = {
|
||||||
|
key = "value"
|
||||||
|
}
|
||||||
|
optional_computed = test_resource_nested.b.id
|
||||||
|
}
|
||||||
|
`),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package schema
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -94,16 +95,20 @@ func (r *ConfigFieldReader) readField(
|
||||||
}
|
}
|
||||||
|
|
||||||
if protoVersion5 {
|
if protoVersion5 {
|
||||||
|
switch schema.Type {
|
||||||
|
case TypeList, TypeSet, TypeMap, typeObject:
|
||||||
// Check if the value itself is unknown.
|
// Check if the value itself is unknown.
|
||||||
// The new protocol shims will add unknown values to this list of
|
// The new protocol shims will add unknown values to this list of
|
||||||
// ComputedKeys. THis is the only way we have to indicate that a
|
// ComputedKeys. This is the only way we have to indicate that a
|
||||||
// collection is unknown in the config
|
// collection is unknown in the config
|
||||||
for _, unknown := range r.Config.ComputedKeys {
|
for _, unknown := range r.Config.ComputedKeys {
|
||||||
if k == unknown {
|
if k == unknown {
|
||||||
|
log.Printf("[DEBUG] setting computed for %q from ComputedKeys", k)
|
||||||
return FieldReadResult{Computed: true, Exists: true}, nil
|
return FieldReadResult{Computed: true, Exists: true}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch schema.Type {
|
switch schema.Type {
|
||||||
case TypeBool, TypeFloat, TypeInt, TypeString:
|
case TypeBool, TypeFloat, TypeInt, TypeString:
|
||||||
|
|
Loading…
Reference in New Issue