tftmpl

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2021 License: MPL-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
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. This includes the required services variable and generated
	// provider variables based on CTS user configuration for the task.
	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 where the required Consul services input
	// variable is written to.
	TFVarsFilename = "terraform.tfvars"

	// TFVarsTmplFilename is the template file for TFVarsFilename. This is used
	// by hcat for monitoring service changes from Consul.
	TFVarsTmplFilename = "terraform.tfvars.tmpl"

	// ProviderTFVarsFilename is the file name for input variables for
	// configured Terraform providers. Generated provider input variables are
	// written in a separate file from terraform.tfvars because it may contain
	// sensitive or secret values.
	ProvidersTFVarsFilename = "providers.tfvars"
)

Variables

View Source
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.
#
`)

	// TaskPreamble is the base format for task information included at the
	// beginning of generated module files.
	TaskPreamble = `# Task: %s
# Description: %s

`
)
View Source
var VariableServices = []byte(
	`# Service definition protocol v0
variable "services" {
  description = "Consul services monitored by Consul Terraform Sync"
  type = map(
    object({
      id        = string
      name      = string
      kind      = 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)

      cts_user_defined_meta = map(string)
    })
  )
}
`)

VariableServices is versioned to track compatibility with the generated root module with modules.

Functions

func HCLTmplFuncMap

func HCLTmplFuncMap(meta map[string]map[string]string) template.FuncMap

HCLTmplFuncMap is the map of template functions for rendering HCL to their respective implementations

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

func LoadModuleVariables(filePath string) (hcltmpl.Variables, error)

LoadModuleVariables loads Terraform input variables from a file.

func ParseModuleVariables

func ParseModuleVariables(content []byte, filename string) (hcltmpl.Variables, error)

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 {
	TerraformVersion *goVersion.Version
	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.

type Service

type Service struct {
	// Consul service information
	Datacenter  string
	Description string
	Name        string
	Namespace   string
	Tag         string

	// CTSUserDefinedMeta is user defined metadata that is configured by
	// operators for CTS to append to Consul service information to be used for
	// network infrastructure automation.
	CTSUserDefinedMeta map[string]string
}

type Task

type Task struct {
	Description string
	Name        string
	Source      string
	Version     string
}

Task contains information for a Sync task. The Terraform driver interprets task values for determining the Terraform module.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL