helper/resource: compiles, fails because Context doesn't work, probably
This commit is contained in:
parent
90dd00ee3c
commit
0bcbccf046
|
@ -31,12 +31,13 @@ func (m *Map) Validate(
|
|||
// Apply performs a create or update depending on the diff, and calls
|
||||
// the proper function on the matching Resource.
|
||||
func (m *Map) Apply(
|
||||
s *terraform.ResourceState,
|
||||
info *terraform.InstanceInfo,
|
||||
s *terraform.InstanceState,
|
||||
d *terraform.ResourceDiff,
|
||||
meta interface{}) (*terraform.ResourceState, error) {
|
||||
r, ok := m.Mapping[s.Type]
|
||||
meta interface{}) (*terraform.InstanceState, error) {
|
||||
r, ok := m.Mapping[info.Type]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("Unknown resource type: %s", s.Type)
|
||||
return nil, fmt.Errorf("Unknown resource type: %s", info.Type)
|
||||
}
|
||||
|
||||
if d.Destroy || d.RequiresNew() {
|
||||
|
@ -57,7 +58,7 @@ func (m *Map) Apply(
|
|||
}
|
||||
}
|
||||
|
||||
var result *terraform.ResourceState
|
||||
var result *terraform.InstanceState
|
||||
var err error
|
||||
if s.ID == "" {
|
||||
result, err = r.Create(s, d, meta)
|
||||
|
@ -65,7 +66,7 @@ func (m *Map) Apply(
|
|||
if r.Update == nil {
|
||||
return s, fmt.Errorf(
|
||||
"Resource type '%s' doesn't support update",
|
||||
s.Type)
|
||||
info.Type)
|
||||
}
|
||||
|
||||
result, err = r.Update(s, d, meta)
|
||||
|
@ -83,12 +84,13 @@ func (m *Map) Apply(
|
|||
|
||||
// Diff performs a diff on the proper resource type.
|
||||
func (m *Map) Diff(
|
||||
s *terraform.ResourceState,
|
||||
info *terraform.InstanceInfo,
|
||||
s *terraform.InstanceState,
|
||||
c *terraform.ResourceConfig,
|
||||
meta interface{}) (*terraform.ResourceDiff, error) {
|
||||
r, ok := m.Mapping[s.Type]
|
||||
r, ok := m.Mapping[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, meta)
|
||||
|
@ -101,16 +103,17 @@ func (m *Map) Diff(
|
|||
//
|
||||
// An error is returned if the resource isn't registered.
|
||||
func (m *Map) Refresh(
|
||||
s *terraform.ResourceState,
|
||||
meta interface{}) (*terraform.ResourceState, error) {
|
||||
info *terraform.InstanceInfo,
|
||||
s *terraform.InstanceState,
|
||||
meta interface{}) (*terraform.InstanceState, error) {
|
||||
// If the resource isn't created, don't refresh.
|
||||
if s.ID == "" {
|
||||
return s, nil
|
||||
}
|
||||
|
||||
r, ok := m.Mapping[s.Type]
|
||||
r, ok := m.Mapping[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, meta)
|
||||
|
|
|
@ -17,33 +17,33 @@ type Resource struct {
|
|||
// CreateFunc is a function that creates a resource that didn't previously
|
||||
// exist.
|
||||
type CreateFunc func(
|
||||
*terraform.ResourceState,
|
||||
*terraform.InstanceState,
|
||||
*terraform.ResourceDiff,
|
||||
interface{}) (*terraform.ResourceState, error)
|
||||
interface{}) (*terraform.InstanceState, error)
|
||||
|
||||
// DestroyFunc is a function that destroys a resource that previously
|
||||
// exists using the state.
|
||||
type DestroyFunc func(
|
||||
*terraform.ResourceState,
|
||||
*terraform.InstanceState,
|
||||
interface{}) error
|
||||
|
||||
// DiffFunc is a function that performs a diff of a resource.
|
||||
type DiffFunc func(
|
||||
*terraform.ResourceState,
|
||||
*terraform.InstanceState,
|
||||
*terraform.ResourceConfig,
|
||||
interface{}) (*terraform.ResourceDiff, error)
|
||||
|
||||
// RefreshFunc is a function that performs a refresh of a specific type
|
||||
// of resource.
|
||||
type RefreshFunc func(
|
||||
*terraform.ResourceState,
|
||||
interface{}) (*terraform.ResourceState, error)
|
||||
*terraform.InstanceState,
|
||||
interface{}) (*terraform.InstanceState, error)
|
||||
|
||||
// UpdateFunc is a function that is called to update a resource that
|
||||
// previously existed. The difference between this and CreateFunc is that
|
||||
// the diff is guaranteed to only contain attributes that don't require
|
||||
// a new resource.
|
||||
type UpdateFunc func(
|
||||
*terraform.ResourceState,
|
||||
*terraform.InstanceState,
|
||||
*terraform.ResourceDiff,
|
||||
interface{}) (*terraform.ResourceState, error)
|
||||
interface{}) (*terraform.InstanceState, error)
|
||||
|
|
|
@ -244,18 +244,24 @@ func ComposeTestCheckFunc(fs ...TestCheckFunc) TestCheckFunc {
|
|||
|
||||
func TestCheckResourceAttr(name, key, value string) TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
rs, ok := s.Resources[name]
|
||||
ms := s.RootModule()
|
||||
rs, ok := ms.Resources[name]
|
||||
if !ok {
|
||||
return fmt.Errorf("Not found: %s", name)
|
||||
}
|
||||
|
||||
if rs.Attributes[key] != value {
|
||||
is := rs.Primary
|
||||
if is == nil {
|
||||
return fmt.Errorf("No primary instance: %s", name)
|
||||
}
|
||||
|
||||
if is.Attributes[key] != value {
|
||||
return fmt.Errorf(
|
||||
"%s: Attribute '%s' expected %#v, got %#v",
|
||||
name,
|
||||
key,
|
||||
value,
|
||||
rs.Attributes[key])
|
||||
is.Attributes[key])
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -18,7 +18,7 @@ func init() {
|
|||
|
||||
func TestTest(t *testing.T) {
|
||||
mp := testProvider()
|
||||
mp.ApplyReturn = &terraform.ResourceState{
|
||||
mp.ApplyReturn = &terraform.InstanceState{
|
||||
ID: "foo",
|
||||
}
|
||||
|
||||
|
@ -33,13 +33,14 @@ func TestTest(t *testing.T) {
|
|||
checkStepFn := func(s *terraform.State) error {
|
||||
checkStep = true
|
||||
|
||||
rs, ok := s.Resources["test_instance.foo"]
|
||||
rs, ok := s.RootModule().Resources["test_instance.foo"]
|
||||
if !ok {
|
||||
t.Error("test_instance.foo is not present")
|
||||
return nil
|
||||
}
|
||||
if rs.ID != "foo" {
|
||||
t.Errorf("bad check ID: %s", rs.ID)
|
||||
is := rs.Primary
|
||||
if is.ID != "foo" {
|
||||
t.Errorf("bad check ID: %s", is.ID)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -120,7 +121,7 @@ func TestTest_preCheck(t *testing.T) {
|
|||
|
||||
func TestTest_stepError(t *testing.T) {
|
||||
mp := testProvider()
|
||||
mp.ApplyReturn = &terraform.ResourceState{
|
||||
mp.ApplyReturn = &terraform.InstanceState{
|
||||
ID: "foo",
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue