terraform: add Info field to Resource, remove from Node

This commit is contained in:
Mitchell Hashimoto 2014-09-19 23:01:51 -06:00
parent 06c862a379
commit 53c23266ca
5 changed files with 18 additions and 24 deletions

View File

@ -543,10 +543,7 @@ func (c *Context) applyWalkFn() depgraph.WalkFunc {
return err return err
} }
info := &InstanceInfo{ diff, err = r.Provider.Diff(r.Info, r.State.Primary, r.Config)
Type: r.State.Type,
}
diff, err = r.Provider.Diff(info, r.State.Primary, r.Config)
if err != nil { if err != nil {
return err return err
} }
@ -591,8 +588,7 @@ func (c *Context) applyWalkFn() depgraph.WalkFunc {
// With the completed diff, apply! // With the completed diff, apply!
log.Printf("[DEBUG] %s: Executing Apply", r.Id) log.Printf("[DEBUG] %s: Executing Apply", r.Id)
info := &InstanceInfo{Type: r.State.Type} is, applyerr := r.Provider.Apply(r.Info, r.State.Primary, diff)
is, applyerr := r.Provider.Apply(info, r.State.Primary, diff)
var errs []error var errs []error
if applyerr != nil { if applyerr != nil {
@ -798,8 +794,7 @@ func (c *Context) planWalkFn(result *Plan) depgraph.WalkFunc {
state.Type = r.State.Type state.Type = r.State.Type
} }
state.init() state.init()
info := &InstanceInfo{Type: state.Type} diff, err = r.Provider.Diff(r.Info, state.Primary, r.Config)
diff, err = r.Provider.Diff(info, state.Primary, r.Config)
if err != nil { if err != nil {
return err return err
} }
@ -918,8 +913,7 @@ func (c *Context) refreshWalkFn() depgraph.WalkFunc {
handleHook(h.PreRefresh(r.Id, is)) handleHook(h.PreRefresh(r.Id, is))
} }
info := &InstanceInfo{Type: r.State.Type} is, err := r.Provider.Refresh(r.Info, is)
is, err := r.Provider.Refresh(info, is)
if err != nil { if err != nil {
return err return err
} }
@ -977,7 +971,7 @@ func (c *Context) validateWalkFn(rws *[]string, res *[]error) depgraph.WalkFunc
log.Printf("[INFO] Validating resource: %s", rn.Resource.Id) log.Printf("[INFO] Validating resource: %s", rn.Resource.Id)
ws, es := rn.Resource.Provider.ValidateResource( ws, es := rn.Resource.Provider.ValidateResource(
rn.Type, rn.Resource.Config) rn.Resource.Info.Type, rn.Resource.Config)
for i, w := range ws { for i, w := range ws {
ws[i] = fmt.Sprintf("'%s' warning: %s", rn.Resource.Id, w) ws[i] = fmt.Sprintf("'%s' warning: %s", rn.Resource.Id, w)
} }

View File

@ -1887,7 +1887,7 @@ func TestContextPlan_state(t *testing.T) {
actual := strings.TrimSpace(plan.String()) actual := strings.TrimSpace(plan.String())
expected := strings.TrimSpace(testTerraformPlanStateStr) expected := strings.TrimSpace(testTerraformPlanStateStr)
if actual != expected { if actual != expected {
t.Fatalf("bad:\n%s", actual) t.Fatalf("bad:\n%s\n\nexpected:\n\n%s", actual, expected)
} }
} }

View File

