incorporate addrs.ConfigResource

This commit is contained in:
James Bardin 2020-03-12 14:47:28 -04:00
parent 9054716caf
commit d65bd64955
10 changed files with 34 additions and 56 deletions

View File

@ -452,8 +452,7 @@ func (n *EvalMaybeRestoreDeposedObject) Eval(ctx EvalContext) (interface{}, erro
// in that case, allowing expression evaluation to see it as a zero-element // in that case, allowing expression evaluation to see it as a zero-element
// list rather than as not set at all. // list rather than as not set at all.
type EvalWriteResourceState struct { type EvalWriteResourceState struct {
Addr addrs.Resource Addr addrs.ConfigResource
Module addrs.Module
Config *configs.Resource Config *configs.Resource
ProviderAddr addrs.AbsProviderConfig ProviderAddr addrs.AbsProviderConfig
} }
@ -489,18 +488,18 @@ func (n *EvalWriteResourceState) Eval(ctx EvalContext) (interface{}, error) {
// can refer to it. Since this node represents the abstract module, we need // can refer to it. Since this node represents the abstract module, we need
// to expand the module here to create all resources. // to expand the module here to create all resources.
expander := ctx.InstanceExpander() expander := ctx.InstanceExpander()
for _, module := range expander.ExpandModule(n.Module) { for _, module := range expander.ExpandModule(n.Addr.Module) {
// This method takes care of all of the business logic of updating this // This method takes care of all of the business logic of updating this
// while ensuring that any existing instances are preserved, etc. // while ensuring that any existing instances are preserved, etc.
state.SetResourceMeta(n.Addr.Absolute(module), eachMode, n.ProviderAddr) state.SetResourceMeta(n.Addr.Absolute(module), eachMode, n.ProviderAddr)
switch eachMode { switch eachMode {
case states.EachList: case states.EachList:
expander.SetResourceCount(module, n.Addr, count) expander.SetResourceCount(module, n.Addr.Resource, count)
case states.EachMap: case states.EachMap:
expander.SetResourceForEach(module, n.Addr, forEach) expander.SetResourceForEach(module, n.Addr.Resource, forEach)
default: default:
expander.SetResourceSingle(module, n.Addr) expander.SetResourceSingle(module, n.Addr.Resource)
} }
} }

View File

@ -209,7 +209,7 @@ func TestApplyGraphBuilder_doubleCBD(t *testing.T) {
continue continue
} }
switch tv.Addr.Name { switch tv.Addr.Resource.Name {
case "A": case "A":
destroyA = fmt.Sprintf("test_object.A (destroy deposed %s)", tv.DeposedKey) destroyA = fmt.Sprintf("test_object.A (destroy deposed %s)", tv.DeposedKey)
case "B": case "B":

View File

@ -59,7 +59,7 @@ func (n *NodeRefreshableDataResource) DynamicExpand(ctx EvalContext) (*Graph, er
// Inform our instance expander about our expansion results above, // Inform our instance expander about our expansion results above,
// and then use it to calculate the instance addresses we'll expand for. // and then use it to calculate the instance addresses we'll expand for.
expander := ctx.InstanceExpander() expander := ctx.InstanceExpander()
for _, path := range expander.ExpandModule(n.Module) { for _, path := range expander.ExpandModule(n.Addr.Module) {
switch { switch {
case count >= 0: case count >= 0:
expander.SetResourceCount(path, n.ResourceAddr().Resource, count) expander.SetResourceCount(path, n.ResourceAddr().Resource, count)

View File

@ -40,12 +40,7 @@ func TestNodeRefreshableDataResourceDynamicExpand_scaleOut(t *testing.T) {
n := &NodeRefreshableDataResource{ n := &NodeRefreshableDataResource{
NodeAbstractResource: &NodeAbstractResource{ NodeAbstractResource: &NodeAbstractResource{
Addr: addrs.Resource{ Addr: addrs.RootModule.Resource(addrs.DataResourceMode, "aws_instance", "foo"),
Mode: addrs.DataResourceMode,
Type: "aws_instance",
Name: "foo",
},
Module: addrs.RootModule,
Config: m.Module.DataResources["data.aws_instance.foo"], Config: m.Module.DataResources["data.aws_instance.foo"],
}, },
} }
@ -125,12 +120,7 @@ func TestNodeRefreshableDataResourceDynamicExpand_scaleIn(t *testing.T) {
n := &NodeRefreshableDataResource{ n := &NodeRefreshableDataResource{
NodeAbstractResource: &NodeAbstractResource{ NodeAbstractResource: &NodeAbstractResource{
Addr: addrs.Resource{ Addr: addrs.RootModule.Resource(addrs.DataResourceMode, "aws_instance", "foo"),
Mode: addrs.DataResourceMode,
Type: "aws_instance",
Name: "foo",
},
Module: addrs.RootModule,
Config: m.Module.DataResources["data.aws_instance.foo"], Config: m.Module.DataResources["data.aws_instance.foo"],
ResolvedProvider: addrs.AbsProviderConfig{ ResolvedProvider: addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("aws"), Provider: addrs.NewLegacyProvider("aws"),

View File

@ -43,8 +43,7 @@ type GraphNodeResourceInstance interface {
// operations. It registers all the interfaces for a resource that common // operations. It registers all the interfaces for a resource that common
// across multiple operation types. // across multiple operation types.
type NodeAbstractResource struct { type NodeAbstractResource struct {
Addr addrs.Resource Addr addrs.ConfigResource
Module addrs.Module
// The fields below will be automatically set using the Attach // The fields below will be automatically set using the Attach
// interfaces if you're running those transforms, but also be explicitly // interfaces if you're running those transforms, but also be explicitly
@ -80,15 +79,18 @@ var (
) )
func (n *NodeAbstractResource) addr() addrs.AbsResource { func (n *NodeAbstractResource) addr() addrs.AbsResource {
return n.Addr.Absolute(n.Module.UnkeyedInstanceShim()) return n.Addr.Absolute(n.Addr.Module.UnkeyedInstanceShim())
} }
// NewNodeAbstractResource creates an abstract resource graph node for // NewNodeAbstractResource creates an abstract resource graph node for
// the given absolute resource address. // the given absolute resource address.
func NewNodeAbstractResource(addr addrs.AbsResource) *NodeAbstractResource { func NewNodeAbstractResource(addr addrs.AbsResource) *NodeAbstractResource {
// FIXME: this should probably accept a ConfigResource
return &NodeAbstractResource{ return &NodeAbstractResource{
Addr: addr.Resource, Addr: addrs.ConfigResource{
Module: addr.Module.Module(), Resource: addr.Resource,
Module: addr.Module.Module(),
},
} }
} }
@ -136,8 +138,10 @@ func NewNodeAbstractResourceInstance(addr addrs.AbsResourceInstance) *NodeAbstra
// request. // request.
return &NodeAbstractResourceInstance{ return &NodeAbstractResourceInstance{
NodeAbstractResource: NodeAbstractResource{ NodeAbstractResource: NodeAbstractResource{
Addr: addr.Resource.Resource, Addr: addrs.ConfigResource{
Module: addr.Module.Module(), Resource: addr.Resource.Resource,
Module: addr.Module.Module(),
},
}, },
ModuleInstance: addr.Module, ModuleInstance: addr.Module,
InstanceKey: addr.Resource.Key, InstanceKey: addr.Resource.Key,
@ -154,7 +158,7 @@ func (n *NodeAbstractResourceInstance) Name() string {
// GraphNodeModuleInstance // GraphNodeModuleInstance
func (n *NodeAbstractResource) Path() addrs.ModuleInstance { func (n *NodeAbstractResource) Path() addrs.ModuleInstance {
return n.Module.UnkeyedInstanceShim() return n.Addr.Module.UnkeyedInstanceShim()
} }
func (n *NodeAbstractResourceInstance) Path() addrs.ModuleInstance { func (n *NodeAbstractResourceInstance) Path() addrs.ModuleInstance {
@ -163,12 +167,12 @@ func (n *NodeAbstractResourceInstance) Path() addrs.ModuleInstance {
// GraphNodeModulePath // GraphNodeModulePath
func (n *NodeAbstractResource) ModulePath() addrs.Module { func (n *NodeAbstractResource) ModulePath() addrs.Module {
return n.Module return n.Addr.Module
} }
// GraphNodeReferenceable // GraphNodeReferenceable
func (n *NodeAbstractResource) ReferenceableAddrs() []addrs.Referenceable { func (n *NodeAbstractResource) ReferenceableAddrs() []addrs.Referenceable {
return []addrs.Referenceable{n.Addr} return []addrs.Referenceable{n.Addr.Resource}
} }
// GraphNodeReferenceable // GraphNodeReferenceable
@ -314,7 +318,7 @@ func (n *NodeAbstractResource) ProvidedBy() (addrs.ProviderConfig, bool) {
// GraphNodeProviderConsumer // GraphNodeProviderConsumer
func (n *NodeAbstractResource) ImpliedProvider() addrs.Provider { func (n *NodeAbstractResource) ImpliedProvider() addrs.Provider {
return n.Addr.DefaultProvider() return n.Addr.Resource.DefaultProvider()
} }
// GraphNodeProviderConsumer // GraphNodeProviderConsumer
@ -342,7 +346,7 @@ func (n *NodeAbstractResourceInstance) ProvidedBy() (addrs.ProviderConfig, bool)
// GraphNodeProviderConsumer // GraphNodeProviderConsumer
func (n *NodeAbstractResourceInstance) ImpliedProvider() addrs.Provider { func (n *NodeAbstractResourceInstance) ImpliedProvider() addrs.Provider {
return n.Addr.DefaultProvider() return n.Addr.Resource.DefaultProvider()
} }
// GraphNodeProvisionerConsumer // GraphNodeProvisionerConsumer

View File

@ -61,7 +61,6 @@ func (n *NodeApplyableResource) EvalTree() EvalNode {
return &EvalWriteResourceState{ return &EvalWriteResourceState{
Addr: n.Addr, Addr: n.Addr,
Module: n.Module,
Config: n.Config, Config: n.Config,
ProviderAddr: n.ResolvedProvider, ProviderAddr: n.ResolvedProvider,
} }

View File

@ -38,7 +38,6 @@ func (n *NodePlannableResource) EvalTree() EvalNode {
// this ensures we can reference the resource even if the count is 0 // this ensures we can reference the resource even if the count is 0
return &EvalWriteResourceState{ return &EvalWriteResourceState{
Addr: n.Addr, Addr: n.Addr,
Module: n.Module,
Config: n.Config, Config: n.Config,
ProviderAddr: n.ResolvedProvider, ProviderAddr: n.ResolvedProvider,
} }

View File

@ -60,7 +60,7 @@ func (n *NodeRefreshableManagedResource) DynamicExpand(ctx EvalContext) (*Graph,
// Inform our instance expander about our expansion results above, // Inform our instance expander about our expansion results above,
// and then use it to calculate the instance addresses we'll expand for. // and then use it to calculate the instance addresses we'll expand for.
expander := ctx.InstanceExpander() expander := ctx.InstanceExpander()
for _, module := range expander.ExpandModule(n.Module) { for _, module := range expander.ExpandModule(n.Addr.Module) {
switch { switch {
case count >= 0: case count >= 0:
expander.SetResourceCount(module, n.ResourceAddr().Resource, count) expander.SetResourceCount(module, n.ResourceAddr().Resource, count)
@ -70,7 +70,7 @@ func (n *NodeRefreshableManagedResource) DynamicExpand(ctx EvalContext) (*Graph,
expander.SetResourceSingle(module, n.ResourceAddr().Resource) expander.SetResourceSingle(module, n.ResourceAddr().Resource)
} }
} }
instanceAddrs := expander.ExpandResource(n.Module, n.ResourceAddr().Resource) instanceAddrs := expander.ExpandResource(n.Addr.Module, n.ResourceAddr().Resource)
// Our graph transformers require access to the full state, so we'll // Our graph transformers require access to the full state, so we'll
// temporarily lock it while we work on this. // temporarily lock it while we work on this.

View File

@ -42,12 +42,7 @@ func TestNodeRefreshableManagedResourceDynamicExpand_scaleOut(t *testing.T) {
n := &NodeRefreshableManagedResource{ n := &NodeRefreshableManagedResource{
NodeAbstractResource: &NodeAbstractResource{ NodeAbstractResource: &NodeAbstractResource{
Addr: addrs.Resource{ Addr: addrs.RootModule.Resource(addrs.ManagedResourceMode, "aws_instance", "foo"),
Mode: addrs.ManagedResourceMode,
Type: "aws_instance",
Name: "foo",
},
Module: addrs.RootModule,
Config: m.Module.ManagedResources["aws_instance.foo"], Config: m.Module.ManagedResources["aws_instance.foo"],
}, },
} }
@ -127,12 +122,7 @@ func TestNodeRefreshableManagedResourceDynamicExpand_scaleIn(t *testing.T) {
n := &NodeRefreshableManagedResource{ n := &NodeRefreshableManagedResource{
NodeAbstractResource: &NodeAbstractResource{ NodeAbstractResource: &NodeAbstractResource{
Addr: addrs.Resource{ Addr: addrs.RootModule.Resource(addrs.ManagedResourceMode, "aws_instance", "foo"),
Mode: addrs.ManagedResourceMode,
Type: "aws_instance",
Name: "foo",
},
Module: addrs.RootModule,
Config: m.Module.ManagedResources["aws_instance.foo"], Config: m.Module.ManagedResources["aws_instance.foo"],
}, },
} }
@ -172,12 +162,7 @@ func TestNodeRefreshableManagedResourceEvalTree_scaleOut(t *testing.T) {
n := &NodeRefreshableManagedResourceInstance{ n := &NodeRefreshableManagedResourceInstance{
NodeAbstractResourceInstance: &NodeAbstractResourceInstance{ NodeAbstractResourceInstance: &NodeAbstractResourceInstance{
NodeAbstractResource: NodeAbstractResource{ NodeAbstractResource: NodeAbstractResource{
Addr: addrs.Resource{ Addr: addrs.RootModule.Resource(addrs.ManagedResourceMode, "aws_instance", "foo"),
Mode: addrs.ManagedResourceMode,
Type: "aws_instance",
Name: "foo",
},
Module: addrs.RootModule,
Config: m.Module.ManagedResources["aws_instance.foo"], Config: m.Module.ManagedResources["aws_instance.foo"],
}, },
InstanceKey: addrs.IntKey(2), InstanceKey: addrs.IntKey(2),

View File

@ -111,8 +111,10 @@ func (t *ConfigTransformer) transformSingle(g *Graph, config *configs.Config) er
} }
abstract := &NodeAbstractResource{ abstract := &NodeAbstractResource{
Addr: relAddr, Addr: addrs.ConfigResource{
Module: path, Resource: relAddr,
Module: path,
},
} }
if _, ok := t.uniqueMap[abstract.Name()]; ok { if _, ok := t.uniqueMap[abstract.Name()]; ok {