tftmpl

package
v0.1.0-techpreview2 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2020 License: MPL-2.0 Imports: 19 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
	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

View Source
var HCLTmplFuncMap = map[string]interface{}{
	"indent":   tfunc.Helpers()["indent"],
	"subtract": tfunc.Math()["subtract"],

	"joinStrings": joinStringsFunc,
	"HCLService":  hclServiceFunc,
}

HCLTmplFuncMap are template functions for rendering HCL

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.

`)
)
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
      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

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

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

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 {
	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 {
	Datacenter  string
	Description string
	Name        string
	Namespace   string
	Tag         string
}

func (Service) TemplateServiceID

func (s Service) TemplateServiceID() string

TODO incorporate namespace

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