@ -56,7 +56,6 @@ const GraphRootNode = "root"
// or a component of a resource. // or a component of a resource.
type GraphNodeResource struct { type GraphNodeResource struct {
Index int Index int
Type string
Config *config.Resource Config *config.Resource
Orphan bool Orphan bool
Resource *Resource Resource *Resource
@ -268,10 +267,10 @@ func graphAddConfigResources(
Name: name, Name: name,
Meta: &GraphNodeResource{ Meta: &GraphNodeResource{
Index: index, Index: index,
Type: r.Type,
Config: r, Config: r,
Resource: &Resource{ Resource: &Resource{
Id: name, Id: name,
Info: &InstanceInfo{Type: r.Type},
State: state, State: state,
Config: NewResourceConfig(r.RawConfig), Config: NewResourceConfig(r.RawConfig),
Tainted: len(state.Tainted) > 0, Tainted: len(state.Tainted) > 0,
@ -552,11 +551,11 @@ func graphAddMissingResourceProviders(
continue continue
} }
prefixes := matchingPrefixes(rn.Type, ps) prefixes := matchingPrefixes(rn.Resource.Info.Type, ps)
if len(prefixes) == 0 { if len(prefixes) == 0 {
errs = append(errs, fmt.Errorf( errs = append(errs, fmt.Errorf(
"No matching provider for type: %s", "No matching provider for type: %s",
rn.Type)) rn.Resource.Info.Type))
continue continue
} }
@ -608,10 +607,10 @@ func graphAddOrphans(g *depgraph.Graph, c *config.Config, s *State) {
Name: k, Name: k,
Meta: &GraphNodeResource{ Meta: &GraphNodeResource{
Index: -1, Index: -1,
Type: rs.Type,
Orphan: true, Orphan: true,
Resource: &Resource{ Resource: &Resource{
Id: k, Id: k,
Info: &InstanceInfo{Type: rs.Type},
State: rs, State: rs,
Config: NewResourceConfig(nil), Config: NewResourceConfig(nil),
}, },
@ -676,7 +675,7 @@ func graphAddProviderConfigs(g *depgraph.Graph, c *config.Config) {
// Look up the provider config for this resource // Look up the provider config for this resource
pcName := config.ProviderConfigName( pcName := config.ProviderConfigName(
resourceNode.Type, c.ProviderConfigs) resourceNode.Resource.Info.Type, c.ProviderConfigs)
if pcName == "" { if pcName == "" {
continue continue
} }
@ -817,9 +816,9 @@ func graphAddTainted(g *depgraph.Graph, s *State) {
Name: name, Name: name,
Meta: &GraphNodeResource{ Meta: &GraphNodeResource{
Index: -1, Index: -1,
Type: rs.Type,
Resource: &Resource{ Resource: &Resource{
Id: k, Id: k,
Info: &InstanceInfo{Type: rs.Type},
State: rs, State: rs,
Config: NewResourceConfig(nil), Config: NewResourceConfig(nil),
Diff: &InstanceDiff{Destroy: true}, Diff: &InstanceDiff{Destroy: true},
@ -987,18 +986,18 @@ func graphMapResourceProviders(g *depgraph.Graph) error {
panic(fmt.Sprintf( panic(fmt.Sprintf(
"Resource provider ID not found: %s (type: %s)", "Resource provider ID not found: %s (type: %s)",
rn.ResourceProviderID, rn.ResourceProviderID,
rn.Type)) rn.Resource.Info.Type))
} }
var provider ResourceProvider var provider ResourceProvider
for _, k := range rpn.ProviderKeys { for _, k := range rpn.ProviderKeys {
// Only try this provider if it has the right prefix // Only try this provider if it has the right prefix
if !strings.HasPrefix(rn.Type, k) { if !strings.HasPrefix(rn.Resource.Info.Type, k) {
continue continue
} }
rp := rpn.Providers[k] rp := rpn.Providers[k]
if ProviderSatisfies(rp, rn.Type) { if ProviderSatisfies(rp, rn.Resource.Info.Type) {
provider = rp provider = rp
break break
} }
@ -1007,7 +1006,7 @@ func graphMapResourceProviders(g *depgraph.Graph) error {
if provider == nil { if provider == nil {
errs = append(errs, fmt.Errorf( errs = append(errs, fmt.Errorf(
"Resource provider not found for resource type '%s'", "Resource provider not found for resource type '%s'",
rn.Type)) rn.Resource.Info.Type))
continue continue
} }

View File

@ -27,6 +27,7 @@ type ResourceProvisionerConfig struct {
// wants to reach. // wants to reach.
type Resource struct { type Resource struct {
Id string Id string
Info *InstanceInfo
Config *ResourceConfig Config *ResourceConfig
Diff *InstanceDiff Diff *InstanceDiff
Provider ResourceProvider Provider ResourceProvider

View File

@ -484,7 +484,7 @@ CREATE: aws_instance.bar
type: "" => "aws_instance" type: "" => "aws_instance"
UPDATE: aws_instance.foo UPDATE: aws_instance.foo
num: "" => "2" num: "" => "2"
type: "" => "" type: "" => "aws_instance"
STATE: STATE: