diff --git a/terraform/resource_provider.go b/terraform/resource_provider.go index 613bb749b..d530561d1 100644 --- a/terraform/resource_provider.go +++ b/terraform/resource_provider.go @@ -1,10 +1,5 @@ package terraform -// ComputedPlaceholder is the placeholder value for computed attributes. -// ResourceProviders can compare values to this during a diff to determine -// if it is just a placeholder. -const ComputedPlaceholder = "74D93920-ED26-11E3-AC10-0800200C9A66" - // ResourceProvider is an interface that must be implemented by any // resource provider: the thing that creates and manages the resources in // a Terraform configuration. diff --git a/terraform/state.go b/terraform/state.go index e40e13b05..9ade06428 100644 --- a/terraform/state.go +++ b/terraform/state.go @@ -2,6 +2,8 @@ package terraform import ( "sync" + + "github.com/hashicorp/terraform/config" ) // State keeps track of a snapshot state-of-the-world that Terraform @@ -43,8 +45,7 @@ type ResourceState struct { // won't be available until apply, the value is replaced with the // computeID. func (s *ResourceState) MergeDiff( - d map[string]*ResourceAttrDiff, - computedID string) *ResourceState { + d map[string]*ResourceAttrDiff) *ResourceState { var result ResourceState if s != nil { result = *s @@ -58,7 +59,7 @@ func (s *ResourceState) MergeDiff( } for k, diff := range d { if diff.NewComputed { - result.Attributes[k] = computedID + result.Attributes[k] = config.UnknownVariableValue continue } diff --git a/terraform/state_test.go b/terraform/state_test.go index efb4369ca..44b8d3e4e 100644 --- a/terraform/state_test.go +++ b/terraform/state_test.go @@ -3,6 +3,8 @@ package terraform import ( "reflect" "testing" + + "github.com/hashicorp/terraform/config" ) func TestResourceState_MergeDiff(t *testing.T) { @@ -29,12 +31,12 @@ func TestResourceState_MergeDiff(t *testing.T) { }, } - rs2 := rs.MergeDiff(diff, "what") + rs2 := rs.MergeDiff(diff) expected := map[string]string{ "foo": "baz", "bar": "foo", - "baz": "what", + "baz": config.UnknownVariableValue, } if !reflect.DeepEqual(expected, rs2.Attributes) { @@ -52,7 +54,7 @@ func TestResourceState_MergeDiff_nil(t *testing.T) { }, } - rs2 := rs.MergeDiff(diff, "computed") + rs2 := rs.MergeDiff(diff) expected := map[string]string{ "foo": "baz", diff --git a/terraform/terraform.go b/terraform/terraform.go index c2fc131ed..519c7654a 100644 --- a/terraform/terraform.go +++ b/terraform/terraform.go @@ -144,11 +144,13 @@ func (t *Terraform) diffWalkFn( rs = state.resources[r.Id()] } if len(vars) > 0 { - r = r.ReplaceVariables(vars) + if err := r.RawConfig.Interpolate(vars); err != nil { + panic(fmt.Sprintf("Interpolate error: %s", err)) + } } l.RUnlock() - diff, err := p.Provider.Diff(rs, r.Config) + diff, err := p.Provider.Diff(rs, r.RawConfig.Config()) if err != nil { return err } @@ -166,7 +168,7 @@ func (t *Terraform) diffWalkFn( result.Resources[r.Id()] = diff // Determine the new state and update variables - rs = rs.MergeDiff(diff.Attributes, ComputedPlaceholder) + rs = rs.MergeDiff(diff.Attributes) for ak, av := range rs.Attributes { vars[fmt.Sprintf("%s.%s", r.Id(), ak)] = av } @@ -179,7 +181,11 @@ func (t *terraformProvider) init(vars map[string]string) (err error) { t.Once.Do(func() { var c map[string]interface{} if t.Config != nil { - c = t.Config.ReplaceVariables(vars).Config + if err := t.Config.RawConfig.Interpolate(vars); err != nil { + panic(err) + } + + c = t.Config.RawConfig.Config() } err = t.Provider.Configure(c) diff --git a/terraform/terraform_test.go b/terraform/terraform_test.go index 9422f3f60..f703820fc 100644 --- a/terraform/terraform_test.go +++ b/terraform/terraform_test.go @@ -47,7 +47,7 @@ func TestNew(t *testing.T) { } pc = testProviderConfig(tf, "aws_instance.foo") - if pc.Config["foo"].(string) != "bar" { + if pc.RawConfig.Raw["foo"].(string) != "bar" { t.Fatalf("bad: %#v", pc) } } @@ -114,11 +114,11 @@ func TestNew_providerConfigCache(t *testing.T) { t.Fatalf("bad: %#v", pc) } pc = testProviderConfig(tf, "aws_instance.foo") - if pc.Config["foo"].(string) != "bar" { + if pc.RawConfig.Raw["foo"].(string) != "bar" { t.Fatalf("bad: %#v", pc) } pc = testProviderConfig(tf, "aws_elb.lb") - if pc.Config["foo"].(string) != "baz" { + if pc.RawConfig.Raw["foo"].(string) != "baz" { t.Fatalf("bad: %#v", pc) } @@ -299,7 +299,7 @@ func testProviderFunc(n string, rs []string) ResourceProviderFactory { New: v.(string), } - if strings.Contains(attrDiff.New, ComputedPlaceholder) { + if strings.Contains(attrDiff.New, config.UnknownVariableValue) { attrDiff.NewComputed = true }