tfwrite

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitTokensAsList

func SplitTokensAsList(tokens hclwrite.Tokens) []hclwrite.Tokens

SplitTokensAsList parses tokens of a given list and splits it as a list of tokens. `["foo", "bar"]` => [`"foo"`, `"bar"`] Returns nil if the input cannot be parsed as a list.

Types

type Attribute

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

Attribute is an attribute of resource.

func NewAttribute

func NewAttribute(attr *hclwrite.Attribute) *Attribute

NewAttribute creates a new instance of Attribute.

func (*Attribute) References added in v0.2.1

func (a *Attribute) References() []string

References returns all variable references contained in the value. It returns a unique and sorted list.

func (*Attribute) RenameReference added in v0.2.1

func (a *Attribute) RenameReference(from string, to string)

RenameReference renames all variable references contained in the value. The `from` and `to` arguments are specified as dot-delimited resource addresses. The `from` argument can be a partial prefix match, but must match the length of the `to` argument.

func (*Attribute) ValueAsString

func (a *Attribute) ValueAsString() (string, error)

ValueAsString returns a value of Attribute as string.

func (*Attribute) ValueAsTokens

func (a *Attribute) ValueAsTokens() hclwrite.Tokens

ValueAsTokens returns a value of Attribute as raw tokens.

type Block

type Block interface {
	// Raw returns a raw block instance of hclwrite.
	// It should keep it private if possible, but it's required for some
	// operations.
	Raw() *hclwrite.Block

	// Type returns a type of block.
	Type() string

	// SchemaType returns the first label of block.
	// If it does not have a label, return an empty string.
	// Note that it's not the same as the *hclwrite.Block.Type().
	SchemaType() string

	// SetType updates the type name of the block to a given name.
	SetType(typeName string)

	// Attributes returns all attributes.
	// Note that this does not return attributes in nested blocks.
	Attributes() []*Attribute

	// GetAttribute returns an attribute for a given name.
	GetAttribute(name string) *Attribute

	// SetAttributeValue sets an attribute for a given name with value.
	SetAttributeValue(name string, value cty.Value)

	// SetAttributeRaw sets an attribute for a given name with raw tokens.
	SetAttributeRaw(name string, tokens hclwrite.Tokens)

	// AppendAttribute appends a given attribute to the block.
	AppendAttribute(attr *Attribute)

	// RemoveAttribute removes an attribute for a given name from the block.
	RemoveAttribute(name string)

	// CopyAttribute is a helper method which copies an attribute from a given block.
	// Do nothing if the given block doesn't have the attribute.
	CopyAttribute(from Block, name string)

	// NestedBlocks returns all nested blocks.
	NestedBlocks() []*NestedBlock

	// AppendNestedBlock appends a given nested block to the parent block.
	AppendNestedBlock(nestedBlock Block)

	// AppendUnwrappedNestedBlockBody appends a body of a given block to
	// the parent block. It looks a weird operation, but it's often needed for
	// refactoring like splitting a resource type for sub resource types.
	AppendUnwrappedNestedBlockBody(nestedBlock Block)

	// RemoveNestedBlock removes a given nested block from the parent block.
	RemoveNestedBlock(nestedBlock Block)

	// FindNestedBlocksByType returns all matching blocks from the body that have
	// the given block type or returns an empty list if not found.
	FindNestedBlocksByType(blockType string) []Block

	// VerticalFormat formats a body of the block in vertical. Since
	// VerticalFormat clears tokens internally, If you call VerticalFormat each
	// time RemoveNestedBlock is called, the subsequent RemoveNestedBlock will not
	// work properly, so call VerticalFormat only once for each block.
	VerticalFormat()

	// References returns all variable references for all attributes.
	// It returns a unique and sorted list.
	References() []string

	// RenameReference renames all variable references for all attributes.
	// The `from` and `to` arguments are specified as dot-delimited resource addresses.
	// The `from` argument can be a partial prefix match, but must match the length
	// of the `to` argument.
	RenameReference(from string, to string)
}

Block represents an abstract HCL block.

type DataSource added in v0.2.0

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

DataSource represents a data block. It implements the Block interface.

func NewDataSource added in v0.2.0

func NewDataSource(block *hclwrite.Block) *DataSource

NewDataSource creates a new instance of DataSource.

func NewEmptyDataSource added in v0.2.0

func NewEmptyDataSource(dataSourceType string, dataSourceName string) *DataSource

NewEmptyDataSource creates a new DataSource with an empty body.

func (DataSource) AppendAttribute added in v0.2.0

func (b DataSource) AppendAttribute(attr *Attribute)

AppendAttribute appends a given attribute to the block.

func (DataSource) AppendNestedBlock added in v0.2.0

func (b DataSource) AppendNestedBlock(nestedBlock Block)

AppendNestedBlock appends a given nested block to the parent block.

func (DataSource) AppendUnwrappedNestedBlockBody added in v0.2.0

func (b DataSource) AppendUnwrappedNestedBlockBody(nestedBlock Block)

AppendUnwrappedNestedBlockBody appends a body of a given block to the parent block. It looks a weird operation, but it's often needed for refactoring like splitting a resource type for sub resource types.

func (DataSource) Attributes added in v0.2.1

func (b DataSource) Attributes() []*Attribute

Attributes returns all attributes. Note that this does not return attributes in nested blocks.

func (DataSource) CopyAttribute added in v0.2.0

func (b DataSource) CopyAttribute(from Block, name string)

CopyAttribute is a helper method which copies an attribute from a given block. Do nothing if the given block doesn't have the attribute.

func (*DataSource) Count added in v0.2.0

func (r *DataSource) Count() *Attribute

Count returns a meta argument of count. It returns nil if not found.

func (DataSource) FindNestedBlocksByType added in v0.2.0

func (b DataSource) FindNestedBlocksByType(blockType string) []Block

FindNestedBlocksByType returns all matching blocks from the body that have the given block type or returns an empty list if not found.

func (*DataSource) ForEach added in v0.2.0

