terraform

package
Version: v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: MIT Imports: 17 Imported by: 1

Documentation

Overview

Package terraform is the representation of a Terraform Module.

It contains:

• Header: Module header found in shape of multi line '*.tf' comments or an entire file

• Footer: Module footer found in shape of multi line '*.tf' comments or an entire file

• Inputs: List of input 'variables' extracted from the Terraform module .tf files

• ModuleCalls: List of 'modules' extracted from the Terraform module .tf files

• Outputs: List of 'outputs' extracted from Terraform module .tf files

• Providers: List of 'providers' extracted from resources used in Terraform module

• Requirements: List of 'requirements' extracted from the Terraform module .tf files

• Resources: List of 'resources' extracted from the Terraform module .tf files

Usage

options := &terraform.Options{
    Path:           "./examples",
    ShowHeader:     true,
    HeaderFromFile: "main.tf",
    ShowFooter:     true,
    FooterFromFile: "footer.md",
    SortBy: &terraform.SortBy{
        Name: true,
    },
    ReadComments: true,
}

tfmodule, err := terraform.LoadWithOptions(options)
if err != nil {
    log.Fatal(err)
}

...

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Input

type Input struct {
	Name        string       `json:"name" toml:"name" xml:"name" yaml:"name"`
	Type        types.String `json:"type" toml:"type" xml:"type" yaml:"type"`
	Description types.String `json:"description" toml:"description" xml:"description" yaml:"description"`
	Default     types.Value  `json:"default" toml:"default" xml:"default" yaml:"default"`
	Required    bool         `json:"required" toml:"required" xml:"required" yaml:"required"`
	Position    Position     `json:"-" toml:"-" xml:"-" yaml:"-"`
}

Input represents a Terraform input.

func (*Input) GetValue

func (i *Input) GetValue() string

GetValue returns JSON representation of the 'Default' value, which is an 'interface'. If 'Default' is a primitive type, the primitive value of 'Default' will be returned and not the JSON formatted of it.

func (*Input) HasDefault

func (i *Input) HasDefault() bool

HasDefault indicates if a Terraform variable has a default value set.

type Module

type Module struct {
	XMLName xml.Name `json:"-" toml:"-" xml:"module" yaml:"-"`

	Header       string         `json:"header" toml:"header" xml:"header" yaml:"header"`
	Footer       string         `json:"footer" toml:"footer" xml:"footer" yaml:"footer"`
	Inputs       []*Input       `json:"inputs" toml:"inputs" xml:"inputs>input" yaml:"inputs"`
	ModuleCalls  []*ModuleCall  `json:"modules" toml:"modules" xml:"modules>module" yaml:"modules"`
	Outputs      []*Output      `json:"outputs" toml:"outputs" xml:"outputs>output" yaml:"outputs"`
	Providers    []*Provider    `json:"providers" toml:"providers" xml:"providers>provider" yaml:"providers"`
	Requirements []*Requirement `json:"requirements" toml:"requirements" xml:"requirements>requirement" yaml:"requirements"`
	Resources    []*Resource    `json:"resources" toml:"resources" xml:"resources>resource" yaml:"resources"`

	RequiredInputs []*Input `json:"-" toml:"-" xml:"-" yaml:"-"`
	OptionalInputs []*Input `json:"-" toml:"-" xml:"-" yaml:"-"`
}

Module represents a Terraform module. It consists of

func LoadWithOptions

func LoadWithOptions(config *print.Config) (*Module, error)

LoadWithOptions returns new instance of Module with all the inputs and outputs discovered from provided 'path' containing Terraform config

func (*Module) HasFooter

func (m *Module) HasFooter() bool

HasFooter indicates if the module has footer.

func (*Module) HasHeader

func (m *Module) HasHeader() bool

HasHeader indicates if the module has header.

func (*Module) HasInputs

func (m *Module) HasInputs() bool

HasInputs indicates if the module has inputs.

func (*Module) HasModuleCalls

func (m *Module) HasModuleCalls() bool

HasModuleCalls indicates if the module has modulecalls.

func (*Module) HasOutputs

func (m *Module) HasOutputs() bool

HasOutputs indicates if the module has outputs.

func (*Module) HasProviders

func (m *Module) HasProviders() bool

HasProviders indicates if the module has providers.

func (*Module) HasRequirements

func (m *Module) HasRequirements() bool

HasRequirements indicates if the module has requirements.

func (*Module) HasResources

func (m *Module) HasResources() bool

HasResources indicates if the module has resources.

type ModuleCall

type ModuleCall struct {
	Name        string       `json:"name" toml:"name" xml:"name" yaml:"name"`
	Source      string       `json:"source" toml:"source" xml:"source" yaml:"source"`
	Version     string       `json:"version" toml:"version" xml:"version" yaml:"version"`
	Description types.String `json:"description" toml:"description" xml:"description" yaml:"description"`
	Position    Position     `json:"-" toml:"-" xml:"-" yaml:"-"`
}

