create refresh node expanders
This commit is contained in:
parent
74d85aa956
commit
0afa3710fd
|
@ -67,7 +67,7 @@ func (b *RefreshGraphBuilder) Steps() []GraphTransformer {
|
|||
}
|
||||
|
||||
concreteManagedResource := func(a *NodeAbstractResource) dag.Vertex {
|
||||
return &NodeRefreshableManagedResource{
|
||||
return &nodeExpandRefreshableManagedResource{
|
||||
NodeAbstractResource: a,
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ func (b *RefreshGraphBuilder) Steps() []GraphTransformer {
|
|||
}
|
||||
|
||||
concreteDataResource := func(a *NodeAbstractResource) dag.Vertex {
|
||||
return &NodeRefreshableDataResource{
|
||||
return &nodeExpandRefreshableDataResource{
|
||||
NodeAbstractResource: a,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,11 +102,11 @@ provider["registry.terraform.io/-/test"] (close) - *terraform.graphNodeCloseProv
|
|||
data.test_object.foo[1] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
||||
data.test_object.foo[2] - *terraform.NodeRefreshableManagedResourceInstance
|
||||
data.test_object.foo[2] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
||||
test_object.foo - *terraform.NodeRefreshableManagedResource
|
||||
test_object.foo - *terraform.nodeExpandRefreshableManagedResource
|
||||
test_object.foo[0] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
||||
test_object.foo[1] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
||||
test_object.foo[2] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
||||
test_object.foo - *terraform.NodeRefreshableManagedResource
|
||||
test_object.foo - *terraform.nodeExpandRefreshableManagedResource
|
||||
provider["registry.terraform.io/-/test"] - *terraform.NodeApplyableProvider
|
||||
test_object.foo[0] (deposed 00000001) - *terraform.NodePlanDeposedResourceInstanceObject
|
||||
provider["registry.terraform.io/-/test"] - *terraform.NodeApplyableProvider
|
||||
|
|
|
@ -10,12 +10,45 @@ import (
|
|||
"github.com/zclconf/go-cty/cty"
|
||||
)
|
||||
|
||||
// NodeRefreshableDataResource represents a resource that is "refreshable".
|
||||
type NodeRefreshableDataResource struct {
|
||||
type nodeExpandRefreshableDataResource struct {
|
||||
*NodeAbstractResource
|
||||
}
|
||||
|
||||
var (
|
||||
_ GraphNodeDynamicExpandable = (*nodeExpandRefreshableDataResource)(nil)
|
||||
_ GraphNodeReferenceable = (*nodeExpandRefreshableDataResource)(nil)
|
||||
_ GraphNodeReferencer = (*nodeExpandRefreshableDataResource)(nil)
|
||||
_ GraphNodeConfigResource = (*nodeExpandRefreshableDataResource)(nil)
|
||||
_ GraphNodeAttachResourceConfig = (*nodeExpandRefreshableDataResource)(nil)
|
||||
)
|
||||
|
||||
func (n *nodeExpandRefreshableDataResource) References() []*addrs.Reference {
|
||||
return (&NodeRefreshableManagedResource{NodeAbstractResource: n.NodeAbstractResource}).References()
|
||||
}
|
||||
|
||||
func (n *nodeExpandRefreshableDataResource) DynamicExpand(ctx EvalContext) (*Graph, error) {
|
||||
var g Graph
|
||||
|
||||
expander := ctx.InstanceExpander()
|
||||
for _, module := range expander.ExpandModule(n.Addr.Module) {
|
||||
g.Add(&NodeRefreshableDataResource{
|
||||
NodeAbstractResource: n.NodeAbstractResource,
|
||||
Addr: n.Addr.Resource.Absolute(module),
|
||||
})
|
||||
}
|
||||
|
||||
return &g, nil
|
||||
}
|
||||
|
||||
// NodeRefreshableDataResource represents a resource that is "refreshable".
|
||||
type NodeRefreshableDataResource struct {
|
||||
*NodeAbstractResource
|
||||
|
||||
Addr addrs.AbsResource
|
||||
}
|
||||
|
||||
var (
|
||||
_ GraphNodeModuleInstance = (*NodeRefreshableDataResource)(nil)
|
||||
_ GraphNodeDynamicExpandable = (*NodeRefreshableDataResource)(nil)
|
||||
_ GraphNodeReferenceable = (*NodeRefreshableDataResource)(nil)
|
||||
_ GraphNodeReferencer = (*NodeRefreshableDataResource)(nil)
|
||||
|
@ -24,6 +57,10 @@ var (
|
|||
_ GraphNodeAttachProviderMetaConfigs = (*NodeAbstractResource)(nil)
|
||||
)
|
||||
|
||||
func (n *NodeRefreshableDataResource) Path() addrs.ModuleInstance {
|
||||
return n.Addr.Module
|
||||
}
|
||||
|
||||
// GraphNodeDynamicExpandable
|
||||
func (n *NodeRefreshableDataResource) DynamicExpand(ctx EvalContext) (*Graph, error) {
|
||||
var diags tfdiags.Diagnostics
|
||||
|
@ -54,22 +91,18 @@ func (n *NodeRefreshableDataResource) DynamicExpand(ctx EvalContext) (*Graph, er
|
|||
// if we're transitioning whether "count" is set at all.
|
||||
fixResourceCountSetTransition(ctx, n.ResourceAddr(), count != -1)
|
||||
|
||||
var instanceAddrs []addrs.AbsResourceInstance
|
||||
|
||||
// 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.Addr.Module) {
|
||||
switch {
|
||||
case count >= 0:
|
||||
expander.SetResourceCount(path, n.ResourceAddr().Resource, count)
|
||||
case forEachMap != nil:
|
||||
expander.SetResourceForEach(path, n.ResourceAddr().Resource, forEachMap)
|
||||
default:
|
||||
expander.SetResourceSingle(path, n.ResourceAddr().Resource)
|
||||
}
|
||||
instanceAddrs = append(instanceAddrs, expander.ExpandResource(n.ResourceAddr().Absolute(path))...)
|
||||
switch {
|
||||
case count >= 0:
|
||||
expander.SetResourceCount(n.Addr.Module, n.ResourceAddr().Resource, count)
|
||||
case forEachMap != nil:
|
||||
expander.SetResourceForEach(n.Addr.Module, n.ResourceAddr().Resource, forEachMap)
|
||||
default:
|
||||
expander.SetResourceSingle(n.Addr.Module, n.ResourceAddr().Resource)
|
||||
}
|
||||
instanceAddrs := expander.ExpandResource(n.ResourceAddr().Absolute(path))
|
||||
|
||||
// Our graph transformers require access to the full state, so we'll
|
||||
// temporarily lock it while we work on this.
|
||||
|
|
|
@ -14,9 +14,7 @@ import (
|
|||
"github.com/hashicorp/terraform/tfdiags"
|
||||
)
|
||||
|
||||
// NodeRefreshableManagedResource represents a resource that is expandable into
|
||||
// NodeRefreshableManagedResourceInstance. Resource count orphans are also added.
|
||||
type NodeRefreshableManagedResource struct {
|
||||
type nodeExpandRefreshableManagedResource struct {
|
||||
*NodeAbstractResource
|
||||
|
||||
// We attach dependencies to the Resource during refresh, since the
|
||||
|
@ -25,16 +23,16 @@ type NodeRefreshableManagedResource struct {
|
|||
}
|
||||
|
||||
var (
|
||||
_ GraphNodeDynamicExpandable = (*NodeRefreshableManagedResource)(nil)
|
||||
_ GraphNodeReferenceable = (*NodeRefreshableManagedResource)(nil)
|
||||
_ GraphNodeReferencer = (*NodeRefreshableManagedResource)(nil)
|
||||
_ GraphNodeConfigResource = (*NodeRefreshableManagedResource)(nil)
|
||||
_ GraphNodeAttachResourceConfig = (*NodeRefreshableManagedResource)(nil)
|
||||
_ GraphNodeAttachDependencies = (*NodeRefreshableManagedResource)(nil)
|
||||
_ GraphNodeDynamicExpandable = (*nodeExpandRefreshableManagedResource)(nil)
|
||||
_ GraphNodeReferenceable = (*nodeExpandRefreshableManagedResource)(nil)
|
||||
_ GraphNodeReferencer = (*nodeExpandRefreshableManagedResource)(nil)
|
||||
_ GraphNodeConfigResource = (*nodeExpandRefreshableManagedResource)(nil)
|
||||
_ GraphNodeAttachResourceConfig = (*nodeExpandRefreshableManagedResource)(nil)
|
||||
_ GraphNodeAttachDependencies = (*nodeExpandRefreshableManagedResource)(nil)
|
||||
)
|
||||
|
||||
// GraphNodeAttachDependencies
|
||||
func (n *NodeRefreshableManagedResource) AttachDependencies(deps []addrs.ConfigResource) {
|
||||
func (n *nodeExpandRefreshableManagedResource) AttachDependencies(deps []addrs.ConfigResource) {
|
||||
var shimmed []addrs.AbsResource
|
||||
for _, r := range deps {
|
||||
shimmed = append(shimmed, r.Absolute(r.Module.UnkeyedInstanceShim()))
|
||||
|
@ -43,6 +41,50 @@ func (n *NodeRefreshableManagedResource) AttachDependencies(deps []addrs.ConfigR
|
|||
n.Dependencies = shimmed
|
||||
}
|
||||
|
||||
func (n *nodeExpandRefreshableManagedResource) References() []*addrs.Reference {
|
||||
return (&NodeRefreshableManagedResource{NodeAbstractResource: n.NodeAbstractResource}).References()
|
||||
}
|
||||
|
||||
func (n *nodeExpandRefreshableManagedResource) DynamicExpand(ctx EvalContext) (*Graph, error) {
|
||||
var g Graph
|
||||
|
||||
expander := ctx.InstanceExpander()
|
||||
for _, module := range expander.ExpandModule(n.Addr.Module) {
|
||||
g.Add(&NodeRefreshableManagedResource{
|
||||
NodeAbstractResource: n.NodeAbstractResource,
|
||||
Addr: n.Addr.Resource.Absolute(module),
|
||||
Dependencies: n.Dependencies,
|
||||
})
|
||||
}
|
||||
|
||||
return &g, nil
|
||||
}
|
||||
|
||||
// NodeRefreshableManagedResource represents a resource that is expandable into
|
||||
// NodeRefreshableManagedResourceInstance. Resource count orphans are also added.
|
||||
type NodeRefreshableManagedResource struct {
|
||||
*NodeAbstractResource
|
||||
|
||||
Addr addrs.AbsResource
|
||||
|
||||
// We attach dependencies to the Resource during refresh, since the
|
||||
// instances are instantiated during DynamicExpand.
|
||||
Dependencies []addrs.AbsResource
|
||||
}
|
||||
|
||||
var (
|
||||
_ GraphNodeModuleInstance = (*NodeRefreshableManagedResource)(nil)
|
||||
_ GraphNodeDynamicExpandable = (*NodeRefreshableManagedResource)(nil)
|
||||
_ GraphNodeReferenceable = (*NodeRefreshableManagedResource)(nil)
|
||||
_ GraphNodeReferencer = (*NodeRefreshableManagedResource)(nil)
|
||||
_ GraphNodeConfigResource = (*NodeRefreshableManagedResource)(nil)
|
||||
_ GraphNodeAttachResourceConfig = (*NodeRefreshableManagedResource)(nil)
|
||||
)
|
||||
|
||||
func (n *NodeRefreshableManagedResource) Path() addrs.ModuleInstance {
|
||||
return n.Addr.Module
|
||||
}
|
||||
|
||||
// GraphNodeDynamicExpandable
|
||||
func (n *NodeRefreshableManagedResource) DynamicExpand(ctx EvalContext) (*Graph, error) {
|
||||
var diags tfdiags.Diagnostics
|
||||
|
@ -65,15 +107,13 @@ 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.Addr.Module) {
|
||||
switch {
|
||||
case count >= 0:
|
||||
expander.SetResourceCount(module, n.ResourceAddr().Resource, count)
|
||||
case forEachMap != nil:
|
||||
expander.SetResourceForEach(module, n.ResourceAddr().Resource, forEachMap)
|
||||
default:
|
||||
expander.SetResourceSingle(module, n.ResourceAddr().Resource)
|
||||
}
|
||||
switch {
|
||||
case count >= 0:
|
||||
expander.SetResourceCount(n.Addr.Module, n.ResourceAddr().Resource, count)
|
||||
case forEachMap != nil:
|
||||
expander.SetResourceForEach(n.Addr.Module, n.ResourceAddr().Resource, forEachMap)
|
||||
default:
|
||||
expander.SetResourceSingle(n.Addr.Module, n.ResourceAddr().Resource)
|
||||
}
|
||||
instanceAddrs := expander.ExpandModuleResource(n.Addr.Module, n.ResourceAddr().Resource)
|
||||
|
||||
|
|
|
@ -173,7 +173,7 @@ func (t *ProviderTransformer) Transform(g *Graph) error {
|
|||
p := req.Addr
|
||||
target := m[key]
|
||||
|
||||
_, ok := v.(GraphNodeModuleInstance)
|
||||
_, ok := v.(GraphNodeModulePath)
|
||||
if !ok && target == nil {
|
||||
// No target and no path to traverse up from
|
||||
diags = diags.Append(fmt.Errorf("%s: provider %s couldn't be found", dag.VertexName(v), p))
|
||||
|
|
Loading…
Reference in New Issue