mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-06 14:13:16 -06:00
36d0a50427
This is part of a general effort to move all of Terraform's non-library package surface under internal in order to reinforce that these are for internal use within Terraform only. If you were previously importing packages under this prefix into an external codebase, you could pin to an earlier release tag as an interim solution until you've make a plan to achieve the same functionality some other way.
37 lines
944 B
Go
37 lines
944 B
Go
package terraform
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/hashicorp/terraform/internal/addrs"
|
|
"github.com/hashicorp/terraform/internal/configs/configschema"
|
|
"github.com/hashicorp/terraform/internal/dag"
|
|
)
|
|
|
|
// ResourceCountTransformer is a GraphTransformer that expands the count
|
|
// out for a specific resource.
|
|
//
|
|
// This assumes that the count is already interpolated.
|
|
type ResourceCountTransformer struct {
|
|
Concrete ConcreteResourceInstanceNodeFunc
|
|
Schema *configschema.Block
|
|
|
|
Addr addrs.ConfigResource
|
|
InstanceAddrs []addrs.AbsResourceInstance
|
|
}
|
|
|
|
func (t *ResourceCountTransformer) Transform(g *Graph) error {
|
|
for _, addr := range t.InstanceAddrs {
|
|
abstract := NewNodeAbstractResourceInstance(addr)
|
|
abstract.Schema = t.Schema
|
|
var node dag.Vertex = abstract
|
|
if f := t.Concrete; f != nil {
|
|
node = f(abstract)
|
|
}
|
|
|
|
log.Printf("[TRACE] ResourceCountTransformer: adding %s as %T", addr, node)
|
|
g.Add(node)
|
|
}
|
|
return nil
|
|
}
|