func (r *DataSource) ForEach() *Attribute

ForEach returns a meta argument of for_each. It returns nil if not found.

func (DataSource) GetAttribute added in v0.2.0

func (b DataSource) GetAttribute(name string) *Attribute

GetAttribute returns an attribute for a given name.

func (*DataSource) Name added in v0.2.0

func (r *DataSource) Name() string

Name returns a name of data source. It returns the second label of block.

func (DataSource) NestedBlocks added in v0.2.1

func (b DataSource) NestedBlocks() []*NestedBlock

NestedBlocks returns all nested blocks.

func (DataSource) Raw added in v0.2.0

func (b DataSource) Raw() *hclwrite.Block

Raw returns a raw block instance of hclwrite. It should keep it private if possible, but it's required for some operations.

func (*DataSource) ReferableName added in v0.2.0

func (r *DataSource) ReferableName() string

ReferableName returns a name of data source instance which can be referenced as a part of address. It contains an index reference if count or for_each is set. If neither count nor for_each is set, it just returns the name.

func (DataSource) References added in v0.2.1

func (b DataSource) References() []string

References returns all variable references for all attributes. It returns a unique and sorted list.

func (DataSource) RemoveAttribute added in v0.2.0

func (b DataSource) RemoveAttribute(name string)

RemoveAttribute removes an attribute for a given name from the block.

func (DataSource) RemoveNestedBlock added in v0.2.0

func (b DataSource) RemoveNestedBlock(nestedBlock Block)

RemoveNestedBlock removes a given nested block from the parent block.

func (DataSource) RenameReference added in v0.2.1

func (b DataSource) RenameReference(from string, to string)

RenameReference renames all variable references for all attributes. The `from` and `to` arguments are specified as dot-delimited resource addresses. The `from` argument can be a partial prefix match, but must match the length of the `to` argument.

func (DataSource) SchemaType added in v0.2.0

func (b DataSource) SchemaType() string

SchemaType returns the first label of block. If it does not have a label, return an empty string. Note that it's not the same as the *hclwrite.Block.Type().

func (DataSource) SetAttributeRaw added in v0.2.0

func (b DataSource) SetAttributeRaw(name string, tokens hclwrite.Tokens)

SetAttributeRaw sets an attribute for a given name with raw tokens.

func (DataSource) SetAttributeValue added in v0.2.0

func (b DataSource) SetAttributeValue(name string, value cty.Value)

SetAttributeValue sets an attribute for a given name with value.

func (DataSource) SetType added in v0.2.0

func (b DataSource) SetType(typeName string)

SetType updates the type name of the block to a given name.

func (DataSource) Type added in v0.2.0

func (b DataSource) Type() string

Type returns a type of block.

func (DataSource) VerticalFormat added in v0.2.0

func (b DataSource) VerticalFormat()

VerticalFormat formats a body of the block in vertical. Since VerticalFormat clears tokens internally, If you call VerticalFormat each time RemoveNestedBlock is called, the subsequent RemoveNestedBlock will not work properly, so call VerticalFormat only once for each block.

type File

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

File represents a Terraform configuration file

func NewEmptyFile

func NewEmptyFile() *File

NewEmptyFile creates a new file with an empty body.

func NewFile

func NewFile(file *hclwrite.File) *File

NewFile creates a new instance of File.

func (*File) AppendBlock added in v0.2.0

func (f *File) AppendBlock(block Block)

AppendBlock appends a given block to the file.

func (*File) Blocks added in v0.2.0

func (f *File) Blocks() []Block

Blocks returns all blocks.

func (*File) FindBlocksByType added in v0.2.0

func (f *File) FindBlocksByType(blockType string, schemaType string) []Block

FindBlocksByType returns all matching blocks from the body that have the given blockType and schemaType or returns an empty list if not found. If the given blockType or schemaType are a non-empty string, filter the results.

func (*File) Raw

func (f *File) Raw() *hclwrite.File

Raw returns a raw object for hclwrite.

type Locals added in v0.2.1

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

Locals represents a locals block. It implements the Block interface.

func NewEmptyLocals added in v0.2.1

func NewEmptyLocals() *Locals

NewEmptyLocals creates a new Locals with an empty body.

func NewLocals added in v0.2.1

func NewLocals(block *hclwrite.Block) *Locals

NewLocals creates a new instance of Locals.

func (Locals) AppendAttribute added in v0.2.1

func (b Locals) AppendAttribute(attr *Attribute)

AppendAttribute appends a given attribute to the block.

func (Locals) AppendNestedBlock added in v0.2.1

func (b Locals) AppendNestedBlock(nestedBlock Block)

AppendNestedBlock appends a given nested block to the parent block.

func (Locals) AppendUnwrappedNestedBlockBody added in v0.2.1

func (b Locals) AppendUnwrappedNestedBlockBody(nestedBlock Block)

AppendUnwrappedNestedBlockBody appends a body of a given block to the parent block. It looks a weird operation, but it's often needed for refactoring like splitting a resource type for sub resource types.

func (Locals) Attributes added in v0.2.1

func (b Locals) Attributes() []*Attribute

Attributes returns all attributes. Note that this does not return attributes in nested blocks.

func (Locals) CopyAttribute added in v0.2.1

func (b Locals) CopyAttribute(from Block, name string)

CopyAttribute is a helper method which copies an attribute from a given block. Do nothing if the given block doesn't have the attribute.

func (Locals) FindNestedBlocksByType added in v0.2.1

func (b Locals) FindNestedBlocksByType(blockType string) []Block

FindNestedBlocksByType returns all matching blocks from the body that have the given block type or returns an empty list if not found.

func (Locals) GetAttribute added in v0.2.1

func (b Locals) GetAttribute(name string) *Attribute

GetAttribute returns an attribute for a given name.

func (Locals) NestedBlocks added in v0.2.1

func (b Locals) NestedBlocks() []*NestedBlock

NestedBlocks returns all nested blocks.

func (Locals) Raw added in v0.2.1

