tftmpl

package
v0.4.0-beta1 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2021 License: MPL-2.0 Imports: 17 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 InitRootModule

func InitRootModule(input *RootModuleInputData) error

InitRootModule generates the root module and writes the following files to disk.

always: main.tf, variables.tf, terraform.tfvars.tmpl

conditionally: variables.module.tf, providers.tfvars

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 CatalogServicesCondition added in v0.2.0

type CatalogServicesCondition struct {
	CatalogServicesMonitor
	SourceIncludesVar bool
}

CatalogServicesCondition handles appending templating for the catalog-service run condition

func (CatalogServicesCondition) SourceIncludesVariable added in v0.2.0

func (c CatalogServicesCondition) SourceIncludesVariable() bool

SourceIncludesVariable returns true if the variables are to be included and false otherwise

type CatalogServicesMonitor added in v0.4.0

type CatalogServicesMonitor struct {
	Regexp     string
	Datacenter string
	Namespace  string
	NodeMeta   map[string]string
}

CatalogServicesMonitor handles appending templating for the catalog-service run monitor

func (CatalogServicesMonitor) ServicesAppended added in v0.4.0

func (m CatalogServicesMonitor) ServicesAppended() bool

ServicesAppended returns true if the services are to be appended, and false otherwise

type Condition added in v0.2.0

type Condition interface {
	Monitor

	// SourceIncludesVariable returns if the module source expects to
	// include the monitor variable.
	SourceIncludesVariable() bool
}

Condition handles appending a run condition's relevant templating for Terraform generated files

type ConsulKVCondition added in v0.4.0

type ConsulKVCondition struct {
	ConsulKVMonitor
	SourceIncludesVar bool
}

ConsulKVCondition handles appending templating for the consul-kv run condition

func (ConsulKVCondition) SourceIncludesVariable added in v0.4.0

func (c ConsulKVCondition) SourceIncludesVariable() bool

SourceIncludesVariable returns true if the variables are to be included and false otherwise

type ConsulKVMonitor added in v0.4.0

type ConsulKVMonitor struct {
	Path       string
	Recurse    bool
	Datacenter string
	Namespace  string
}

ConsulKVMonitor handles appending templating for the consul-kv run monitor

func (ConsulKVMonitor) ServicesAppended added in v0.4.0

func (m ConsulKVMonitor) ServicesAppended() bool

type Monitor added in v0.4.0

type Monitor interface {
	// ServicesAppended returns if the services variable has been appended
	// to the template content.
	ServicesAppended() bool
	// contains filtered or unexported methods
}

Monitor handles appending a run monitor's relevant templating for Terraform generated files

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
	Condition        Condition
	SourceInput      SourceInput

	Path      string
	FilePerms os.FileMode
	// contains filtered or unexported fields
}

RootModuleInputData is the input data used to generate the root module

type Service

type Service struct {
	// Consul service information
	Datacenter  string
	Description string
	Name        string
	Namespace   string
	Filter      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 ServicesCondition added in v0.2.0

type ServicesCondition struct {
	ServicesMonitor
	SourceIncludesVar bool
}

ServicesCondition handles appending templating for the services run condition This is the default run condition

func (ServicesCondition) SourceIncludesVariable added in v0.2.0

func (c ServicesCondition) SourceIncludesVariable() bool

SourceIncludesVariable returns true if the variables are to be included and false otherwise

type ServicesMonitor added in v0.4.0

type ServicesMonitor struct {
	Regexp string
}

ServicesMonitor handles appending templating for the services run monitor

func (ServicesMonitor) ServicesAppended added in v0.4.0

func (m ServicesMonitor) ServicesAppended() bool

ServicesAppended returns true if the services are to be appended and false otherwise

type ServicesSourceInput added in v0.4.0

type ServicesSourceInput struct {
	ServicesMonitor
}

ServicesSourceInput handles appending a run source variable's relevant templating for Terraform generated files

type SourceInput added in v0.4.0

type SourceInput interface {
	Monitor
}

SourceInput handles appending a run source input's relevant templating for Terraform generated files

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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