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
// list rather than as not set at all.
type EvalWriteResourceState struct {
Addr addrs.Resource
Module addrs.Module
Addr addrs.ConfigResource
Config *configs.Resource
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
// to expand the module here to create all resources.
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
// while ensuring that any existing instances are preserved, etc.
state.SetResourceMeta(n.Addr.Absolute(module), eachMode, n.ProviderAddr)
switch eachMode {
case states.EachList:
expander.SetResourceCount(module, n.Addr, count)
expander.SetResourceCount(module, n.Addr.Resource, count)
case states.EachMap:
expander.SetResourceForEach(module, n.Addr, forEach)
expander.SetResourceForEach(module, n.Addr.Resource, forEach)
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
}
switch tv.Addr.Name {
switch tv.Addr.Resource.Name {
case "A":
destroyA = fmt.Sprintf("test_object.A (destroy deposed %s)", tv.DeposedKey)
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,
// and then use it to calculate the instance addresses we'll expand for.
expander := ctx.InstanceExpander()
for _, path := range expander.ExpandModule(n.Module) {
for _, path := range expander.ExpandModule(n.Addr.Module) {
switch {
case count >= 0:
expander.SetResourceCount(path, n.ResourceAddr().Resource, count)

View File

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

View File

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

View File

@ -61,7 +61,6 @@ func (n *NodeApplyableResource) EvalTree() EvalNode {
return &EvalWriteResourceState{
Addr: n.Addr,
Module: n.Module,
Config: n.Config,
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
return &EvalWriteResourceState{
Addr: n.Addr,
Module: n.Module,
Config: n.Config,
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,
// and then use it to calculate the instance addresses we'll expand for.
expander := ctx.InstanceExpander()
for _, module := range expander.ExpandModule(n.Module) {
for _, module := range expander.ExpandModule(n.Addr.Module) {
switch {
case count >= 0:
expander.SetResourceCount(module, n.ResourceAddr().Resource, count)
@ -70,7 +70,7 @@ func (n *NodeRefreshableManagedResource) DynamicExpand(ctx EvalContext) (*Graph,
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
// temporarily lock it while we work on this.

View File

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

View File

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