func (b Locals) Raw() *hclwrite.Block

Raw returns a raw block instance of hclwrite. It should keep it private if possible, but it's required for some operations.

func (Locals) References added in v0.2.1

func (b Locals) References() []string

References returns all variable references for all attributes. It returns a unique and sorted list.

func (Locals) RemoveAttribute added in v0.2.1

func (b Locals) RemoveAttribute(name string)

RemoveAttribute removes an attribute for a given name from the block.

func (Locals) RemoveNestedBlock added in v0.2.1

func (b Locals) RemoveNestedBlock(nestedBlock Block)

RemoveNestedBlock removes a given nested block from the parent block.

func (Locals) RenameReference added in v0.2.1

func (b Locals) RenameReference(from string, to string)

RenameReference renames all variable references for all attributes. The `from` and `to` arguments are specified as dot-delimited resource addresses. The `from` argument can be a partial prefix match, but must match the length of the `to` argument.

func (Locals) SchemaType added in v0.2.1

func (b Locals) SchemaType() string

SchemaType returns the first label of block. If it does not have a label, return an empty string. Note that it's not the same as the *hclwrite.Block.Type().

func (Locals) SetAttributeRaw added in v0.2.1

func (b Locals) SetAttributeRaw(name string, tokens hclwrite.Tokens)

SetAttributeRaw sets an attribute for a given name with raw tokens.

func (Locals) SetAttributeValue added in v0.2.1

func (b Locals) SetAttributeValue(name string, value cty.Value)

SetAttributeValue sets an attribute for a given name with value.

func (Locals) SetType added in v0.2.1

func (b Locals) SetType(typeName string)

SetType updates the type name of the block to a given name.

func (Locals) Type added in v0.2.1

func (b Locals) Type() string

Type returns a type of block.

func (Locals) VerticalFormat added in v0.2.1

func (b Locals) VerticalFormat()

VerticalFormat formats a body of the block in vertical. Since VerticalFormat clears tokens internally, If you call VerticalFormat each time RemoveNestedBlock is called, the subsequent RemoveNestedBlock will not work properly, so call VerticalFormat only once for each block.

type Module added in v0.2.1

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

Module represents a module block. It implements the Block interface.

func NewEmptyModule added in v0.2.1

func NewEmptyModule(moduleType string) *Module

NewEmptyModule creates a new Module with an empty body.

func NewModule added in v0.2.1

func NewModule(block *hclwrite.Block) *Module

NewModule creates a new instance of Module.

func (Module) AppendAttribute added in v0.2.1

func (b Module) AppendAttribute(attr *Attribute)

AppendAttribute appends a given attribute to the block.

func (Module) AppendNestedBlock added in v0.2.1

func (b Module) AppendNestedBlock(nestedBlock Block)

AppendNestedBlock appends a given nested block to the parent block.

func (Module) AppendUnwrappedNestedBlockBody added in v0.2.1

func (b Module) AppendUnwrappedNestedBlockBody(nestedBlock Block)

AppendUnwrappedNestedBlockBody appends a body of a given block to the parent block. It looks a weird operation, but it's often needed for refactoring like splitting a resource type for sub resource types.

func (Module) Attributes added in v0.2.1

func (b Module) Attributes() []*Attribute

Attributes returns all attributes. Note that this does not return attributes in nested blocks.

func (Module) CopyAttribute added in v0.2.1

func (b Module) CopyAttribute(from Block, name string)

CopyAttribute is a helper method which copies an attribute from a given block. Do nothing if the given block doesn't have the attribute.

func (Module) FindNestedBlocksByType added in v0.2.1

func (b Module) FindNestedBlocksByType(blockType string) []Block

FindNestedBlocksByType returns all matching blocks from the body that have the given block type or returns an empty list if not found.

func (Module) GetAttribute added in v0.2.1

func (b Module) GetAttribute(name string) *Attribute

GetAttribute returns an attribute for a given name.

func (Module) NestedBlocks added in v0.2.1

func (b Module) NestedBlocks() []*NestedBlock

NestedBlocks returns all nested blocks.

func (Module) Raw added in v0.2.1

func (b Module) Raw() *hclwrite.Block

Raw returns a raw block instance of hclwrite. It should keep it private if possible, but it's required for some operations.

func (Module) References added in v0.2.1

func (b Module) References() []string

References returns all variable references for all attributes. It returns a unique and sorted list.

func (Module) RemoveAttribute added in v0.2.1

func (b Module) RemoveAttribute(name string)

RemoveAttribute removes an attribute for a given name from the block.

func (Module) RemoveNestedBlock added in v0.2.1

func (b Module) RemoveNestedBlock(nestedBlock Block)

RemoveNestedBlock removes a given nested block from the parent block.

func (Module) RenameReference added in v0.2.1

func (b Module) RenameReference(from string, to string)

RenameReference renames all variable references for all attributes. The `from` and `to` arguments are specified as dot-delimited resource addresses. The `from` argument can be a partial prefix match, but must match the length of the `to` argument.

func (Module) SchemaType added in v0.2.1

func (b Module) SchemaType() string

SchemaType returns the first label of block. If it does not have a label, return an empty string. Note that it's not the same as the *hclwrite.Block.Type().

func (Module) SetAttributeRaw added in v0.2.1

func (b Module) SetAttributeRaw(name string, tokens hclwrite.Tokens)

SetAttributeRaw sets an attribute for a given name with raw tokens.

func (Module) SetAttributeValue added in v0.2.1

func (b Module) SetAttributeValue(name string, value cty.Value)

SetAttributeValue sets an attribute for a given name with value.

func (Module) SetType added in v0.2.1

func (b Module) SetType(typeName string)

SetType updates the type name of the block to a given name.

func (Module) Type added in v0.2.1

func (b Module) Type() string

Type returns a type of block.

func (Module) VerticalFormat added in v0.2.1

func (b Module) VerticalFormat()