ModuleCall represents a submodule called by Terraform module.

func (*ModuleCall) FullName

func (mc *ModuleCall) FullName() string

FullName returns full name of the modulecall, with version if available

type Output

type Output struct {
	Name        string       `json:"name" toml:"name" xml:"name" yaml:"name"`
	Description types.String `json:"description" toml:"description" xml:"description" yaml:"description"`
	Value       types.Value  `json:"value,omitempty" toml:"value,omitempty" xml:"value,omitempty" yaml:"value,omitempty"`
	Sensitive   bool         `json:"sensitive,omitempty" toml:"sensitive,omitempty" xml:"sensitive,omitempty" yaml:"sensitive,omitempty"`
	Position    Position     `json:"-" toml:"-" xml:"-" yaml:"-"`
	ShowValue   bool         `json:"-" toml:"-" xml:"-" yaml:"-"`
}

Output represents a Terraform output.

func (*Output) GetValue

func (o *Output) GetValue() string

GetValue returns JSON representation of the 'Value', which is an 'interface'. If 'Value' is a primitive type, the primitive value of 'Value' will be returned and not the JSON formatted of it.

func (*Output) HasDefault

func (o *Output) HasDefault() bool

HasDefault indicates if a Terraform output has a default value set.

func (*Output) MarshalJSON

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

MarshalJSON custom yaml marshal function to take '--output-values' flag into consideration. It means if the flag is not set Value and Sensitive fields are set to 'omitempty', otherwise if output values are being shown 'omitempty' gets explicitly removed to show even empty and false values.

func (*Output) MarshalXML

func (o *Output) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML custom xml marshal function to take '--output-values' flag into consideration. It means if the flag is not set Value and Sensitive fields are set to 'omitempty', otherwise if output values are being shown 'omitempty' gets explicitly removed to show even empty and false values.

func (*Output) MarshalYAML

func (o *Output) MarshalYAML() (interface{}, error)

MarshalYAML custom yaml marshal function to take '--output-values' flag into consideration. It means if the flag is not set Value and Sensitive fields are set to 'omitempty', otherwise if output values are being shown 'omitempty' gets explicitly removed to show even empty and false values.

type Position

type Position struct {
	Filename string `json:"-" toml:"-" xml:"-" yaml:"-"`
	Line     int    `json:"-" toml:"-" xml:"-" yaml:"-"`
}

Position represents position of Terraform item (input, output, provider, etc) in a file.

type Provider

type Provider struct {
	Name     string       `json:"name" toml:"name" xml:"name" yaml:"name"`
	Alias    types.String `json:"alias" toml:"alias" xml:"alias" yaml:"alias"`
	Version  types.String `json:"version" toml:"version" xml:"version" yaml:"version"`
	Position Position     `json:"-" toml:"-" xml:"-" yaml:"-"`
}

Provider represents a Terraform output.

func (*Provider) FullName

func (p *Provider) FullName() string

FullName returns full name of the provider, with alias if available

type Requirement

type Requirement struct {
	Name    string       `json:"name" toml:"name" xml:"name" yaml:"name"`
	Version types.String `json:"version" toml:"version" xml:"version" yaml:"version"`
}

Requirement represents a requirement for Terraform module.

type Resource

type Resource struct {
	Type           string       `json:"type" toml:"type" xml:"type" yaml:"type"`
	Name           string       `json:"name" toml:"name" xml:"name" yaml:"name"`
	ProviderName   string       `json:"provider" toml:"provider" xml:"provider" yaml:"provider"`
	ProviderSource string       `json:"source" toml:"source" xml:"source" yaml:"source"`
	Mode           string       `json:"mode" toml:"mode" xml:"mode" yaml:"mode"`
	Version        types.String `json:"version" toml:"version" xml:"version" yaml:"version"`
	Description    types.String `json:"description" toml:"description" xml:"description" yaml:"description"`
	Position       Position     `json:"-" toml:"-" xml:"-" yaml:"-"`
}

Resource represents a managed or data type that is created by the module

func (*Resource) GetMode

func (r *Resource) GetMode() string

GetMode returns normalized resource type as "resource" or "data source"

func (*Resource) Spec

func (r *Resource) Spec() string

Spec returns the resource spec addresses a specific resource in the config. It takes the form: resource_type.resource_name[resource index] For more details, see: https://www.terraform.io/docs/cli/state/resource-addressing.html#resource-spec

func (*Resource) URL

func (r *Resource) URL() string

URL returns a best guess at the URL for resource documentation

Jump to

Keyboard shortcuts

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