diff: show properly fufilled variables if possible

This commit is contained in:
Mitchell Hashimoto 2014-06-20 12:12:24 -07:00
parent 2fd129ddc4
commit 9e42654145
2 changed files with 67 additions and 0 deletions

View File

@ -30,6 +30,9 @@ func (b *ResourceBuilder) Diff(
// Go through the configuration and find the changed attributes
for k, v := range c.Raw {
newV := v.(string)
if cleanV, ok := c.Config[k]; ok {
newV = cleanV.(string)
}
var oldV string
var ok bool

View File

@ -3,6 +3,7 @@ package diff
import (
"testing"
"github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/terraform"
)
@ -90,6 +91,59 @@ func TestResourceBuilder_same(t *testing.T) {
}
}
func TestResourceBuilder_unknown(t *testing.T) {
rb := &ResourceBuilder{}
state := &terraform.ResourceState{}
c := testConfig(t, map[string]interface{}{
"foo": "${var.unknown}",
}, map[string]string{
"var.foo": "bar",
"var.unknown": config.UnknownVariableValue,
})
diff, err := rb.Diff(state, c)
if err != nil {
t.Fatalf("err: %s", err)
}
if diff == nil {
t.Fatal("should not be nil")
}
actual := testResourceDiffStr(diff)
expected := testRBUnknownDiff
if actual != expected {
t.Fatalf("bad: %s", actual)
}
}
func TestResourceBuilder_vars(t *testing.T) {
rb := &ResourceBuilder{}
state := &terraform.ResourceState{}
c := testConfig(t, map[string]interface{}{
"foo": "${var.foo}",
}, map[string]string{
"var.foo": "bar",
})
diff, err := rb.Diff(state, c)
if err != nil {
t.Fatalf("err: %s", err)
}
if diff == nil {
t.Fatal("should not be nil")
}
actual := testResourceDiffStr(diff)
expected := testRBVarsDiff
if actual != expected {
t.Fatalf("bad: %s", actual)
}
}
const testRBNewDiff = `CREATE
foo: "" => "bar"
id: "" => "<computed>" (forces new resource)
@ -101,3 +155,13 @@ const testRBRequiresNewDiff = `CREATE
id: "1" => "<computed>" (forces new resource)
private_ip: "127.0.0.1" => "<computed>"
`
const testRBUnknownDiff = `CREATE
foo: "" => "${var.unknown}"
id: "" => "<computed>" (forces new resource)
`
const testRBVarsDiff = `CREATE
foo: "" => "bar"
id: "" => "<computed>" (forces new resource)
`