VerticalFormat formats a body of the block in vertical. Since VerticalFormat clears tokens internally, If you call VerticalFormat each time RemoveNestedBlock is called, the subsequent RemoveNestedBlock will not work properly, so call VerticalFormat only once for each block.

type Moved added in v0.2.1

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

Moved represents a moved block. It implements the Block interface.

func NewEmptyMoved added in v0.2.1

func NewEmptyMoved() *Moved

NewEmptyMoved creates a new Moved with an empty body.

func NewMoved added in v0.2.1

func NewMoved(block *hclwrite.Block) *Moved

NewMoved creates a new instance of Moved.

func (Moved) AppendAttribute added in v0.2.1

func (b Moved) AppendAttribute(attr *Attribute)

AppendAttribute appends a given attribute to the block.

func (Moved) AppendNestedBlock added in v0.2.1

func (b Moved) AppendNestedBlock(nestedBlock Block)

AppendNestedBlock appends a given nested block to the parent block.

func (Moved) AppendUnwrappedNestedBlockBody added in v0.2.1

func (b Moved) AppendUnwrappedNestedBlockBody(nestedBlock Block)

AppendUnwrappedNestedBlockBody appends a body of a given block to the parent block. It looks a weird operation, but it's often needed for refactoring like splitting a resource type for sub resource types.

func (Moved) Attributes added in v0.2.1

func (b Moved) Attributes() []*Attribute

Attributes returns all attributes. Note that this does not return attributes in nested blocks.

func (Moved) CopyAttribute added in v0.2.1

func (b Moved) CopyAttribute(from Block, name string)

CopyAttribute is a helper method which copies an attribute from a given block. Do nothing if the given block doesn't have the attribute.

func (Moved) FindNestedBlocksByType added in v0.2.1

func (b Moved) FindNestedBlocksByType(blockType string) []Block

FindNestedBlocksByType returns all matching blocks from the body that have the given block type or returns an empty list if not found.

func (Moved) GetAttribute added in v0.2.1

func (b Moved) GetAttribute(name string) *Attribute

GetAttribute returns an attribute for a given name.

func (Moved) NestedBlocks added in v0.2.1

func (b Moved) NestedBlocks() []*NestedBlock

NestedBlocks returns all nested blocks.

func (Moved) Raw added in v0.2.1

func (b Moved) Raw() *hclwrite.Block

Raw returns a raw block instance of hclwrite. It should keep it private if possible, but it's required for some operations.

func (Moved) References added in v0.2.1

func (b Moved) References() []string

References returns all variable references for all attributes. It returns a unique and sorted list.

func (Moved) RemoveAttribute added in v0.2.1

func (b Moved) RemoveAttribute(name string)

RemoveAttribute removes an attribute for a given name from the block.

func (Moved) RemoveNestedBlock added in v0.2.1

func (b Moved) RemoveNestedBlock(nestedBlock Block)

RemoveNestedBlock removes a given nested block from the parent block.

func (Moved) RenameReference added in v0.2.1

func (b Moved) RenameReference(from string, to string)

RenameReference renames all variable references for all attributes. The `from` and `to` arguments are specified as dot-delimited resource addresses. The `from` argument can be a partial prefix match, but must match the length of the `to` argument.

func (Moved) SchemaType added in v0.2.1

func (b Moved) SchemaType() string

SchemaType returns the first label of block. If it does not have a label, return an empty string. Note that it's not the same as the *hclwrite.Block.Type().

func (Moved) SetAttributeRaw added in v0.2.1

func (b Moved) SetAttributeRaw(name string, tokens hclwrite.Tokens)

SetAttributeRaw sets an attribute for a given name with raw tokens.

func (Moved) SetAttributeValue added in v0.2.1

func (b Moved) SetAttributeValue(name string, value cty.Value)

SetAttributeValue sets an attribute for a given name with value.

func (Moved) SetType added in v0.2.1

func (b Moved) SetType(typeName string)

SetType updates the type name of the block to a given name.

func (Moved) Type added in v0.2.1

func (b Moved) Type() string

Type returns a type of block.

func (Moved) VerticalFormat added in v0.2.1

func (b Moved) VerticalFormat()

VerticalFormat formats a body of the block in vertical. Since VerticalFormat clears tokens internally, If you call VerticalFormat each time RemoveNestedBlock is called, the subsequent RemoveNestedBlock will not work properly, so call VerticalFormat only once for each block.

type NestedBlock

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

NestedBlock represents a nested block. It implements the Block interface.

func NewEmptyNestedBlock

func NewEmptyNestedBlock(blockType string) *NestedBlock

NewEmptyNestedBlock creates a new NestedBlock with an empty body.

func NewNestedBlock

func NewNestedBlock(block *hclwrite.Block) *NestedBlock

NewNestedBlock creates a new instance of NestedBlock.

func (NestedBlock) AppendAttribute

func (b NestedBlock) AppendAttribute(attr *Attribute)

AppendAttribute appends a given attribute to the block.

func (NestedBlock) AppendNestedBlock

func (b NestedBlock) AppendNestedBlock(nestedBlock Block)

AppendNestedBlock appends a given nested block to the parent block.

func (NestedBlock) AppendUnwrappedNestedBlockBody

func (b NestedBlock) AppendUnwrappedNestedBlockBody(nestedBlock Block)

AppendUnwrappedNestedBlockBody appends a body of a given block to the parent block. It looks a weird operation, but it's often needed for refactoring like splitting a resource type for sub resource types.

func (NestedBlock) Attributes added in v0.2.1

func (b NestedBlock) Attributes() []*Attribute

Attributes returns all attributes. Note that this does not return attributes in nested blocks.

func (NestedBlock) CopyAttribute added in v0.0.3

func (b NestedBlock) CopyAttribute(from Block, name string)

CopyAttribute is a helper method which copies an attribute from a given block. Do nothing if the given block doesn't have the attribute.

func (NestedBlock) FindNestedBlocksByType

func (b NestedBlock) FindNestedBlocksByType(blockType string) []Block

