Documentation
¶
Index ¶
- Constants
- Variables
- func InitRootModule(input *RootModuleInputData) error
- func LoadModuleVariables(filePath string) (hcltmpl.Variables, error)
- func ParseModuleVariables(content []byte, filename string) (hcltmpl.Variables, error)
- type CatalogServicesCondition
- type CatalogServicesMonitor
- type Condition
- type ConsulKVCondition
- type ConsulKVMonitor
- type ConsulKVSourceInput
- type Monitor
- type RootModuleInputData
- type Service
- type ServicesCondition
- type ServicesMonitor
- type ServicesSourceInput
- type SourceInput
- 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. 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 ¶
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 ` )
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 ¶
LoadModuleVariables loads Terraform input variables from a file.
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 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
func (CatalogServicesMonitor) SourceIncludesVariable ¶ added in v0.4.0
func (m CatalogServicesMonitor) SourceIncludesVariable() bool
SourceIncludesVariable returns true if the source variables are to be included in the template. For the case of a catalog-service monitor, this always returns true and must be overridden to return based on other conditions.
type Condition ¶ added in v0.2.0
type Condition interface { Monitor }
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
ConsulKVMonitor handles appending templating for the consul-kv run monitor
func (ConsulKVMonitor) ServicesAppended ¶ added in v0.4.0
func (m ConsulKVMonitor) ServicesAppended() bool
ServicesAppended always returns false for consul-kv as it doesn't deal with services
func (ConsulKVMonitor) SourceIncludesVariable ¶ added in v0.4.0
func (m ConsulKVMonitor) SourceIncludesVariable() bool
SourceIncludesVariable returns true if the source variables are to be included in the template. For the case of a consul-kv monitor, this always returns true and must be overridden to return based on other conditions.
type ConsulKVSourceInput ¶ added in v0.4.0
type ConsulKVSourceInput struct {
ConsulKVMonitor
}
ConsulKVSourceInput handles appending a run source variable's relevant templating for Terraform generated files
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 // SourceIncludesVariable returns if the module source expects to // include the monitor variable. SourceIncludesVariable() 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
func (ServicesMonitor) SourceIncludesVariable ¶ added in v0.4.0
func (m ServicesMonitor) SourceIncludesVariable() bool
SourceIncludesVariable returns true if the source variables are to be included in the template. For the case of a service monitor, this always returns true and must be overridden to return based on other conditions.
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