Documentation
¶
Index ¶
- Constants
- Variables
- func InitRootModule(input *RootModuleInputData, modulePath string, filePerms os.FileMode, ...) error
- func LoadModuleVariables(filePath string) (hcltmpl.Variables, error)
- func NewMainTF(w io.Writer, input *RootModuleInputData) error
- func NewModuleVariablesTF(w io.Writer, input *RootModuleInputData) error
- func NewTFVarsTmpl(w io.Writer, input *RootModuleInputData) error
- func NewVariablesTF(w io.Writer, input *RootModuleInputData) error
- func ParseModuleVariables(content []byte, filename string) (hcltmpl.Variables, error)
- type RootModuleInputData
- type Service
- type Task
Constants ¶
const ( // TerraformRequiredVersion is the version constraint pinned to the generated // root module to ensure compatibility across Sync, Terraform, and // modules. TerraformRequiredVersion = version.CompatibleTerraformVersionConstraint // RootFilename is the file name for the root module. RootFilename = "main.tf" // VarsFilename is the file name for the variable definitions in the root module VarsFilename = "variables.tf" // ModuleVarsFilename is the file name for the variable definitions corresponding // to the input variables from a user that is specific to the task's module. ModuleVarsFilename = "variables.module.tf" // TFVarsFilename is the file name for input variables for configured // Terraform providers and Consul service information. TFVarsFilename = "terraform.tfvars" // TFVarsTmplFilename is the template file for TFVarsFilename TFVarsTmplFilename = "terraform.tfvars.tmpl" )
Variables ¶
var HCLTmplFuncMap = map[string]interface{}{ "indent": tfunc.Helpers()["indent"], "subtract": tfunc.Math()["subtract"], "joinStrings": joinStringsFunc, "HCLService": hclServiceFunc, }
HCLTmplFuncMap are template functions for rendering HCL
var ( // RootPreamble is a warning message included to the beginning of the // generated root module files. RootPreamble = []byte( `# This file is generated by Consul Terraform Sync. # # The HCL blocks, arguments, variables, and values are derived from the # operator configuration for Sync. Any manual changes to this file # may not be preserved and could be overwritten by a subsequent update. `) )
var VariableServices = []byte(
`# Service definition protocol v0
variable "services" {
description = "Consul services monitored by Consul Terraform Sync"
type = map(
object({
id = string
name = string
address = string
port = number
meta = map(string)
tags = list(string)
namespace = string
status = string
node = string
node_id = string
node_address = string
node_datacenter = string
node_tagged_addresses = map(string)
node_meta = map(string)
})
)
}
`)
VariableServices is versioned to track compatibility with the generated root module with modules.
Functions ¶
func InitRootModule ¶
func InitRootModule(input *RootModuleInputData, modulePath string, filePerms os.FileMode, force bool) error
InitRootModule generates the root module and writes the following files to disk: main.tf, variables.tf
func LoadModuleVariables ¶
LoadModuleVariables loads Terraform input variables from a file.
func NewMainTF ¶
func NewMainTF(w io.Writer, input *RootModuleInputData) error
NewMainTF writes content used for main.tf of a Terraform root module.
func NewModuleVariablesTF ¶
func NewModuleVariablesTF(w io.Writer, input *RootModuleInputData) error
NewModuleVariablesTF writes content used for variables.module.tf of a Terraform root module. These variable defintions correspond to variables that are passed as arguments within the module block.
func NewTFVarsTmpl ¶
func NewTFVarsTmpl(w io.Writer, input *RootModuleInputData) error
NewTFVarsTmpl writes content to assign values to the root module's variables that is commonly placed in a .tfvars file.
func NewVariablesTF ¶
func NewVariablesTF(w io.Writer, input *RootModuleInputData) error
NewVariablesTF writes content used for variables.tf of a Terraform root module.
func ParseModuleVariables ¶
ParseModuleVariables parses bytes representing Terraform input variables for a module. It encodes the content into cty.Value types. Invalid HCL syntax and unsupported Terraform variable types result in an error.
Types ¶
type RootModuleInputData ¶
type RootModuleInputData struct { Backend map[string]interface{} Providers []hcltmpl.NamedBlock ProviderInfo map[string]interface{} Services []Service Task Task Variables hcltmpl.Variables // contains filtered or unexported fields }
RootModuleInputData is the input data used to generate the root module
func (*RootModuleInputData) Init ¶
func (d *RootModuleInputData) Init()
Init processes input data used to generate a Terraform root module. It converts the RootModuleInputData values into HCL objects compatible for Terraform configuration syntax.