FindNestedBlocksByType returns all matching blocks from the body that have the given block type or returns an empty list if not found.

func (NestedBlock) GetAttribute

func (b NestedBlock) GetAttribute(name string) *Attribute

GetAttribute returns an attribute for a given name.

func (NestedBlock) NestedBlocks added in v0.2.1

func (b NestedBlock) NestedBlocks() []*NestedBlock

NestedBlocks returns all nested blocks.

func (NestedBlock) Raw

func (b NestedBlock) Raw() *hclwrite.Block

Raw returns a raw block instance of hclwrite. It should keep it private if possible, but it's required for some operations.

func (NestedBlock) References added in v0.2.1

func (b NestedBlock) References() []string

References returns all variable references for all attributes. It returns a unique and sorted list.

func (NestedBlock) RemoveAttribute

func (b NestedBlock) RemoveAttribute(name string)

RemoveAttribute removes an attribute for a given name from the block.

func (NestedBlock) RemoveNestedBlock

func (b NestedBlock) RemoveNestedBlock(nestedBlock Block)

RemoveNestedBlock removes a given nested block from the parent block.

func (NestedBlock) RenameReference added in v0.2.1

func (b NestedBlock) RenameReference(from string, to string)

RenameReference renames all variable references for all attributes. The `from` and `to` arguments are specified as dot-delimited resource addresses. The `from` argument can be a partial prefix match, but must match the length of the `to` argument.

func (NestedBlock) SchemaType added in v0.2.0

func (b NestedBlock) SchemaType() string

SchemaType returns the first label of block. If it does not have a label, return an empty string. Note that it's not the same as the *hclwrite.Block.Type().

func (NestedBlock) SetAttributeRaw

func (b NestedBlock) SetAttributeRaw(name string, tokens hclwrite.Tokens)

SetAttributeRaw sets an attribute for a given name with raw tokens.

func (NestedBlock) SetAttributeValue

func (b NestedBlock) SetAttributeValue(name string, value cty.Value)

SetAttributeValue sets an attribute for a given name with value.

func (NestedBlock) SetType

func (b NestedBlock) SetType(typeName string)

SetType updates the type name of the block to a given name.

func (NestedBlock) Type

func (b NestedBlock) Type() string

Type returns a type of block.

func (NestedBlock) VerticalFormat

func (b NestedBlock) VerticalFormat()

VerticalFormat formats a body of the block in vertical. Since VerticalFormat clears tokens internally, If you call VerticalFormat each time RemoveNestedBlock is called, the subsequent RemoveNestedBlock will not work properly, so call VerticalFormat only once for each block.

type Output added in v0.2.1

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

Output represents a output block. It implements the Block interface.

func NewEmptyOutput added in v0.2.1

func NewEmptyOutput(outputType string) *Output

NewEmptyOutput creates a new Output with an empty body.

func NewOutput added in v0.2.1

func NewOutput(block *hclwrite.Block) *Output

NewOutput creates a new instance of Output.

func (Output) AppendAttribute added in v0.2.1

func (b Output) AppendAttribute(attr *Attribute)

AppendAttribute appends a given attribute to the block.

func (Output) AppendNestedBlock added in v0.2.1

func (b Output) AppendNestedBlock(nestedBlock Block)

AppendNestedBlock appends a given nested block to the parent block.

func (Output) AppendUnwrappedNestedBlockBody added in v0.2.1

func (b Output) AppendUnwrappedNestedBlockBody(nestedBlock Block)

AppendUnwrappedNestedBlockBody appends a body of a given block to the parent block. It looks a weird operation, but it's often needed for refactoring like splitting a resource type for sub resource types.

func (Output) Attributes added in v0.2.1

func (b Output) Attributes() []*Attribute

Attributes returns all attributes. Note that this does not return attributes in nested blocks.

func (Output) CopyAttribute added in v0.2.1

func (b Output) CopyAttribute(from Block, name string)

CopyAttribute is a helper method which copies an attribute from a given block. Do nothing if the given block doesn't have the attribute.

func (Output) FindNestedBlocksByType added in v0.2.1

func (b Output) FindNestedBlocksByType(blockType string) []Block

FindNestedBlocksByType returns all matching blocks from the body that have the given block type or returns an empty list if not found.

func (Output) GetAttribute added in v0.2.1

func (b Output) GetAttribute(name string) *Attribute

GetAttribute returns an attribute for a given name.

func (Output) NestedBlocks added in v0.2.1

func (b Output) NestedBlocks() []*NestedBlock

NestedBlocks returns all nested blocks.

func (Output) Raw added in v0.2.1

func (b Output) Raw() *hclwrite.Block

Raw returns a raw block instance of hclwrite. It should keep it private if possible, but it's required for some operations.

func (Output) References added in v0.2.1

func (b Output) References() []string

References returns all variable references for all attributes. It returns a unique and sorted list.

func (Output) RemoveAttribute added in v0.2.1

func (b Output) RemoveAttribute(name string)

RemoveAttribute removes an attribute for a given name from the block.

func (Output) RemoveNestedBlock added in v0.2.1

func (b Output) RemoveNestedBlock(nestedBlock Block)

RemoveNestedBlock removes a given nested block from the parent block.

func (Output) RenameReference added in v0.2.1

func (b Output) RenameReference(from string, to string)

RenameReference renames all variable references for all attributes. The `from` and `to` arguments are specified as dot-delimited resource addresses. The `from` argument can be a partial prefix match, but must match the length of the `to` argument.

func (Output) SchemaType added in v0.2.1

func (b Output) SchemaType() string

SchemaType returns the first label of block. If it does not have a label, return an empty string. Note that it's not the same as the *hclwrite.Block.Type().

func (Output) SetAttributeRaw added in v0.2.1

func (b Output) SetAttributeRaw(name string, tokens hclwrite.Tokens)

SetAttributeRaw sets an attribute for a given name with raw tokens.

func (Output) SetAttributeValue added in v0.2.1

func (b Output) SetAttributeValue(name string, value cty.Value)

