codegen

package
v0.99.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package codegen contains routines for generating terraform code

Index

Constants

View Source
const (
	// A comment that is added to the top of the generated file to indicate that this file was generated by Terragrunt.
	// We use a hardcoded random string at the end to make the string further unique.
	TerragruntGeneratedSignature = "Generated by Terragrunt. Sig: nIlQXj57tbuaRZEa"

	// The default prefix to use for comments in the generated file
	DefaultCommentPrefix = "# "
)
View Source
const (
	ExistsErrorStr               = "error"
	ExistsSkipStr                = "skip"
	ExistsOverwriteStr           = "overwrite"
	ExistsOverwriteTerragruntStr = "overwrite_terragrunt"

	DisabledSkipStr             = "skip"
	DisabledRemoveStr           = "remove"
	DisabledRemoveTerragruntStr = "remove_terragrunt"

	EncryptionKeyProviderKey = "key_provider"
)

Variables

This section is empty.

Functions

func RemoteStateConfigToTerraformCode

func RemoteStateConfigToTerraformCode(backend string, config map[string]any, encryption map[string]any) ([]byte, error)

RemoteStateConfigToTerraformCode converts the arbitrary map that represents a remote state config into HCL code to configure that remote state.

func ReplaceAllCommasOutsideQuotesWithNewLines

func ReplaceAllCommasOutsideQuotesWithNewLines(s string) string

ReplaceAllCommasOutsideQuotesWithNewLines replaces all commas outside quotes with new lines. This is useful for instances where a single line of HCL content might contain a comma, and we don't want to split the line into multiple lines.

func WriteToFile

func WriteToFile(l log.Logger, opts *options.TerragruntOptions, basePath string, config *GenerateConfig) error

WriteToFile will generate a new file at the given target path with the given contents. If a file already exists at the target path, the behavior depends on the value of IfExists: - if ExistsError, return an error. - if ExistsSkip, do nothing and return - if ExistsOverwrite, overwrite the existing file

Types

type GenerateConfig

type GenerateConfig struct {
	HclFmt           *bool  `cty:"hcl_fmt"`
	Path             string `cty:"path"`
	IfExistsStr      string `cty:"if_exists"`
	IfDisabledStr    string `cty:"if_disabled"`
	CommentPrefix    string `cty:"comment_prefix"`
	Contents         string `cty:"contents"`
	IfExists         GenerateConfigExists
	IfDisabled       GenerateConfigDisabled
	DisableSignature bool `cty:"disable_signature"`
	Disable          bool `cty:"disable"`
}

GenerateConfig is configuration for generating code

type GenerateConfigDisabled

type GenerateConfigDisabled int

GenerateConfigDisabled is an enum to represent valid values for if_disabled.

const (
	DisabledSkip GenerateConfigDisabled = iota
	DisabledRemove
	DisabledRemoveTerragrunt
	DisabledUnknown
)

func GenerateConfigDisabledFromString

func GenerateConfigDisabledFromString(val string) (GenerateConfigDisabled, error)

GenerateConfigDisabledFromString converts a string representation of if_disabled into the enum, returning an error if it is not set to one of the known values.

type GenerateConfigExists

type GenerateConfigExists int

GenerateConfigExists is an enum to represent valid values for if_exists.

const (
	ExistsError GenerateConfigExists = iota
	ExistsSkip
	ExistsOverwrite
	ExistsOverwriteTerragrunt
	ExistsUnknown
)

func GenerateConfigExistsFromString

func GenerateConfigExistsFromString(val string) (GenerateConfigExists, error)

GenerateConfigExistsFromString converts a string representation of if_exists into the enum, returning an error if it is not set to one of the known values.

type GenerateFileExistsError

type GenerateFileExistsError struct {
	// contains filtered or unexported fields
}

func (GenerateFileExistsError) Error

func (err GenerateFileExistsError) Error() string

type GenerateFileRemoveError

type GenerateFileRemoveError struct {
	// contains filtered or unexported fields
}

func (GenerateFileRemoveError) Error

func (err GenerateFileRemoveError) Error() string

type UnknownGenerateIfDisabledVal

type UnknownGenerateIfDisabledVal struct {
	// contains filtered or unexported fields
}

func (UnknownGenerateIfDisabledVal) Error

type UnknownGenerateIfExistsVal

type UnknownGenerateIfExistsVal struct {
	// contains filtered or unexported fields
}

func (UnknownGenerateIfExistsVal) Error

func (err UnknownGenerateIfExistsVal) Error() string

Jump to

Keyboard shortcuts

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