github.com/opentofu/opentofu@v1.7.1/internal/tofu/node_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  // nodeExternalReference allows external callers (such as the testing framework)
    11  // to provide the list of references they are making into the graph. This
    12  // ensures that OpenTofu will not remove any nodes from the graph that might
    13  // not be referenced from within a module but are referenced by the currently
    14  // executing test file.
    15  //
    16  // This should only be added to the graph if we are executing the
    17  // `tofu test` command.
    18  type nodeExternalReference struct {
    19  	ExternalReferences []*addrs.Reference
    20  }
    21  
    22  var (
    23  	_ GraphNodeReferencer = (*nodeExternalReference)(nil)
    24  )
    25  
    26  // GraphNodeModulePath
    27  func (n *nodeExternalReference) ModulePath() addrs.Module {
    28  	// The external references are always made from test files, which currently
    29  	// execute as if they are in the root module.
    30  	return addrs.RootModule
    31  }
    32  
    33  // GraphNodeReferencer
    34  func (n *nodeExternalReference) References() []*addrs.Reference {
    35  	return n.ExternalReferences
    36  }