SetAttributeValue sets an attribute for a given name with value.

func (Output) SetType added in v0.2.1

func (b Output) SetType(typeName string)

SetType updates the type name of the block to a given name.

func (Output) Type added in v0.2.1

func (b Output) Type() string

Type returns a type of block.

func (Output) VerticalFormat added in v0.2.1

func (b Output) VerticalFormat()

VerticalFormat formats a body of the block in vertical. Since VerticalFormat clears tokens internally, If you call VerticalFormat each time RemoveNestedBlock is called, the subsequent RemoveNestedBlock will not work properly, so call VerticalFormat only once for each block.

type Provider added in v0.2.0

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

Provider represents a provider block. It implements the Block interface.

func NewEmptyProvider added in v0.2.0

func NewEmptyProvider(providerType string) *Provider

NewEmptyProvider creates a new Provider with an empty body.

func NewProvider added in v0.2.0

func NewProvider(block *hclwrite.Block) *Provider

NewProvider creates a new instance of Provider.

func (Provider) AppendAttribute added in v0.2.0

func (b Provider) AppendAttribute(attr *Attribute)

AppendAttribute appends a given attribute to the block.

func (Provider) AppendNestedBlock added in v0.2.0

func (b Provider) AppendNestedBlock(nestedBlock Block)

AppendNestedBlock appends a given nested block to the parent block.

func (Provider) AppendUnwrappedNestedBlockBody added in v0.2.0

func (b Provider) AppendUnwrappedNestedBlockBody(nestedBlock Block)

AppendUnwrappedNestedBlockBody appends a body of a given block to the parent block. It looks a weird operation, but it's often needed for refactoring like splitting a resource type for sub resource types.

func (Provider) Attributes added in v0.2.1

func (b Provider) Attributes() []*Attribute

Attributes returns all attributes. Note that this does not return attributes in nested blocks.

func (Provider) CopyAttribute added in v0.2.0

func (b Provider) CopyAttribute(from Block, name string)

CopyAttribute is a helper method which copies an attribute from a given block. Do nothing if the given block doesn't have the attribute.

func (Provider) FindNestedBlocksByType added in v0.2.0

func (b Provider) FindNestedBlocksByType(blockType string) []Block

FindNestedBlocksByType returns all matching blocks from the body that have the given block type or returns an empty list if not found.

func (Provider) GetAttribute added in v0.2.0

func (b Provider) GetAttribute(name string) *Attribute

GetAttribute returns an attribute for a given name.

func (Provider) NestedBlocks added in v0.2.1

func (b Provider) NestedBlocks() []*NestedBlock

NestedBlocks returns all nested blocks.

func (Provider) Raw added in v0.2.0

func (b Provider) Raw() *hclwrite.Block

Raw returns a raw block instance of hclwrite. It should keep it private if possible, but it's required for some operations.

func (Provider) References added in v0.2.1

func (b Provider) References() []string

References returns all variable references for all attributes. It returns a unique and sorted list.

func (Provider) RemoveAttribute added in v0.2.0

func (b Provider) RemoveAttribute(name string)

RemoveAttribute removes an attribute for a given name from the block.

func (Provider) RemoveNestedBlock added in v0.2.0

func (b Provider) RemoveNestedBlock(nestedBlock Block)

RemoveNestedBlock removes a given nested block from the parent block.

func (Provider) RenameReference added in v0.2.1

func (b Provider) RenameReference(from string, to string)

RenameReference renames all variable references for all attributes. The `from` and `to` arguments are specified as dot-delimited resource addresses. The `from` argument can be a partial prefix match, but must match the length of the `to` argument.

func (Provider) SchemaType added in v0.2.0

func (b Provider) SchemaType() string

SchemaType returns the first label of block. If it does not have a label, return an empty string. Note that it's not the same as the *hclwrite.Block.Type().

func (Provider) SetAttributeRaw added in v0.2.0

func (b Provider) SetAttributeRaw(name string, tokens hclwrite.Tokens)

SetAttributeRaw sets an attribute for a given name with raw tokens.

func (Provider) SetAttributeValue added in v0.2.0

func (b Provider) SetAttributeValue(name string, value cty.Value)

SetAttributeValue sets an attribute for a given name with value.

func (Provider) SetType added in v0.2.0

func (b Provider) SetType(typeName string)

SetType updates the type name of the block to a given name.

func (Provider) Type added in v0.2.0

func (b Provider) Type() string

Type returns a type of block.

func (Provider) VerticalFormat added in v0.2.0

func (b Provider) VerticalFormat()

VerticalFormat formats a body of the block in vertical. Since VerticalFormat clears tokens internally, If you call VerticalFormat each time RemoveNestedBlock is called, the subsequent RemoveNestedBlock will not work properly, so call VerticalFormat only once for each block.

type Resource

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

Resource represents a resource block. It implements the Block interface.

func NewEmptyResource

func NewEmptyResource(resourceType string, resourceName string) *Resource

NewEmptyResource creates a new Resource with an empty body.

func NewResource

func NewResource(block *hclwrite.Block) *Resource

NewResource creates a new instance of Resource.

func (Resource) AppendAttribute

func (b Resource) AppendAttribute(attr *Attribute)

AppendAttribute appends a given attribute to the block.

func (Resource) AppendNestedBlock

func (b Resource) AppendNestedBlock(nestedBlock Block)

AppendNestedBlock appends a given nested block to the parent block.

func (Resource) AppendUnwrappedNestedBlockBody

func (b Resource) AppendUnwrappedNestedBlockBody(nestedBlock Block)

AppendUnwrappedNestedBlockBody appends a body of a given block to the parent block. It looks a weird operation, but it's often needed for refactoring like splitting a resource type for sub resource types.

func (Resource) Attributes added in v0.2.1

func (b Resource) Attributes() []*Attribute

Attributes returns all attributes. Note that this does not return attributes in nested blocks.

func (Resource) CopyAttribute added in v0.0.3

func (b Resource) CopyAttribute(from Block, name string)

