rpc: conform to new API

This commit is contained in:
Mitchell Hashimoto 2014-09-16 16:48:33 -07:00
parent 25a3cc480c
commit 585067c8f5
4 changed files with 47 additions and 26 deletions

View File

@ -73,10 +73,12 @@ func (p *ResourceProvider) Configure(c *terraform.ResourceConfig) error {
}
func (p *ResourceProvider) Apply(
s *terraform.ResourceState,
d *terraform.ResourceDiff) (*terraform.ResourceState, error) {
info *terraform.InstanceInfo,
s *terraform.InstanceState,
d *terraform.ResourceDiff) (*terraform.InstanceState, error) {
var resp ResourceProviderApplyResponse
args := &ResourceProviderApplyArgs{
Info: info,
State: s,
Diff: d,
}
@ -93,10 +95,12 @@ func (p *ResourceProvider) Apply(
}
func (p *ResourceProvider) Diff(
s *terraform.ResourceState,
info *terraform.InstanceInfo,
s *terraform.InstanceState,
c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
var resp ResourceProviderDiffResponse
args := &ResourceProviderDiffArgs{
Info: info,
State: s,
Config: c,
}
@ -112,9 +116,15 @@ func (p *ResourceProvider) Diff(
}
func (p *ResourceProvider) Refresh(
s *terraform.ResourceState) (*terraform.ResourceState, error) {
info *terraform.InstanceInfo,
s *terraform.InstanceState) (*terraform.InstanceState, error) {
var resp ResourceProviderRefreshResponse
err := p.Client.Call(p.Name+".Refresh", s, &resp)
args := &ResourceProviderRefreshArgs{
Info: info,
State: s,
}
err := p.Client.Call(p.Name+".Refresh", args, &resp)
if err != nil {
return nil, err
}
@ -148,17 +158,19 @@ type ResourceProviderConfigureResponse struct {
}
type ResourceProviderApplyArgs struct {
State *terraform.ResourceState
Info *terraform.InstanceInfo
State *terraform.InstanceState
Diff *terraform.ResourceDiff
}
type ResourceProviderApplyResponse struct {
State *terraform.ResourceState
State *terraform.InstanceState
Error *BasicError
}
type ResourceProviderDiffArgs struct {
State *terraform.ResourceState
Info *terraform.InstanceInfo
State *terraform.InstanceState
Config *terraform.ResourceConfig
}
@ -167,8 +179,13 @@ type ResourceProviderDiffResponse struct {
Error *BasicError
}
type ResourceProviderRefreshArgs struct {
Info *terraform.InstanceInfo
State *terraform.InstanceState
}
type ResourceProviderRefreshResponse struct {
State *terraform.ResourceState
State *terraform.InstanceState
Error *BasicError
}
@ -234,7 +251,7 @@ func (s *ResourceProviderServer) Configure(
func (s *ResourceProviderServer) Apply(
args *ResourceProviderApplyArgs,
result *ResourceProviderApplyResponse) error {
state, err := s.Provider.Apply(args.State, args.Diff)
state, err := s.Provider.Apply(args.Info, args.State, args.Diff)
*result = ResourceProviderApplyResponse{
State: state,
Error: NewBasicError(err),
@ -245,7 +262,7 @@ func (s *ResourceProviderServer) Apply(
func (s *ResourceProviderServer) Diff(
args *ResourceProviderDiffArgs,
result *ResourceProviderDiffResponse) error {
diff, err := s.Provider.Diff(args.State, args.Config)
diff, err := s.Provider.Diff(args.Info, args.State, args.Config)
*result = ResourceProviderDiffResponse{
Diff: diff,
Error: NewBasicError(err),
@ -254,9 +271,9 @@ func (s *ResourceProviderServer) Diff(
}
func (s *ResourceProviderServer) Refresh(
state *terraform.ResourceState,
args *ResourceProviderRefreshArgs,
result *ResourceProviderRefreshResponse) error {
newState, err := s.Provider.Refresh(state)
newState, err := s.Provider.Refresh(args.Info, args.State)
*result = ResourceProviderRefreshResponse{
State: newState,
Error: NewBasicError(err),

View File

@ -101,14 +101,15 @@ func TestResourceProvider_apply(t *testing.T) {
}
provider := &ResourceProvider{Client: client, Name: name}
p.ApplyReturn = &terraform.ResourceState{
p.ApplyReturn = &terraform.InstanceState{
ID: "bob",
}
// Apply
state := &terraform.ResourceState{}
info := &terraform.InstanceInfo{}
state := &terraform.InstanceState{}
diff := &terraform.ResourceDiff{}
newState, err := provider.Apply(state, diff)
newState, err := provider.Apply(info, state, diff)
if !p.ApplyCalled {
t.Fatal("apply should be called")
}
@ -142,11 +143,12 @@ func TestResourceProvider_diff(t *testing.T) {
}
// Diff
state := &terraform.ResourceState{}
info := &terraform.InstanceInfo{}
state := &terraform.InstanceState{}
config := &terraform.ResourceConfig{
Raw: map[string]interface{}{"foo": "bar"},
}
diff, err := provider.Diff(state, config)
diff, err := provider.Diff(info, state, config)
if !p.DiffCalled {
t.Fatal("diff should be called")
}
@ -173,11 +175,12 @@ func TestResourceProvider_diff_error(t *testing.T) {
p.DiffReturnError = errors.New("foo")
// Diff
state := &terraform.ResourceState{}
info := &terraform.InstanceInfo{}
state := &terraform.InstanceState{}
config := &terraform.ResourceConfig{
Raw: map[string]interface{}{"foo": "bar"},
}
diff, err := provider.Diff(state, config)
diff, err := provider.Diff(info, state, config)
if !p.DiffCalled {
t.Fatal("diff should be called")
}
@ -201,13 +204,14 @@ func TestResourceProvider_refresh(t *testing.T) {
}
provider := &ResourceProvider{Client: client, Name: name}
p.RefreshReturn = &terraform.ResourceState{
p.RefreshReturn = &terraform.InstanceState{
ID: "bob",
}
// Refresh
state := &terraform.ResourceState{}
newState, err := provider.Refresh(state)
info := &terraform.InstanceInfo{}
state := &terraform.InstanceState{}
newState, err := provider.Refresh(info, state)
if !p.RefreshCalled {
t.Fatal("refresh should be called")
}

View File

@ -36,7 +36,7 @@ func (p *ResourceProvisioner) Validate(c *terraform.ResourceConfig) ([]string, [
}
func (p *ResourceProvisioner) Apply(
s *terraform.ResourceState,
s *terraform.InstanceState,
c *terraform.ResourceConfig) error {
var resp ResourceProvisionerApplyResponse
args := &ResourceProvisionerApplyArgs{
@ -65,7 +65,7 @@ type ResourceProvisionerValidateResponse struct {
}
type ResourceProvisionerApplyArgs struct {
State *terraform.ResourceState
State *terraform.InstanceState
Config *terraform.ResourceConfig
}

View File

@ -22,7 +22,7 @@ func TestResourceProvisioner_apply(t *testing.T) {
provisioner := &ResourceProvisioner{Client: client, Name: name}
// Apply
state := &terraform.ResourceState{}
state := &terraform.InstanceState{}
conf := &terraform.ResourceConfig{}
err = provisioner.Apply(state, conf)
if !p.ApplyCalled {