mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-23 23:50:12 -06:00
cb2e9119aa
Signed-off-by: namgyalangmo <75657887+namgyalangmo@users.noreply.github.com>
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
// Copyright (c) The OpenTofu Authors
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
// Copyright (c) 2023 HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package tofu
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/opentofu/opentofu/internal/addrs"
|
|
"github.com/opentofu/opentofu/internal/configs/configschema"
|
|
"github.com/opentofu/opentofu/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
|
|
}
|