Skip to content

Commit

Permalink
helper/schema: Get on computed diff should be empty
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Aug 27, 2014
1 parent c9a541d commit faa4e75
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 14 deletions.
29 changes: 17 additions & 12 deletions helper/schema/resource_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,20 +558,25 @@ func (d *ResourceData) getPrimitive(

if d.diff != nil && source >= getSourceDiff {
attrD, ok := d.diff.Attributes[k]
if ok && !attrD.NewComputed {
result = attrD.New
if attrD.NewExtra != nil {
// If NewExtra != nil, then we have processed data as the New,
// so we store that but decode the unprocessed data into result
resultProcessed = result

err := mapstructure.WeakDecode(attrD.NewExtra, &result)
if err != nil {
panic(err)
if ok {
if !attrD.NewComputed {
result = attrD.New
if attrD.NewExtra != nil {
// If NewExtra != nil, then we have processed data as the New,
// so we store that but decode the unprocessed data into result
resultProcessed = result

err := mapstructure.WeakDecode(attrD.NewExtra, &result)
if err != nil {
panic(err)
}
}
}

resultSet = true
resultSet = true
} else {
result = ""
resultSet = false
}
}
}

Expand Down
34 changes: 32 additions & 2 deletions helper/schema/resource_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ func TestResourceDataGet(t *testing.T) {
Diff: &terraform.ResourceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "",
New: "",
Old: "foo",
New: "bar",
NewComputed: true,
},
},
Expand Down Expand Up @@ -117,6 +117,36 @@ func TestResourceDataGet(t *testing.T) {
Value: "bar",
},

{
Schema: map[string]*Schema{
"availability_zone": &Schema{
Type: TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
},

State: &terraform.ResourceState{
Attributes: map[string]string{
"availability_zone": "foo",
},
},

Diff: &terraform.ResourceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "foo",
New: "bar",
NewComputed: true,
},
},
},

Key: "availability_zone",
Value: "",
},

{
Schema: map[string]*Schema{
"port": &Schema{
Expand Down

0 comments on commit faa4e75

Please sign in to comment.