github.com/iaas-resource-provision/iaas-rpc@v1.0.7-0.20211021023331-ed21f798c408/internal/terraform/transform_variable.go (about)

     1  package terraform
     2  
     3  import (
     4  	"github.com/iaas-resource-provision/iaas-rpc/internal/addrs"
     5  	"github.com/iaas-resource-provision/iaas-rpc/internal/configs"
     6  )
     7  
     8  // RootVariableTransformer is a GraphTransformer that adds all the root
     9  // variables to the graph.
    10  //
    11  // Root variables are currently no-ops but they must be added to the
    12  // graph since downstream things that depend on them must be able to
    13  // reach them.
    14  type RootVariableTransformer struct {
    15  	Config *configs.Config
    16  }
    17  
    18  func (t *RootVariableTransformer) Transform(g *Graph) error {
    19  	// We can have no variables if we have no config.
    20  	if t.Config == nil {
    21  		return nil
    22  	}
    23  
    24  	// We're only considering root module variables here, since child
    25  	// module variables are handled by ModuleVariableTransformer.
    26  	vars := t.Config.Module.Variables
    27  
    28  	// Add all variables here
    29  	for _, v := range vars {
    30  		node := &NodeRootVariable{
    31  			Addr: addrs.InputVariable{
    32  				Name: v.Name,
    33  			},
    34  			Config: v,
    35  		}
    36  		g.Add(node)
    37  	}
    38  
    39  	return nil
    40  }