terragen

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2023 License: MIT Imports: 7 Imported by: 0

README

terragen

Terragen is library and (eventually) tools for generating code in the Terraform / Terragrunt ecosystem.

Need to have a bunch of repetitive files for Terragrunt configurations? Don't want to maintain all of them? Terragen lets you define them in one place, using the same familiar HCL syntax, then generates the actual files for you.

Example Terragen configuration file:

terragrunt_configuration "test" {
  source = "mymodule"
  destination_path = "path/to/test/terragrunt.hcl"
  include "something" {
    path = "hello"
  }
}

terragrunt_include_all "all" {
  path = "world"
}

Using the terragen.GenerateFromFile function, you would get a file at the path path/to/test/terragrunt.hcl that looked like this:

terraform {
  source = "mymodule"
}

include "something" {
  path = "hello"
}
include "all" {
  path = "world"
}

Right now, Terragen supports a very limited set of syntax for generating minimal Terragrunt configuration files. The goal is to expand on this feature set, to eventually include things like:

  • Support more complete Terragrunt configuration syntax, such as locals, dependencies, etc.
  • Support generating Terraform files.
  • Fetch file contents from remote sources, using something like go-getter.
  • Include a CLI that will perform the generation for you.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeFromFile

func DecodeFromFile(filename string, out interface{}) error

func GenerateFromFile

func GenerateFromFile(configurationsFilePath string) error

Types

type ConfigurationsFile added in v0.2.0

type ConfigurationsFile struct {
	// These are used for generating Terragrunt root files.
	TerragruntConfigurations []TerragruntConfiguration `hcl:"terragrunt_configuration,block"`
	// These `include` blocks will be present in all generated files.
	TerragruntIncludeAlls []terragrunt.IncludeConfig `hcl:"terragrunt_include_all,block"`
}

ConfigurationsFile represents a file containing a set of configurations.

type Generator

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

func NewGenerator

func NewGenerator(optFns ...GeneratorOptsFn) (*Generator, error)

func (*Generator) DecodeFromFile

func (g *Generator) DecodeFromFile(filename string, out interface{}) error

func (*Generator) GenerateFromConfig added in v0.3.0

func (g *Generator) GenerateFromConfig(config *ConfigurationsFile) error

func (*Generator) GenerateFromFile

func (g *Generator) GenerateFromFile(configurationsFilePath string) error

type GeneratorOptsFn

type GeneratorOptsFn func(*Generator) error

func WithFs

func WithFs(fs afero.Fs) GeneratorOptsFn

WithFs sets the file system for the Generator.

type TerragruntConfiguration added in v0.2.0

type TerragruntConfiguration struct {
	Name string `hcl:"name,label"`
	// Source is the value passed for the `terraform` block's `source` attribute.
	Source string `hcl:"source,attr"`
	// DestinationPath is the path at which the file should be generated.
	DestinationPath string `hcl:"destination_path,attr"`
	// Includes is used to generate an `includes` block in the generated file.
	Includes []terragrunt.IncludeConfig `hcl:"include,block"`
}

TerragruntConfiguration represents the information required for the generation of a Terragrunt configuration.

Directories

Path Synopsis
internal
terragrunt
Package Terragrunt defines the structures of generated Terragrunt configuration files.
Package Terragrunt defines the structures of generated Terragrunt configuration files.

Jump to

Keyboard shortcuts

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