helper/schema: conforms to new API, tests pass
This commit is contained in:
parent
0bcbccf046
commit
81d9d70296
|
@ -136,11 +136,12 @@ func (p *Provider) Configure(c *terraform.ResourceConfig) error {
|
|||
|
||||
// Apply implementation of terraform.ResourceProvider interface.
|
||||
func (p *Provider) Apply(
|
||||
s *terraform.ResourceState,
|
||||
d *terraform.ResourceDiff) (*terraform.ResourceState, error) {
|
||||
r, ok := p.ResourcesMap[s.Type]
|
||||
info *terraform.InstanceInfo,
|
||||
s *terraform.InstanceState,
|
||||
d *terraform.ResourceDiff) (*terraform.InstanceState, error) {
|
||||
r, ok := p.ResourcesMap[info.Type]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unknown resource type: %s", s.Type)
|
||||
return nil, fmt.Errorf("unknown resource type: %s", info.Type)
|
||||
}
|
||||
|
||||
return r.Apply(s, d, p.meta)
|
||||
|
@ -148,11 +149,12 @@ func (p *Provider) Apply(
|
|||
|
||||
// Diff implementation of terraform.ResourceProvider interface.
|
||||
func (p *Provider) Diff(
|
||||
s *terraform.ResourceState,
|
||||
info *terraform.InstanceInfo,
|
||||
s *terraform.InstanceState,
|
||||
c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
|
||||
r, ok := p.ResourcesMap[s.Type]
|
||||
r, ok := p.ResourcesMap[info.Type]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unknown resource type: %s", s.Type)
|
||||
return nil, fmt.Errorf("unknown resource type: %s", info.Type)
|
||||
}
|
||||
|
||||
return r.Diff(s, c)
|
||||
|
@ -160,10 +162,11 @@ func (p *Provider) Diff(
|
|||
|
||||
// Refresh implementation of terraform.ResourceProvider interface.
|
||||
func (p *Provider) Refresh(
|
||||
s *terraform.ResourceState) (*terraform.ResourceState, error) {
|
||||
r, ok := p.ResourcesMap[s.Type]
|
||||
info *terraform.InstanceInfo,
|
||||
s *terraform.InstanceState) (*terraform.InstanceState, error) {
|
||||
r, ok := p.ResourcesMap[info.Type]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unknown resource type: %s", s.Type)
|
||||
return nil, fmt.Errorf("unknown resource type: %s", info.Type)
|
||||
}
|
||||
|
||||
return r.Refresh(s, p.meta)
|
||||
|
|
|
@ -61,9 +61,9 @@ type DeleteFunc func(*ResourceData, interface{}) error
|
|||
|
||||
// Apply creates, updates, and/or deletes a resource.
|
||||
func (r *Resource) Apply(
|
||||
s *terraform.ResourceState,
|
||||
s *terraform.InstanceState,
|
||||
d *terraform.ResourceDiff,
|
||||
meta interface{}) (*terraform.ResourceState, error) {
|
||||
meta interface{}) (*terraform.InstanceState, error) {
|
||||
data, err := schemaMap(r.Schema).Data(s, d)
|
||||
if err != nil {
|
||||
return s, err
|
||||
|
@ -72,7 +72,7 @@ func (r *Resource) Apply(
|
|||
if s == nil {
|
||||
// The Terraform API dictates that this should never happen, but
|
||||
// it doesn't hurt to be safe in this case.
|
||||
s = new(terraform.ResourceState)
|
||||
s = new(terraform.InstanceState)
|
||||
}
|
||||
|
||||
if d.Destroy || d.RequiresNew() {
|
||||
|
@ -99,7 +99,7 @@ func (r *Resource) Apply(
|
|||
err = r.Create(data, meta)
|
||||
} else {
|
||||
if r.Update == nil {
|
||||
return s, fmt.Errorf("%s doesn't support update", s.Type)
|
||||
return s, fmt.Errorf("doesn't support update")
|
||||
}
|
||||
|
||||
err = r.Update(data, meta)
|
||||
|
@ -111,7 +111,7 @@ func (r *Resource) Apply(
|
|||
// Diff returns a diff of this resource and is API compatible with the
|
||||
// ResourceProvider interface.
|
||||
func (r *Resource) Diff(
|
||||
s *terraform.ResourceState,
|
||||
s *terraform.InstanceState,
|
||||
c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
|
||||
return schemaMap(r.Schema).Diff(s, c)
|
||||
}
|
||||
|
@ -123,8 +123,8 @@ func (r *Resource) Validate(c *terraform.ResourceConfig) ([]string, []error) {
|
|||
|
||||
// Refresh refreshes the state of the resource.
|
||||
func (r *Resource) Refresh(
|
||||
s *terraform.ResourceState,
|
||||
meta interface{}) (*terraform.ResourceState, error) {
|
||||
s *terraform.InstanceState,
|
||||
meta interface{}) (*terraform.InstanceState, error) {
|
||||
data, err := schemaMap(r.Schema).Data(s, nil)
|
||||
if err != nil {
|
||||
return s, err
|
||||
|
|
|
@ -23,13 +23,13 @@ type ResourceData struct {
|
|||
// Settable (internally)
|
||||
schema map[string]*Schema
|
||||
config *terraform.ResourceConfig
|
||||
state *terraform.ResourceState
|
||||
state *terraform.InstanceState
|
||||
diff *terraform.ResourceDiff
|
||||
diffing bool
|
||||
|
||||
// Don't set
|
||||
setMap map[string]string
|
||||
newState *terraform.ResourceState
|
||||
newState *terraform.InstanceState
|
||||
partial bool
|
||||
partialMap map[string]struct{}
|
||||
once sync.Once
|
||||
|
@ -168,24 +168,11 @@ func (d *ResourceData) Id() string {
|
|||
// ConnInfo returns the connection info for this resource.
|
||||
func (d *ResourceData) ConnInfo() map[string]string {
|
||||
if d.newState != nil {
|
||||
return d.newState.ConnInfo
|
||||
return d.newState.Ephemeral.ConnInfo
|
||||
}
|
||||
|
||||
if d.state != nil {
|
||||
return d.state.ConnInfo
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Dependencies returns the dependencies in this state.
|
||||
func (d *ResourceData) Dependencies() []terraform.ResourceDependency {
|
||||
if d.newState != nil {
|
||||
return d.newState.Dependencies
|
||||
}
|
||||
|
||||
if d.state != nil {
|
||||
return d.state.Dependencies
|
||||
return d.state.Ephemeral.ConnInfo
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -201,19 +188,13 @@ func (d *ResourceData) SetId(v string) {
|
|||
// SetConnInfo sets the connection info for a resource.
|
||||
func (d *ResourceData) SetConnInfo(v map[string]string) {
|
||||
d.once.Do(d.init)
|
||||
d.newState.ConnInfo = v
|
||||
d.newState.Ephemeral.ConnInfo = v
|
||||
}
|
||||
|
||||
// SetDependencies sets the dependencies of a resource.
|
||||
func (d *ResourceData) SetDependencies(ds []terraform.ResourceDependency) {
|
||||
d.once.Do(d.init)
|
||||
d.newState.Dependencies = ds
|
||||
}
|
||||
|
||||
// State returns the new ResourceState after the diff and any Set
|
||||
// State returns the new InstanceState after the diff and any Set
|
||||
// calls.
|
||||
func (d *ResourceData) State() *terraform.ResourceState {
|
||||
var result terraform.ResourceState
|
||||
func (d *ResourceData) State() *terraform.InstanceState {
|
||||
var result terraform.InstanceState
|
||||
result.ID = d.Id()
|
||||
|
||||
// If we have no ID, then this resource doesn't exist and we just
|
||||
|
@ -223,8 +204,7 @@ func (d *ResourceData) State() *terraform.ResourceState {
|
|||
}
|
||||
|
||||
result.Attributes = d.stateObject("", d.schema)
|
||||
result.ConnInfo = d.ConnInfo()
|
||||
result.Dependencies = d.Dependencies()
|
||||
result.Ephemeral.ConnInfo = d.ConnInfo()
|
||||
|
||||
if v := d.Id(); v != "" {
|
||||
result.Attributes["id"] = d.Id()
|
||||
|
@ -234,7 +214,7 @@ func (d *ResourceData) State() *terraform.ResourceState {
|
|||
}
|
||||
|
||||
func (d *ResourceData) init() {
|
||||
var copyState terraform.ResourceState
|
||||
var copyState terraform.InstanceState
|
||||
if d.state != nil {
|
||||
copyState = *d.state
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
func TestResourceDataGet(t *testing.T) {
|
||||
cases := []struct {
|
||||
Schema map[string]*Schema
|
||||
State *terraform.ResourceState
|
||||
State *terraform.InstanceState
|
||||
Diff *terraform.ResourceDiff
|
||||
Key string
|
||||
Value interface{}
|
||||
|
@ -104,7 +104,7 @@ func TestResourceDataGet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"availability_zone": "bar",
|
||||
},
|
||||
|
@ -127,7 +127,7 @@ func TestResourceDataGet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"availability_zone": "foo",
|
||||
},
|
||||
|
@ -157,7 +157,7 @@ func TestResourceDataGet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"port": "80",
|
||||
},
|
||||
|
@ -179,7 +179,7 @@ func TestResourceDataGet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ports.#": "3",
|
||||
"ports.0": "1",
|
||||
|
@ -202,7 +202,7 @@ func TestResourceDataGet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ports.#": "3",
|
||||
"ports.0": "1",
|
||||
|
@ -241,7 +241,7 @@ func TestResourceDataGet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ports.#": "3",
|
||||
"ports.0": "1",
|
||||
|
@ -342,7 +342,7 @@ func TestResourceDataGet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"availability_zone": "foo",
|
||||
},
|
||||
|
@ -440,7 +440,7 @@ func TestResourceDataGet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"config_vars.#": "2",
|
||||
"config_vars.0.foo": "baz",
|
||||
|
@ -475,7 +475,7 @@ func TestResourceDataGet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"config_vars.#": "1",
|
||||
"config_vars.0.FOO": "bar",
|
||||
|
@ -514,7 +514,7 @@ func TestResourceDataGet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ports.#": "1",
|
||||
"ports.0": "80",
|
||||
|
@ -549,7 +549,7 @@ func TestResourceDataGet(t *testing.T) {
|
|||
func TestResourceDataGetChange(t *testing.T) {
|
||||
cases := []struct {
|
||||
Schema map[string]*Schema
|
||||
State *terraform.ResourceState
|
||||
State *terraform.InstanceState
|
||||
Diff *terraform.ResourceDiff
|
||||
Key string
|
||||
OldValue interface{}
|
||||
|
@ -593,7 +593,7 @@ func TestResourceDataGetChange(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"availability_zone": "foo",
|
||||
},
|
||||
|
@ -635,7 +635,7 @@ func TestResourceDataGetChange(t *testing.T) {
|
|||
func TestResourceDataGetOk(t *testing.T) {
|
||||
cases := []struct {
|
||||
Schema map[string]*Schema
|
||||
State *terraform.ResourceState
|
||||
State *terraform.InstanceState
|
||||
Diff *terraform.ResourceDiff
|
||||
Key string
|
||||
Value interface{}
|
||||
|
@ -798,7 +798,7 @@ func TestResourceDataGetOk(t *testing.T) {
|
|||
func TestResourceDataHasChange(t *testing.T) {
|
||||
cases := []struct {
|
||||
Schema map[string]*Schema
|
||||
State *terraform.ResourceState
|
||||
State *terraform.InstanceState
|
||||
Diff *terraform.ResourceDiff
|
||||
Key string
|
||||
Change bool
|
||||
|
@ -840,7 +840,7 @@ func TestResourceDataHasChange(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"availability_zone": "foo",
|
||||
},
|
||||
|
@ -878,7 +878,7 @@ func TestResourceDataHasChange(t *testing.T) {
|
|||
func TestResourceDataSet(t *testing.T) {
|
||||
cases := []struct {
|
||||
Schema map[string]*Schema
|
||||
State *terraform.ResourceState
|
||||
State *terraform.InstanceState
|
||||
Diff *terraform.ResourceDiff
|
||||
Key string
|
||||
Value interface{}
|
||||
|
@ -1002,7 +1002,7 @@ func TestResourceDataSet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ports.#": "3",
|
||||
"ports.0": "1",
|
||||
|
@ -1079,7 +1079,7 @@ func TestResourceDataSet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ingress.#": "2",
|
||||
"ingress.0.from": "80",
|
||||
|
@ -1119,7 +1119,7 @@ func TestResourceDataSet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ingress.#": "2",
|
||||
"ingress.0.from": "80",
|
||||
|
@ -1164,7 +1164,7 @@ func TestResourceDataSet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ingress.#": "2",
|
||||
"ingress.0.from": "80",
|
||||
|
@ -1288,7 +1288,7 @@ func TestResourceDataSet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ports.#": "3",
|
||||
"ports.0": "100",
|
||||
|
@ -1318,7 +1318,7 @@ func TestResourceDataSet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ports.#": "3",
|
||||
"ports.0": "100",
|
||||
|
@ -1353,7 +1353,7 @@ func TestResourceDataSet(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ports.#": "2",
|
||||
"ports.0": "100",
|
||||
|
@ -1394,10 +1394,10 @@ func TestResourceDataSet(t *testing.T) {
|
|||
func TestResourceDataState(t *testing.T) {
|
||||
cases := []struct {
|
||||
Schema map[string]*Schema
|
||||
State *terraform.ResourceState
|
||||
State *terraform.InstanceState
|
||||
Diff *terraform.ResourceDiff
|
||||
Set map[string]interface{}
|
||||
Result *terraform.ResourceState
|
||||
Result *terraform.InstanceState
|
||||
Partial []string
|
||||
}{
|
||||
// Basic primitive in diff
|
||||
|
@ -1423,7 +1423,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
Result: &terraform.ResourceState{
|
||||
Result: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"availability_zone": "foo",
|
||||
},
|
||||
|
@ -1457,7 +1457,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
"availability_zone": "bar",
|
||||
},
|
||||
|
||||
Result: &terraform.ResourceState{
|
||||
Result: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"availability_zone": "bar",
|
||||
},
|
||||
|
@ -1480,7 +1480,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
"vpc": true,
|
||||
},
|
||||
|
||||
Result: &terraform.ResourceState{
|
||||
Result: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"vpc": "true",
|
||||
},
|
||||
|
@ -1510,7 +1510,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
Result: &terraform.ResourceState{
|
||||
Result: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"availability_zone": "foo",
|
||||
},
|
||||
|
@ -1527,7 +1527,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ports.#": "1",
|
||||
"ports.0": "80",
|
||||
|
@ -1547,7 +1547,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
Result: &terraform.ResourceState{
|
||||
Result: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ports.#": "2",
|
||||
"ports.0": "80",
|
||||
|
@ -1573,7 +1573,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ingress.#": "1",
|
||||
"ingress.0.from": "80",
|
||||
|
@ -1597,7 +1597,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
Result: &terraform.ResourceState{
|
||||
Result: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ingress.#": "2",
|
||||
"ingress.0.from": "150",
|
||||
|
@ -1619,7 +1619,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"config_vars.#": "2",
|
||||
"config_vars.0.foo": "bar",
|
||||
|
@ -1642,7 +1642,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
Result: &terraform.ResourceState{
|
||||
Result: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"config_vars.#": "2",
|
||||
"config_vars.0.foo": "bar",
|
||||
|
@ -1664,7 +1664,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"config_vars.#": "1",
|
||||
"config_vars.0.FOO": "bar",
|
||||
|
@ -1684,7 +1684,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
Result: &terraform.ResourceState{
|
||||
Result: &terraform.InstanceState{
|
||||
Attributes: map[string]string{},
|
||||
},
|
||||
},
|
||||
|
@ -1700,7 +1700,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
ID: "bar",
|
||||
Attributes: map[string]string{
|
||||
"id": "bar",
|
||||
|
@ -1717,7 +1717,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
Result: &terraform.ResourceState{
|
||||
Result: &terraform.InstanceState{
|
||||
ID: "bar",
|
||||
Attributes: map[string]string{
|
||||
"id": "bar",
|
||||
|
@ -1740,7 +1740,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ports.#": "3",
|
||||
"ports.0": "100",
|
||||
|
@ -1751,7 +1751,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
|
||||
Diff: nil,
|
||||
|
||||
Result: &terraform.ResourceState{
|
||||
Result: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ports.#": "2",
|
||||
"ports.0": "80",
|
||||
|
@ -1789,7 +1789,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
|
||||
Partial: []string{},
|
||||
|
||||
Result: &terraform.ResourceState{
|
||||
Result: &terraform.InstanceState{
|
||||
Attributes: map[string]string{},
|
||||
},
|
||||
},
|
||||
|
@ -1804,7 +1804,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ports.#": "1",
|
||||
"ports.0": "80",
|
||||
|
@ -1826,7 +1826,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
|
||||
Partial: []string{},
|
||||
|
||||
Result: &terraform.ResourceState{
|
||||
Result: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ports.#": "1",
|
||||
"ports.0": "80",
|
||||
|
@ -1851,7 +1851,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ingress.#": "1",
|
||||
"ingress.0.from": "80",
|
||||
|
@ -1877,7 +1877,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
|
||||
Partial: []string{},
|
||||
|
||||
Result: &terraform.ResourceState{
|
||||
Result: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ingress.#": "1",
|
||||
"ingress.0.from": "80",
|
||||
|
@ -1898,7 +1898,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"config_vars.#": "2",
|
||||
"config_vars.0.foo": "bar",
|
||||
|
@ -1923,7 +1923,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
|
||||
Partial: []string{},
|
||||
|
||||
Result: &terraform.ResourceState{
|
||||
Result: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"config_vars.#": "2",
|
||||
"config_vars.0.foo": "bar",
|
||||
|
@ -1947,7 +1947,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ports.#": "3",
|
||||
"ports.0": "100",
|
||||
|
@ -1966,7 +1966,7 @@ func TestResourceDataState(t *testing.T) {
|
|||
|
||||
Partial: []string{},
|
||||
|
||||
Result: &terraform.ResourceState{
|
||||
Result: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ports.#": "2",
|
||||
"ports.0": "80",
|
||||
|
@ -2029,24 +2029,7 @@ func TestResourceDataSetConnInfo(t *testing.T) {
|
|||
}
|
||||
|
||||
actual := d.State()
|
||||
if !reflect.DeepEqual(actual.ConnInfo, expected) {
|
||||
t.Fatalf("bad: %#v", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceDataSetDependencies(t *testing.T) {
|
||||
d := &ResourceData{}
|
||||
d.SetId("foo")
|
||||
d.SetDependencies([]terraform.ResourceDependency{
|
||||
terraform.ResourceDependency{ID: "foo"},
|
||||
})
|
||||
|
||||
expected := []terraform.ResourceDependency{
|
||||
terraform.ResourceDependency{ID: "foo"},
|
||||
}
|
||||
|
||||
actual := d.State()
|
||||
if !reflect.DeepEqual(actual.Dependencies, expected) {
|
||||
if !reflect.DeepEqual(actual.Ephemeral.ConnInfo, expected) {
|
||||
t.Fatalf("bad: %#v", actual)
|
||||
}
|
||||
}
|
||||
|
@ -2063,7 +2046,7 @@ func TestResourceDataSetId(t *testing.T) {
|
|||
|
||||
func TestResourceDataSetId_clear(t *testing.T) {
|
||||
d := &ResourceData{
|
||||
state: &terraform.ResourceState{ID: "bar"},
|
||||
state: &terraform.InstanceState{ID: "bar"},
|
||||
}
|
||||
d.SetId("")
|
||||
|
||||
|
@ -2075,7 +2058,7 @@ func TestResourceDataSetId_clear(t *testing.T) {
|
|||
|
||||
func TestResourceDataSetId_override(t *testing.T) {
|
||||
d := &ResourceData{
|
||||
state: &terraform.ResourceState{ID: "bar"},
|
||||
state: &terraform.InstanceState{ID: "bar"},
|
||||
}
|
||||
d.SetId("foo")
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ func TestResourceApply_create(t *testing.T) {
|
|||
return nil
|
||||
}
|
||||
|
||||
var s *terraform.ResourceState = nil
|
||||
var s *terraform.InstanceState = nil
|
||||
|
||||
d := &terraform.ResourceDiff{
|
||||
Attributes: map[string]*terraform.ResourceAttrDiff{
|
||||
|
@ -44,7 +44,7 @@ func TestResourceApply_create(t *testing.T) {
|
|||
t.Fatal("not called")
|
||||
}
|
||||
|
||||
expected := &terraform.ResourceState{
|
||||
expected := &terraform.InstanceState{
|
||||
ID: "foo",
|
||||
Attributes: map[string]string{
|
||||
"id": "foo",
|
||||
|
@ -73,7 +73,7 @@ func TestResourceApply_destroy(t *testing.T) {
|
|||
return nil
|
||||
}
|
||||
|
||||
s := &terraform.ResourceState{
|
||||
s := &terraform.InstanceState{
|
||||
ID: "bar",
|
||||
}
|
||||
|
||||
|
@ -110,7 +110,7 @@ func TestResourceApply_destroyPartial(t *testing.T) {
|
|||
return fmt.Errorf("some error")
|
||||
}
|
||||
|
||||
s := &terraform.ResourceState{
|
||||
s := &terraform.InstanceState{
|
||||
ID: "bar",
|
||||
Attributes: map[string]string{
|
||||
"foo": "12",
|
||||
|
@ -126,7 +126,7 @@ func TestResourceApply_destroyPartial(t *testing.T) {
|
|||
t.Fatal("should error")
|
||||
}
|
||||
|
||||
expected := &terraform.ResourceState{
|
||||
expected := &terraform.InstanceState{
|
||||
ID: "bar",
|
||||
Attributes: map[string]string{
|
||||
"id": "bar",
|
||||
|
@ -154,7 +154,7 @@ func TestResourceApply_update(t *testing.T) {
|
|||
return nil
|
||||
}
|
||||
|
||||
s := &terraform.ResourceState{
|
||||
s := &terraform.InstanceState{
|
||||
ID: "foo",
|
||||
Attributes: map[string]string{
|
||||
"foo": "12",
|
||||
|
@ -174,7 +174,7 @@ func TestResourceApply_update(t *testing.T) {
|
|||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
expected := &terraform.ResourceState{
|
||||
expected := &terraform.InstanceState{
|
||||
ID: "foo",
|
||||
Attributes: map[string]string{
|
||||
"id": "foo",
|
||||
|
@ -199,7 +199,7 @@ func TestResourceApply_updateNoCallback(t *testing.T) {
|
|||
|
||||
r.Update = nil
|
||||
|
||||
s := &terraform.ResourceState{
|
||||
s := &terraform.InstanceState{
|
||||
ID: "foo",
|
||||
Attributes: map[string]string{
|
||||
"foo": "12",
|
||||
|
@ -219,7 +219,7 @@ func TestResourceApply_updateNoCallback(t *testing.T) {
|
|||
t.Fatal("should error")
|
||||
}
|
||||
|
||||
expected := &terraform.ResourceState{
|
||||
expected := &terraform.InstanceState{
|
||||
ID: "foo",
|
||||
Attributes: map[string]string{
|
||||
"foo": "12",
|
||||
|
@ -282,14 +282,14 @@ func TestResourceRefresh(t *testing.T) {
|
|||
return d.Set("foo", d.Get("foo").(int)+1)
|
||||
}
|
||||
|
||||
s := &terraform.ResourceState{
|
||||
s := &terraform.InstanceState{
|
||||
ID: "bar",
|
||||
Attributes: map[string]string{
|
||||
"foo": "12",
|
||||
},
|
||||
}
|
||||
|
||||
expected := &terraform.ResourceState{
|
||||
expected := &terraform.InstanceState{
|
||||
ID: "bar",
|
||||
Attributes: map[string]string{
|
||||
"id": "bar",
|
||||
|
@ -322,7 +322,7 @@ func TestResourceRefresh_delete(t *testing.T) {
|
|||
return nil
|
||||
}
|
||||
|
||||
s := &terraform.ResourceState{
|
||||
s := &terraform.InstanceState{
|
||||
ID: "bar",
|
||||
Attributes: map[string]string{
|
||||
"foo": "12",
|
||||
|
|
|
@ -162,7 +162,7 @@ type schemaMap map[string]*Schema
|
|||
//
|
||||
// The diff is optional.
|
||||
func (m schemaMap) Data(
|
||||
s *terraform.ResourceState,
|
||||
s *terraform.InstanceState,
|
||||
d *terraform.ResourceDiff) (*ResourceData, error) {
|
||||
return &ResourceData{
|
||||
schema: m,
|
||||
|
@ -174,7 +174,7 @@ func (m schemaMap) Data(
|
|||
// Diff returns the diff for a resource given the schema map,
|
||||
// state, and configuration.
|
||||
func (m schemaMap) Diff(
|
||||
s *terraform.ResourceState,
|
||||
s *terraform.InstanceState,
|
||||
c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
|
||||
result := new(terraform.ResourceDiff)
|
||||
result.Attributes = make(map[string]*terraform.ResourceAttrDiff)
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
func TestSchemaMap_Diff(t *testing.T) {
|
||||
cases := []struct {
|
||||
Schema map[string]*Schema
|
||||
State *terraform.ResourceState
|
||||
State *terraform.InstanceState
|
||||
Config map[string]interface{}
|
||||
ConfigVariables map[string]string
|
||||
Diff *terraform.ResourceDiff
|
||||
|
@ -87,7 +87,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
ID: "foo",
|
||||
},
|
||||
|
||||
|
@ -394,7 +394,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ports.#": "3",
|
||||
"ports.0": "1",
|
||||
|
@ -421,7 +421,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ports.#": "2",
|
||||
"ports.0": "1",
|
||||
|
@ -577,7 +577,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ports.#": "2",
|
||||
"ports.0": "2",
|
||||
|
@ -617,7 +617,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"ports.#": "2",
|
||||
"ports.0": "2",
|
||||
|
@ -658,7 +658,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"availability_zone": "bar",
|
||||
"ports.#": "1",
|
||||
|
@ -737,7 +737,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"availability_zone": "foo",
|
||||
"port": "80",
|
||||
|
@ -767,7 +767,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"port": "80",
|
||||
},
|
||||
|
@ -803,7 +803,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"availability_zone": "foo",
|
||||
"port": "80",
|
||||
|
@ -843,7 +843,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"config_vars.#": "1",
|
||||
"config_vars.0.foo": "bar",
|
||||
|
@ -882,7 +882,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"config_vars.#": "1",
|
||||
"config_vars.0.foo": "bar",
|
||||
|
@ -931,7 +931,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"availability_zone": "bar",
|
||||
"address": "foo",
|
||||
|
@ -979,7 +979,7 @@ func TestSchemaMap_Diff(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
State: &terraform.ResourceState{
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"availability_zone": "bar",
|
||||
"ports.#": "1",
|
||||
|
|
Loading…
Reference in New Issue