terraform: ResourceState contains type

This commit is contained in:
Mitchell Hashimoto 2014-06-18 09:30:59 -07:00
parent 0d557a605f
commit a58b2c8675
3 changed files with 25 additions and 7 deletions

View File

@ -32,6 +32,7 @@ func (s *State) init() {
// for later, but is not exposed in any way to the user.
type ResourceState struct {
ID string
Type string
Attributes map[string]string
Extra map[string]interface{}
}

View File

@ -162,12 +162,20 @@ func (t *Terraform) diffWalkFn(
if state != nil {
rs = state.resources[r.Id()]
}
l.RUnlock()
if len(vars) > 0 {
if err := r.RawConfig.Interpolate(vars); err != nil {
panic(fmt.Sprintf("Interpolate error: %s", err))
}
}
l.RUnlock()
// If we have no state, then create an empty state with the
// type fulfilled at the least.
if rs == nil {
rs = new(ResourceState)
}
rs.Type = r.Type
diff, err := p.Provider.Diff(rs, &ResourceConfig{
ComputedKeys: r.RawConfig.UnknownKeys(),

View File

@ -292,10 +292,15 @@ func testProviderFunc(n string, rs []string) ResourceProviderFactory {
return func() (ResourceProvider, error) {
diffFn := func(
_ *ResourceState,
s *ResourceState,
c *ResourceConfig) (*ResourceDiff, error) {
var diff ResourceDiff
diff.Attributes = make(map[string]*ResourceAttrDiff)
diff.Attributes["type"] = &ResourceAttrDiff{
Old: "",
New: s.Type,
}
for k, v := range c.Raw {
if _, ok := v.(string); !ok {
continue
@ -419,15 +424,19 @@ func testTerraformProvider(tf *Terraform, n string) *terraformProvider {
const testTerraformDiffStr = `
UPDATE: aws_instance.bar
foo: "" => "2"
foo: "" => "2"
type: "" => "aws_instance"
UPDATE: aws_instance.foo
num: "" => "2"
num: "" => "2"
type: "" => "aws_instance"
`
const testTerraformDiffComputedStr = `
UPDATE: aws_instance.bar
foo: "" => "<computed>"
foo: "" => "<computed>"
type: "" => "aws_instance"
UPDATE: aws_instance.foo
id: "" => "<computed>"
num: "" => "2"
id: "" => "<computed>"
num: "" => "2"
type: "" => "aws_instance"
`