Merge pull request #808 from hashicorp/b-weird-getok
helper/schema: don't put things into the state that don't exist or are computed
This commit is contained in:
commit
f8cd9ebbc0
|
@ -84,8 +84,7 @@ func (d *ResourceData) GetChange(key string) (interface{}, interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOk returns the data for the given key and whether or not the key
|
// GetOk returns the data for the given key and whether or not the key
|
||||||
// existed or not in the configuration. The second boolean result will also
|
// has been set.
|
||||||
// be false if a key is given that isn't in the schema at all.
|
|
||||||
//
|
//
|
||||||
// The first result will not necessarilly be nil if the value doesn't exist.
|
// The first result will not necessarilly be nil if the value doesn't exist.
|
||||||
// The second result should be checked to determine this information.
|
// The second result should be checked to determine this information.
|
||||||
|
@ -213,11 +212,13 @@ func (d *ResourceData) State() *terraform.InstanceState {
|
||||||
}
|
}
|
||||||
|
|
||||||
raw := d.get([]string{k}, source)
|
raw := d.get([]string{k}, source)
|
||||||
|
if raw.Exists && !raw.Computed {
|
||||||
rawMap[k] = raw.Value
|
rawMap[k] = raw.Value
|
||||||
if raw.ValueProcessed != nil {
|
if raw.ValueProcessed != nil {
|
||||||
rawMap[k] = raw.ValueProcessed
|
rawMap[k] = raw.ValueProcessed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
mapW := &MapFieldWriter{Schema: d.schema}
|
mapW := &MapFieldWriter{Schema: d.schema}
|
||||||
if err := mapW.WriteField(nil, rawMap); err != nil {
|
if err := mapW.WriteField(nil, rawMap); err != nil {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -1919,9 +1919,7 @@ func TestResourceDataState(t *testing.T) {
|
||||||
Partial: []string{},
|
Partial: []string{},
|
||||||
|
|
||||||
Result: &terraform.InstanceState{
|
Result: &terraform.InstanceState{
|
||||||
Attributes: map[string]string{
|
Attributes: map[string]string{},
|
||||||
"availability_zone": "",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1994,9 +1992,7 @@ func TestResourceDataState(t *testing.T) {
|
||||||
},
|
},
|
||||||
|
|
||||||
Result: &terraform.InstanceState{
|
Result: &terraform.InstanceState{
|
||||||
Attributes: map[string]string{
|
Attributes: map[string]string{},
|
||||||
"ports.#": "0",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -2176,9 +2172,7 @@ func TestResourceDataState(t *testing.T) {
|
||||||
Partial: []string{},
|
Partial: []string{},
|
||||||
|
|
||||||
Result: &terraform.InstanceState{
|
Result: &terraform.InstanceState{
|
||||||
Attributes: map[string]string{
|
Attributes: map[string]string{},
|
||||||
"ports.#": "0",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -2239,6 +2233,62 @@ func TestResourceDataState(t *testing.T) {
|
||||||
Attributes: map[string]string{},
|
Attributes: map[string]string{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// #21
|
||||||
|
{
|
||||||
|
Schema: map[string]*Schema{
|
||||||
|
"foo": &Schema{
|
||||||
|
Type: TypeString,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
State: nil,
|
||||||
|
|
||||||
|
Diff: &terraform.InstanceDiff{
|
||||||
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
||||||
|
"foo": &terraform.ResourceAttrDiff{
|
||||||
|
NewComputed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
Result: &terraform.InstanceState{
|
||||||
|
Attributes: map[string]string{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
// #22
|
||||||
|
{
|
||||||
|
Schema: map[string]*Schema{
|
||||||
|
"foo": &Schema{
|
||||||
|
Type: TypeString,
|
||||||
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
State: nil,
|
||||||
|
|
||||||
|
Diff: &terraform.InstanceDiff{
|
||||||
|
Attributes: map[string]*terraform.ResourceAttrDiff{
|
||||||
|
"foo": &terraform.ResourceAttrDiff{
|
||||||
|
NewComputed: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
Set: map[string]interface{}{
|
||||||
|
"foo": "bar",
|
||||||
|
},
|
||||||
|
|
||||||
|
Result: &terraform.InstanceState{
|
||||||
|
Attributes: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tc := range cases {
|
for i, tc := range cases {
|
||||||
|
|
Loading…
Reference in New Issue