CopyAttribute is a helper method which copies an attribute from a given block. Do nothing if the given block doesn't have the attribute.

func (*Resource) Count added in v0.0.3

func (r *Resource) Count() *Attribute

Count returns a meta argument of count. It returns nil if not found.

func (Resource) FindNestedBlocksByType

func (b Resource) FindNestedBlocksByType(blockType string) []Block

FindNestedBlocksByType returns all matching blocks from the body that have the given block type or returns an empty list if not found.

func (*Resource) ForEach added in v0.0.3

func (r *Resource) ForEach() *Attribute

ForEach returns a meta argument of for_each. It returns nil if not found.

func (Resource) GetAttribute

func (b Resource) GetAttribute(name string) *Attribute

GetAttribute returns an attribute for a given name.

func (*Resource) Name

func (r *Resource) Name() string

Name returns a name of resource. It returns the second label of block.

func (Resource) NestedBlocks added in v0.2.1

func (b Resource) NestedBlocks() []*NestedBlock

NestedBlocks returns all nested blocks.

func (Resource) Raw

func (b Resource) Raw() *hclwrite.Block

Raw returns a raw block instance of hclwrite. It should keep it private if possible, but it's required for some operations.

func (*Resource) ReferableName added in v0.0.3

func (r *Resource) ReferableName() string

ReferableName returns a name of resource instance which can be referenced as a part of address. It contains an index reference if count or for_each is set. If neither count nor for_each is set, it just returns the name.

func (Resource) References added in v0.2.1

func (b Resource) References() []string

References returns all variable references for all attributes. It returns a unique and sorted list.

func (Resource) RemoveAttribute

func (b Resource) RemoveAttribute(name string)

RemoveAttribute removes an attribute for a given name from the block.

func (Resource) RemoveNestedBlock

func (b Resource) RemoveNestedBlock(nestedBlock Block)

RemoveNestedBlock removes a given nested block from the parent block.

func (Resource) RenameReference added in v0.2.1

func (b Resource) RenameReference(from string, to string)

RenameReference renames all variable references for all attributes. The `from` and `to` arguments are specified as dot-delimited resource addresses. The `from` argument can be a partial prefix match, but must match the length of the `to` argument.

func (Resource) SchemaType

func (b Resource) SchemaType() string

SchemaType returns the first label of block. If it does not have a label, return an empty string. Note that it's not the same as the *hclwrite.Block.Type().

func (*Resource) SetAttributeByReference

func (r *Resource) SetAttributeByReference(name string, refResource *Resource, refAttribute string)

SetAttributeByReference sets an attribute for a given name to a reference of another resource.

func (Resource) SetAttributeRaw

func (b Resource) SetAttributeRaw(name string, tokens hclwrite.Tokens)

SetAttributeRaw sets an attribute for a given name with raw tokens.

func (Resource) SetAttributeValue

func (b Resource) SetAttributeValue(name string, value cty.Value)

SetAttributeValue sets an attribute for a given name with value.

func (Resource) SetType

func (b Resource) SetType(typeName string)

SetType updates the type name of the block to a given name.

func (Resource) Type

func (b Resource) Type() string

Type returns a type of block.

func (Resource) VerticalFormat

func (b Resource) VerticalFormat()

VerticalFormat formats a body of the block in vertical. Since VerticalFormat clears tokens internally, If you call VerticalFormat each time RemoveNestedBlock is called, the subsequent RemoveNestedBlock will not work properly, so call VerticalFormat only once for each block.

type Terraform added in v0.2.1

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

Terraform represents a terraform block. It implements the Block interface.

func NewEmptyTerraform added in v0.2.1

func NewEmptyTerraform() *Terraform

NewEmptyTerraform creates a new Terraform with an empty body.

func NewTerraform added in v0.2.1

func NewTerraform(block *hclwrite.Block) *Terraform

NewTerraform creates a new instance of Terraform.

func (Terraform) AppendAttribute added in v0.2.1

func (b Terraform) AppendAttribute(attr *Attribute)

AppendAttribute appends a given attribute to the block.

func (Terraform) AppendNestedBlock added in v0.2.1

func (b Terraform) AppendNestedBlock(nestedBlock Block)

AppendNestedBlock appends a given nested block to the parent block.

func (Terraform) AppendUnwrappedNestedBlockBody added in v0.2.1

func (b Terraform) AppendUnwrappedNestedBlockBody(nestedBlock Block)

AppendUnwrappedNestedBlockBody appends a body of a given block to the parent block. It looks a weird operation, but it's often needed for refactoring like splitting a resource type for sub resource types.

func (Terraform) Attributes added in v0.2.1

func (b Terraform) Attributes() []*Attribute

Attributes returns all attributes. Note that this does not return attributes in nested blocks.

func (Terraform) CopyAttribute added in v0.2.1

func (b Terraform) CopyAttribute(from Block, name string)

CopyAttribute is a helper method which copies an attribute from a given block. Do nothing if the given block doesn't have the attribute.

func (Terraform) FindNestedBlocksByType added in v0.2.1

func (b Terraform) FindNestedBlocksByType(blockType string) []Block

FindNestedBlocksByType returns all matching blocks from the body that have the given block type or returns an empty list if not found.

func (Terraform) GetAttribute added in v0.2.1

func (b Terraform) GetAttribute(name string) *Attribute

GetAttribute returns an attribute for a given name.

func (Terraform) NestedBlocks added in v0.2.1

func (b Terraform) NestedBlocks() []*NestedBlock

NestedBlocks returns all nested blocks.

func (Terraform) Raw added in v0.2.1

func (b Terraform) Raw() *hclwrite.Block

Raw returns a raw block instance of hclwrite. It should keep it private if possible, but it's required for some operations.

func (Terraform) References added in v0.2.1

func (b Terraform) References() []string

References returns all variable references for all attributes. It returns a unique and sorted list.

func (Terraform) RemoveAttribute added in v0.2.1

func (b Terraform) RemoveAttribute(name string)

