terraform: add Info field to Resource, remove from Node
This commit is contained in:
parent
06c862a379
commit
53c23266ca
|
@ -543,10 +543,7 @@ func (c *Context) applyWalkFn() depgraph.WalkFunc {
|
|||
return err
|
||||
}
|
||||
|
||||
info := &InstanceInfo{
|
||||
Type: r.State.Type,
|
||||
}
|
||||
diff, err = r.Provider.Diff(info, r.State.Primary, r.Config)
|
||||
diff, err = r.Provider.Diff(r.Info, r.State.Primary, r.Config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -591,8 +588,7 @@ func (c *Context) applyWalkFn() depgraph.WalkFunc {
|
|||
|
||||
// With the completed diff, apply!
|
||||
log.Printf("[DEBUG] %s: Executing Apply", r.Id)
|
||||
info := &InstanceInfo{Type: r.State.Type}
|
||||
is, applyerr := r.Provider.Apply(info, r.State.Primary, diff)
|
||||
is, applyerr := r.Provider.Apply(r.Info, r.State.Primary, diff)
|
||||
|
||||
var errs []error
|
||||
if applyerr != nil {
|
||||
|
@ -798,8 +794,7 @@ func (c *Context) planWalkFn(result *Plan) depgraph.WalkFunc {
|
|||
state.Type = r.State.Type
|
||||
}
|
||||
state.init()
|
||||
info := &InstanceInfo{Type: state.Type}
|
||||
diff, err = r.Provider.Diff(info, state.Primary, r.Config)
|
||||
diff, err = r.Provider.Diff(r.Info, state.Primary, r.Config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -918,8 +913,7 @@ func (c *Context) refreshWalkFn() depgraph.WalkFunc {
|
|||
handleHook(h.PreRefresh(r.Id, is))
|
||||
}
|
||||
|
||||
info := &InstanceInfo{Type: r.State.Type}
|
||||
is, err := r.Provider.Refresh(info, is)
|
||||
is, err := r.Provider.Refresh(r.Info, is)
|
||||
if err != nil {
|
||||
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)
|
||||
ws, es := rn.Resource.Provider.ValidateResource(
|
||||
rn.Type, rn.Resource.Config)
|
||||
rn.Resource.Info.Type, rn.Resource.Config)
|
||||
for i, w := range ws {
|
||||
ws[i] = fmt.Sprintf("'%s' warning: %s", rn.Resource.Id, w)
|
||||
}
|
||||
|
|
|
@ -1887,7 +1887,7 @@ func TestContextPlan_state(t *testing.T) {
|
|||
actual := strings.TrimSpace(plan.String())
|
||||
expected := strings.TrimSpace(testTerraformPlanStateStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad:\n%s", actual)
|
||||
t.Fatalf("bad:\n%s\n\nexpected:\n\n%s", actual, expected)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,6 @@ const GraphRootNode = "root"
|
|||
// or a component of a resource.
|
||||
type GraphNodeResource struct {
|
||||
Index int
|
||||
Type string
|
||||
Config *config.Resource
|
||||
Orphan bool
|
||||
Resource *Resource
|
||||
|
@ -268,10 +267,10 @@ func graphAddConfigResources(
|
|||
Name: name,
|
||||
Meta: &GraphNodeResource{
|
||||
Index: index,
|
||||
Type: r.Type,
|
||||
Config: r,
|
||||
Resource: &Resource{
|
||||
Id: name,
|
||||
Info: &InstanceInfo{Type: r.Type},
|
||||
State: state,
|
||||
Config: NewResourceConfig(r.RawConfig),
|
||||
Tainted: len(state.Tainted) > 0,
|
||||
|
@ -552,11 +551,11 @@ func graphAddMissingResourceProviders(
|
|||
continue
|
||||
}
|
||||
|
||||
prefixes := matchingPrefixes(rn.Type, ps)
|
||||
prefixes := matchingPrefixes(rn.Resource.Info.Type, ps)
|
||||
if len(prefixes) == 0 {
|
||||
errs = append(errs, fmt.Errorf(
|
||||
"No matching provider for type: %s",
|
||||
rn.Type))
|
||||
rn.Resource.Info.Type))
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -608,10 +607,10 @@ func graphAddOrphans(g *depgraph.Graph, c *config.Config, s *State) {
|
|||
Name: k,
|
||||
Meta: &GraphNodeResource{
|
||||
Index: -1,
|
||||
Type: rs.Type,
|
||||
Orphan: true,
|
||||
Resource: &Resource{
|
||||
Id: k,
|
||||
Info: &InstanceInfo{Type: rs.Type},
|
||||
State: rs,
|
||||
Config: NewResourceConfig(nil),
|
||||
},
|
||||
|
@ -676,7 +675,7 @@ func graphAddProviderConfigs(g *depgraph.Graph, c *config.Config) {
|
|||
|
||||
// Look up the provider config for this resource
|
||||
pcName := config.ProviderConfigName(
|
||||
resourceNode.Type, c.ProviderConfigs)
|
||||
resourceNode.Resource.Info.Type, c.ProviderConfigs)
|
||||
if pcName == "" {
|
||||
continue
|
||||
}
|
||||
|
@ -817,9 +816,9 @@ func graphAddTainted(g *depgraph.Graph, s *State) {
|
|||
Name: name,
|
||||
Meta: &GraphNodeResource{
|
||||
Index: -1,
|
||||
Type: rs.Type,
|
||||
Resource: &Resource{
|
||||
Id: k,
|
||||
Info: &InstanceInfo{Type: rs.Type},
|
||||
State: rs,
|
||||
Config: NewResourceConfig(nil),
|
||||
Diff: &InstanceDiff{Destroy: true},
|
||||
|
@ -987,18 +986,18 @@ func graphMapResourceProviders(g *depgraph.Graph) error {
|
|||
panic(fmt.Sprintf(
|
||||
"Resource provider ID not found: %s (type: %s)",
|
||||
rn.ResourceProviderID,
|
||||
rn.Type))
|
||||
rn.Resource.Info.Type))
|
||||
}
|
||||
|
||||
var provider ResourceProvider
|
||||
for _, k := range rpn.ProviderKeys {
|
||||
// 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
|
||||
}
|
||||
|
||||
rp := rpn.Providers[k]
|
||||
if ProviderSatisfies(rp, rn.Type) {
|
||||
if ProviderSatisfies(rp, rn.Resource.Info.Type) {
|
||||
provider = rp
|
||||
break
|
||||
}
|
||||
|
@ -1007,7 +1006,7 @@ func graphMapResourceProviders(g *depgraph.Graph) error {
|
|||
if provider == nil {
|
||||
errs = append(errs, fmt.Errorf(
|
||||
"Resource provider not found for resource type '%s'",
|
||||
rn.Type))
|
||||
rn.Resource.Info.Type))
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ type ResourceProvisionerConfig struct {
|
|||
// wants to reach.
|
||||
type Resource struct {
|
||||
Id string
|
||||
Info *InstanceInfo
|
||||
Config *ResourceConfig
|
||||
Diff *InstanceDiff
|
||||
Provider ResourceProvider
|
||||
|
|
|
@ -484,7 +484,7 @@ CREATE: aws_instance.bar
|
|||
type: "" => "aws_instance"
|
||||
UPDATE: aws_instance.foo
|
||||
num: "" => "2"
|
||||
type: "" => ""
|
||||
type: "" => "aws_instance"
|
||||
|
||||
STATE:
|
||||
|
||||
|
|
Loading…
Reference in New Issue