block

package
v0.3.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TypeTerraform represents the terraform block.
	TypeTerraform = "terraform"
	// TypeBackend represents the backend block inside terraform block.
	TypeBackend = "backend"
	// TypeRequiredProviders represents the required_providers block inside terraform block.
	TypeRequiredProviders = "required_providers"

	// TypeProvider represents the provider block.
	TypeProvider = "provider"
	// TypeModule represents the module block.
	TypeModule = "module"
	// TypeVariable represents the variable block.
	TypeVariable = "variable"
	// TypeOutput represents the output block.
	TypeOutput = "output"
	// TypeResource represents the resource block.
	TypeResource = "resource"

	// TypeK8s represents the kubernetes block.
	TypeK8s = "kubernetes"
)

Variables

This section is empty.

Functions

func ConvertToCtyWithJson

func ConvertToCtyWithJson(val any) (cty.Value, error)

ConvertToCtyWithJson Converts arbitrary go types that are json serializable to a cty Value by using json as an intermediary representation.

func CountLen

func CountLen(blocks ...Blocks) int

CountLen returns the length of the blocks.

func SortValueKeys

func SortValueKeys(val cty.Value) []string

SortValueKeys will return a sorted list of the keys the val has.

Types

type Block

type Block struct {
	// Type the type of the block, e.g. provider, module, resource, etc.
	Type string
	// Label the label of the block, e.g. aws, aws_instance, etc.
	Labels []string

	// Attributes the Attributes of the block.
	Attributes map[string]any
	// contains filtered or unexported fields
}

Block represents to terraform config block like terraform block, provider block, module block, etc. Block.Print() will generate the config string of the block. E.g. Provider block: *

block1 = &Block{
	Type: "provider",
    Labels: []string{"aws"},
	  Attributes: map[string]any{
		"region": "us-east-1",
	},
},
block1.Print("hcl") will generate the string:
provider "aws" {
  region = "us-east-1"
}

block2 = &Block{
	Type: "data",
	Labels: []string{"label1", "label2"},
	Attributes: map[string]any{
		"test": "test"
	},
}
block2.Print("hcl") will generate the string:
data "label1" "label2" {
	  test = "test"
}

func (*Block) AppendBlock

func (b *Block) AppendBlock(block *Block)

func (*Block) EncodeToBytes

func (b *Block) EncodeToBytes() ([]byte, error)

EncodeToBytes returns the block as a config bytes.

func (*Block) ToHCLBlock

func (b *Block) ToHCLBlock() (*hclwrite.Block, error)

ToHCLBlock returns the block as a hclwrite.Block.

type Blocks

type Blocks []*Block

func AppendBlocks

func AppendBlocks(target Blocks, appendBlocks ...Blocks) Blocks

AppendBlocks will append the blocks to the target.

func (*Blocks) GetProviderNames

func (bs *Blocks) GetProviderNames() ([]string, error)

func (*Blocks) Remove

func (bs *Blocks) Remove(block *Block)

Jump to

Keyboard shortcuts

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