terraform: ResourceState contains type
This commit is contained in:
parent
0d557a605f
commit
a58b2c8675
|
@ -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{}
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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"
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue