terraform

package
v0.0.0-...-491fdb2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: Apache-2.0 Imports: 10 Imported by: 3

Documentation

Overview

Package terraform provides helpers for working with Terraform.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(config *Config, dir string, opts *Options, rn runner.Runner) error

Apply applies the config. The config will be written as a .tf.json file in the given dir. All imports in opts.Imports will be imported prior being applied. Thus, if a resource exists it will be imported to the terraform state. Without importing an existing resource terraform can fail with an "ALREADY EXISTS" error when it tries to create it.

func WorkDir

func WorkDir(base string, subdirs ...string) (string, error)

WorkDir creates and returns the directory path to run the current terraform commands.

Types

type ActionFunc

type ActionFunc func(dir string, rn runner.Runner) error

ActionFunc are functions that can implement extra actions to run on existing Terraform deployments.

type Backend

type Backend struct {
	Bucket string `json:"bucket"`
	Prefix string `json:"prefix,omitempty"`
}

Backend provides a terraform backend config. See https://www.terraform.io/docs/backends/types/gcs.html.

func (*Backend) MarshalJSON

func (b *Backend) MarshalJSON() ([]byte, error)

MarshalJSON implements a custom marshaller which marshals the backend under a "gcs" block.

type Config

type Config struct {
	Providers []*Provider `json:"provider,omitempty"`
	Terraform *Terraform  `json:"terraform,omitempty"`
	Data      []*Resource `json:"data,omitempty"`
	Modules   []*Module   `json:"module,omitempty"`
	Resources []*Resource `json:"resource,omitempty"`
	Outputs   []*Output   `json:"output,omitempty"`
}

Config represents a Terraform config. See https://www.terraform.io/docs/configuration/syntax-json.html for documentation. Note: Terraform resources and modules are keyed Type+ID. So google_storage_bucket.foo and google_bigquery_dataset.foo are acceptable in the same config.

func NewConfig

func NewConfig() *Config

NewConfig returns a new terraform config.

type Import

type Import struct {
	Address string
	ID      string
}

Import defines fields used for a terraform import. See https://www.terraform.io/docs/import/usage.html.

type Module

type Module struct {
	Name       string      `json:"-"`
	Source     string      `json:"source"`
	Properties interface{} `json:"-"`
}

Module provides a terraform module config. See https://www.terraform.io/docs/configuration/modules.html for details.

func (*Module) MarshalJSON

func (m *Module) MarshalJSON() ([]byte, error)

MarshalJSON implements a custom marshaller which marshals properties to the top level.

type Options

type Options struct {
	Imports      []Import
	CustomConfig map[string]interface{}
	ApplyFlags   []string
	ExtraActions []ActionFunc
}

Options configure a terraform apply call.

type Output

type Output struct {
	Name  string
	Value string
}

Output provides a terraform output config. See https://www.terraform.io/docs/configuration/outputs.html.

func (*Output) MarshalJSON

func (o *Output) MarshalJSON() ([]byte, error)

MarshalJSON implements a custom marshaller which marshals value to be under name.

type Provider

type Provider struct {
	Name       string
	Properties map[string]interface{}
}

Provider provides a terraform provider config.

func (*Provider) MarshalJSON

func (p *Provider) MarshalJSON() ([]byte, error)

MarshalJSON implements a custom marshaller which marshals properties to be under name.

type Resource

type Resource struct {
	Name       string      `json:"name"`
	Type       string      `json:"type"`
	Properties interface{} `json:"properties"`
}

Resource defines a terraform resource config.

Dependencies can be created between resources using terraform references. See https://www.terraform.io/docs/configuration/resources.html#resource-dependencies.

Meta-arguments are also supported. See https://www.terraform.io/docs/configuration/resources.html#meta-arguments This is especially useful when wanting to create multiple resources that share a common set of fields, such as IAM members of a data resource (e.g. storage_bucket_iam_member). Instead of creating a separate config for each IAM member, a single IAM member using a meta-argument like for_each or count can be expanded by terraform to deploy all IAM members of a resource.

func (*Resource) MarshalJSON

func (r *Resource) MarshalJSON() ([]byte, error)

MarshalJSON implements a custom marshaller which marshals the resource to have the following hierarchy: type - name - properties.

type Terraform

type Terraform struct {
	RequiredVersion string   `json:"required_version,omitempty"`
	Backend         *Backend `json:"backend,omitempty"`
}

Terraform provides a terraform block config. See https://www.terraform.io/docs/configuration/terraform.html for details.

Jump to

Keyboard shortcuts

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