github.com/opentofu/opentofu@v1.7.1/internal/tofu/transform_external_reference.go (about)

     1  // Copyright (c) The OpenTofu Authors
     2  // SPDX-License-Identifier: MPL-2.0
     3  // Copyright (c) 2023 HashiCorp, Inc.
     4  // SPDX-License-Identifier: MPL-2.0
     5  
     6  package tofu
     7  
     8  import "github.com/opentofu/opentofu/internal/addrs"
     9  
    10  // ExternalReferenceTransformer will add a GraphNodeReferencer into the graph
    11  // that makes no changes to the graph itself but, by referencing the addresses
    12  // within ExternalReferences, ensures that any temporary nodes that are required
    13  // by an external caller, such as the tofu testing framework, are not
    14  // skipped because they are not referenced from within the module.
    15  type ExternalReferenceTransformer struct {
    16  	ExternalReferences []*addrs.Reference
    17  }
    18  
    19  func (t *ExternalReferenceTransformer) Transform(g *Graph) error {
    20  	if len(t.ExternalReferences) == 0 {
    21  		return nil
    22  	}
    23  
    24  	g.Add(&nodeExternalReference{
    25  		ExternalReferences: t.ExternalReferences,
    26  	})
    27  	return nil
    28  }