terraform: flowerbox the ResourceProvider interface because it is huge
This commit is contained in:
parent
57b6e5cee9
commit
9142ec400e
|
@ -0,0 +1,47 @@
|
||||||
|
package terraform
|
||||||
|
|
||||||
|
/*
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"reflect"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/config/module"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestContextImport(t *testing.T) {
|
||||||
|
p := testProvider("aws")
|
||||||
|
ctx := testContext2(t, &ContextOpts{
|
||||||
|
Providers: map[string]ResourceProviderFactory{
|
||||||
|
"aws": testProviderFuncFixed(p),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if _, err := ctx.Plan(); err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
state, err := ctx.Apply()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
mod := state.RootModule()
|
||||||
|
if len(mod.Resources) < 2 {
|
||||||
|
t.Fatalf("bad: %#v", mod.Resources)
|
||||||
|
}
|
||||||
|
|
||||||
|
actual := strings.TrimSpace(state.String())
|
||||||
|
expected := strings.TrimSpace(testTerraformApplyStr)
|
||||||
|
if actual != expected {
|
||||||
|
t.Fatalf("bad: \n%s", actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
|
@ -4,6 +4,10 @@ package terraform
|
||||||
// resource provider: the thing that creates and manages the resources in
|
// resource provider: the thing that creates and manages the resources in
|
||||||
// a Terraform configuration.
|
// a Terraform configuration.
|
||||||
type ResourceProvider interface {
|
type ResourceProvider interface {
|
||||||
|
/*********************************************************************
|
||||||
|
* Functions related to the provider
|
||||||
|
*********************************************************************/
|
||||||
|
|
||||||
// Input is called to ask the provider to ask the user for input
|
// Input is called to ask the provider to ask the user for input
|
||||||
// for completing the configuration if necesarry.
|
// for completing the configuration if necesarry.
|
||||||
//
|
//
|
||||||
|
@ -25,18 +29,6 @@ type ResourceProvider interface {
|
||||||
// set.
|
// set.
|
||||||
Validate(*ResourceConfig) ([]string, []error)
|
Validate(*ResourceConfig) ([]string, []error)
|
||||||
|
|
||||||
// ValidateResource is called once at the beginning with the raw
|
|
||||||
// configuration (no interpolation done) and can return a list of warnings
|
|
||||||
// and/or errors.
|
|
||||||
//
|
|
||||||
// This is called once per resource.
|
|
||||||
//
|
|
||||||
// This should not assume any of the values in the resource configuration
|
|
||||||
// are valid since it is possible they have to be interpolated still.
|
|
||||||
// The primary use case of this call is to check that the required keys
|
|
||||||
// are set and that the general structure is correct.
|
|
||||||
ValidateResource(string, *ResourceConfig) ([]string, []error)
|
|
||||||
|
|
||||||
// Configure configures the provider itself with the configuration
|
// Configure configures the provider itself with the configuration
|
||||||
// given. This is useful for setting things like access keys.
|
// given. This is useful for setting things like access keys.
|
||||||
//
|
//
|
||||||
|
@ -49,6 +41,22 @@ type ResourceProvider interface {
|
||||||
// knows how to manage.
|
// knows how to manage.
|
||||||
Resources() []ResourceType
|
Resources() []ResourceType
|
||||||
|
|
||||||
|
/*********************************************************************
|
||||||
|
* Functions related to individual resources
|
||||||
|
*********************************************************************/
|
||||||
|
|
||||||
|
// ValidateResource is called once at the beginning with the raw
|
||||||
|
// configuration (no interpolation done) and can return a list of warnings
|
||||||
|
// and/or errors.
|
||||||
|
//
|
||||||
|
// This is called once per resource.
|
||||||
|
//
|
||||||
|
// This should not assume any of the values in the resource configuration
|
||||||
|
// are valid since it is possible they have to be interpolated still.
|
||||||
|
// The primary use case of this call is to check that the required keys
|
||||||
|
// are set and that the general structure is correct.
|
||||||
|
ValidateResource(string, *ResourceConfig) ([]string, []error)
|
||||||
|
|
||||||
// Apply applies a diff to a specific resource and returns the new
|
// Apply applies a diff to a specific resource and returns the new
|
||||||
// resource state along with an error.
|
// resource state along with an error.
|
||||||
//
|
//
|
||||||
|
@ -69,6 +77,11 @@ type ResourceProvider interface {
|
||||||
// Refresh refreshes a resource and updates all of its attributes
|
// Refresh refreshes a resource and updates all of its attributes
|
||||||
// with the latest information.
|
// with the latest information.
|
||||||
Refresh(*InstanceInfo, *InstanceState) (*InstanceState, error)
|
Refresh(*InstanceInfo, *InstanceState) (*InstanceState, error)
|
||||||
|
|
||||||
|
/*********************************************************************
|
||||||
|
* Functions related to importing
|
||||||
|
*********************************************************************/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResourceProviderCloser is an interface that providers that can close
|
// ResourceProviderCloser is an interface that providers that can close
|
||||||
|
|
Loading…
Reference in New Issue