RemoveAttribute removes an attribute for a given name from the block.

func (Terraform) RemoveNestedBlock added in v0.2.1

func (b Terraform) RemoveNestedBlock(nestedBlock Block)

RemoveNestedBlock removes a given nested block from the parent block.

func (Terraform) RenameReference added in v0.2.1

func (b Terraform) RenameReference(from string, to string)

RenameReference renames all variable references for all attributes. The `from` and `to` arguments are specified as dot-delimited resource addresses. The `from` argument can be a partial prefix match, but must match the length of the `to` argument.

func (Terraform) SchemaType added in v0.2.1

func (b Terraform) SchemaType() string

SchemaType returns the first label of block. If it does not have a label, return an empty string. Note that it's not the same as the *hclwrite.Block.Type().

func (Terraform) SetAttributeRaw added in v0.2.1

func (b Terraform) SetAttributeRaw(name string, tokens hclwrite.Tokens)

SetAttributeRaw sets an attribute for a given name with raw tokens.

func (Terraform) SetAttributeValue added in v0.2.1

func (b Terraform) SetAttributeValue(name string, value cty.Value)

SetAttributeValue sets an attribute for a given name with value.

func (Terraform) SetType added in v0.2.1

func (b Terraform) SetType(typeName string)

SetType updates the type name of the block to a given name.

func (Terraform) Type added in v0.2.1

func (b Terraform) Type() string

Type returns a type of block.

func (Terraform) VerticalFormat added in v0.2.1

func (b Terraform) VerticalFormat()

VerticalFormat formats a body of the block in vertical. Since VerticalFormat clears tokens internally, If you call VerticalFormat each time RemoveNestedBlock is called, the subsequent RemoveNestedBlock will not work properly, so call VerticalFormat only once for each block.

type Variable added in v0.2.1

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

Variable represents a variable block. It implements the Block interface.

func NewEmptyVariable added in v0.2.1

func NewEmptyVariable(variableType string) *Variable

NewEmptyVariable creates a new Variable with an empty body.

func NewVariable added in v0.2.1

func NewVariable(block *hclwrite.Block) *Variable

NewVariable creates a new instance of Variable.

func (Variable) AppendAttribute added in v0.2.1

func (b Variable) AppendAttribute(attr *Attribute)

AppendAttribute appends a given attribute to the block.

func (Variable) AppendNestedBlock added in v0.2.1

func (b Variable) AppendNestedBlock(nestedBlock Block)

AppendNestedBlock appends a given nested block to the parent block.

func (Variable) AppendUnwrappedNestedBlockBody added in v0.2.1

func (b Variable) AppendUnwrappedNestedBlockBody(nestedBlock Block)

AppendUnwrappedNestedBlockBody appends a body of a given block to the parent block. It looks a weird operation, but it's often needed for refactoring like splitting a resource type for sub resource types.

func (Variable) Attributes added in v0.2.1

func (b Variable) Attributes() []*Attribute

Attributes returns all attributes. Note that this does not return attributes in nested blocks.

func (Variable) CopyAttribute added in v0.2.1

func (b Variable) CopyAttribute(from Block, name string)

CopyAttribute is a helper method which copies an attribute from a given block. Do nothing if the given block doesn't have the attribute.

func (Variable) FindNestedBlocksByType added in v0.2.1

func (b Variable) FindNestedBlocksByType(blockType string) []Block

FindNestedBlocksByType returns all matching blocks from the body that have the given block type or returns an empty list if not found.

func (Variable) GetAttribute added in v0.2.1

func (b Variable) GetAttribute(name string) *Attribute

GetAttribute returns an attribute for a given name.

func (Variable) NestedBlocks added in v0.2.1

func (b Variable) NestedBlocks() []*NestedBlock

NestedBlocks returns all nested blocks.

func (Variable) Raw added in v0.2.1

func (b Variable) Raw() *hclwrite.Block

Raw returns a raw block instance of hclwrite. It should keep it private if possible, but it's required for some operations.

func (Variable) References added in v0.2.1

func (b Variable) References() []string

References returns all variable references for all attributes. It returns a unique and sorted list.

func (Variable) RemoveAttribute added in v0.2.1

func (b Variable) RemoveAttribute(name string)

RemoveAttribute removes an attribute for a given name from the block.

func (Variable) RemoveNestedBlock added in v0.2.1

func (b Variable) RemoveNestedBlock(nestedBlock Block)

RemoveNestedBlock removes a given nested block from the parent block.

func (Variable) RenameReference added in v0.2.1

func (b Variable) RenameReference(from string, to string)

RenameReference renames all variable references for all attributes. The `from` and `to` arguments are specified as dot-delimited resource addresses. The `from` argument can be a partial prefix match, but must match the length of the `to` argument.

func (Variable) SchemaType added in v0.2.1

func (b Variable) SchemaType() string

SchemaType returns the first label of block. If it does not have a label, return an empty string. Note that it's not the same as the *hclwrite.Block.Type().

func (Variable) SetAttributeRaw added in v0.2.1

func (b Variable) SetAttributeRaw(name string, tokens hclwrite.Tokens)

SetAttributeRaw sets an attribute for a given name with raw tokens.

func (Variable) SetAttributeValue added in v0.2.1

func (b Variable) SetAttributeValue(name string, value cty.Value)

SetAttributeValue sets an attribute for a given name with value.

func (Variable) SetType added in v0.2.1

func (b Variable) SetType(typeName string)

SetType updates the type name of the block to a given name.

func (Variable) Type added in v0.2.1

func (b Variable) Type() string

Type returns a type of block.

func (Variable) VerticalFormat added in v0.2.1

func (b Variable) VerticalFormat()

VerticalFormat formats a body of the block in vertical. Since VerticalFormat clears tokens internally, If you call VerticalFormat each time RemoveNestedBlock is called, the subsequent RemoveNestedBlock will not work properly, so call VerticalFormat only once for each block.

Jump to

Keyboard shortcuts

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