types

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2023 License: Apache-2.0, BSD-3-Clause Imports: 22 Imported by: 0

README

terraform block types

terraform

  • backend used to store state -> default is local mutually exclusive with cloud examples: remote, s3, azurerm, consul config is specific to the type
  • cloud config: organization hostname workspaces
  • required_providers name source aliases
  • provider-meta seen as experiemental -> example is to use it to gather statistics on the provider usage

provider

- config is based on the provider schema
- expressions: use variables but no resources/data can be used
- meta-arguments
    alias
    version -> depreciated
    source/count/for_each/depends_on -> not expected

variable

- like function arguments
- meta-arguments
    default
    type (string, number, bool, list<TYPE>, set<TYPE>, map<TYPE>, object)
    description
    validation
    sensitive -> 
    nullable
- variables can be assigned using -var or .tfvars files
- idea is to use KRM here
- cannot have expressions

locals

- like local variables -> can use expressions
- can have expressions

output

- like function outputs -> expose variables to the other module
- meta-arguments
    - value -> expression
    - description
    - sensitive
    - depends_on
    - precondition
    - postcondition

module

- meta-arguments:
   - version
   - source = "./aws_vpc" (mandatory)
        -> europe-docker.pkg.dev/srlinux/eu.gcr.io/<TYPE>:<VERSION>
        -> [<HOSTNAME>/]<NAMESPACE>/<TYPE>
            HOSTNAME: registry.terraform.io
            NAMESPACE: An organizational namespace within the specified registry
            TYPE: typically the provider 
        -> ./,,, -> local path
        -> hashicorp/conusl/aws -> registry (app.terraform.io/example-corp/k8s-cluster/azurerm)
        supported:
            - local
            - registry
            - github/bitbucket/git
            - s3
            - gcs
   - providers = { aws = aws.west }
   - for_each
   - count
   - depends_on
   - <dynamic input variables>

resource

- meta-arguments:
    provider
    count
    for_each mutually exclusive with count
    depends_on
    lifecycle
        create_before_destroy
        prevent_destroy
        replace_triggered_by
        ignore_changes
    precondition
    postcondition
    connection
    provisioner

data

- meta-arguments:
    -> see resource

moved

- to deal with module resource changes
- meta-arguments:
    from
    to

import

- Use the import block to import existing infrastructure resources into Terraform, bringing them under Terraform's management
- Not sure if we need this as a resource will do this for us

check

Documentation

Index

Constants

View Source
const (
	ResourceType = "resourceType"
	ResourceID   = "resourceID"
)
View Source
const (
	LoopKeyCountIndex = "count.index"
	LoopKeyForEachKey = "each.key"
	LoopKeyForEachVal = "each.value"
)

Variables

View Source
var BlockTypes = map[BlockType]BlockInitializer{
	BlockTypeBackend:  newBackend,
	BlockTypeProvider: newProvider,
	BlockTypeModule:   newModule,
	BlockTypeInput:    newInput,
	BlockTypeOutput:   newOutput,
	BlockTypeLocal:    newLocal,
	BlockTypeResource: newResource,
	BlockTypeData:     newResource,
	BlockTypeList:     newResource,
}
View Source
var LocalVars = map[string]struct{}{
	LoopKeyCountIndex: {},
	LoopKeyForEachKey: {},
	LoopKeyForEachVal: {},
}

Functions

func GetBlockTypeNames

func GetBlockTypeNames() []string

func GetContext

func GetContext(ctx context.Context) string

func ParseReferenceString

func ParseReferenceString(inputString string) string

Types

type Backend

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

func (*Backend) GetAttributes

func (r *Backend) GetAttributes() *KformBlockAttributes

func (*Backend) GetBlockName

func (r *Backend) GetBlockName() string

func (*Backend) GetBlockType

func (r *Backend) GetBlockType() string

func (*Backend) GetConfig

func (r *Backend) GetConfig() any

func (*Backend) GetContext

func (r *Backend) GetContext(n string) string

func (*Backend) GetDefault

func (r *Backend) GetDefault() []any

func (*Backend) GetDependencies

func (r *Backend) GetDependencies() map[string]string

func (*Backend) GetFileName

func (r *Backend) GetFileName() string

func (*Backend) GetInputParams

func (r *Backend) GetInputParams() map[string]any

func (*Backend) GetLevel

func (r *Backend) GetLevel() int

func (*Backend) GetModDependencies

func (r *Backend) GetModDependencies() map[string]string

func (*Backend) GetModuleName

func (r *Backend) GetModuleName() string

func (*Backend) GetValue

func (r *Backend) GetValue() any

func (*Backend) ProcessBlock

func (r *Backend) ProcessBlock(ctx context.Context, block *KformBlock) context.Context

type Block

type Block interface {
	// implemented generically
	GetBlockType() string
	GetLevel() int
	ProcessBlock(context.Context, *KformBlock) context.Context

	// specific implementation
	UpdateModule(context.Context)
}

func GetBlock

func GetBlock(ctx context.Context, n string) (Block, error)

type BlockContextKey

type BlockContextKey string
const (
	BlockContextKeyUnknown    BlockContextKey = "unknown"
	BlockContextKeyAttributes BlockContextKey = "attributes"
	//BlockContextKeyInstances   BlockContextKey = "instances"
	BlockContextKeyDefault     BlockContextKey = "default"
	BlockContextKeyInputParams BlockContextKey = "inputParams"
	BlockContextKeyConfig      BlockContextKey = "config"
	BlockContextKeyValue       BlockContextKey = "value"
)

type BlockInitializer

type BlockInitializer func(ctx context.Context, n string) Block

type BlockType

type BlockType string
const (
	BlockTypeUnknown           BlockType = "unknown"
	BlockTypeBackend           BlockType = "backend"
	BlockTypeRequiredProviders BlockType = "requiredProviders"
	BlockTypeProvider          BlockType = "provider"
	BlockTypeModule            BlockType = "module"
	BlockTypeInput             BlockType = "input"
	BlockTypeOutput            BlockType = "output"
	BlockTypeLocal             BlockType = "local"
	BlockTypeResource          BlockType = "resource"
	BlockTypeData              BlockType = "data"
	BlockTypeList              BlockType = "list"
	BlockTypeRoot              BlockType = dag.Root
)

func GetBlockType

func GetBlockType(n string) BlockType

type Context

type Context struct {
	FileName   string  `json:"fileName"`
	ModuleKind string  `json:"moduleKind"`
	Module     string  `json:"module"`
	BlockType  *string `json:"blockType,omitempty"`
	Level      int     `json:"level"`
	VarName    *string `json:"varName,omitempty"`
	VarType    *string `json:"varType,omitempty"`
}

type CtxKey

type CtxKey string
const (
	//CtxExecConfig      CtxKey = "execConfig"
	CtxKeyRecorder     CtxKey = "recorder"
	CtxKeyModule       CtxKey = "module"
	CtxKeyModuleName   CtxKey = "moduleName"
	CtxKeyModuleKind   CtxKey = "moduleKind"
	CtxKeyFileName     CtxKey = "fileName"
	CtxKeyLevel        CtxKey = "level"
	CtxKeyBlockType    CtxKey = "blockType"
	CtxKeyVarName      CtxKey = "varName"
	CtxKeyVarType      CtxKey = "varType"
	CtxKeyKformContext CtxKey = "kformContext"
)

func (CtxKey) String

func (c CtxKey) String() string

type DependencyBlock

type DependencyBlock interface {
	GetDependencies() map[string]string
	GetModDependencies() map[string]string
	GetContext(string) string
	GetAttributes() *KformBlockAttributes
}

interface signature

type Initializer

type Initializer func() (kfplugin.Provider, error)

func ProviderInitializer

func ProviderInitializer(execPath string) Initializer

ProviderInitializer produces a provider factory that runs up the executable file in the given path and uses go-plugin to implement Provider Interface against it.

type Input

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

func (*Input) GetAttributes

func (r *Input) GetAttributes() *KformBlockAttributes

func (*Input) GetBlockName

func (r *Input) GetBlockName() string

func (*Input) GetBlockType

func (r *Input) GetBlockType() string

func (*Input) GetConfig

func (r *Input) GetConfig() any

func (*Input) GetContext

func (r *Input) GetContext(n string) string

func (*Input) GetDefault

func (r *Input) GetDefault() []any

func (*Input) GetDependencies

func (r *Input) GetDependencies() map[string]string

func (*Input) GetFileName

func (r *Input) GetFileName() string

func (*Input) GetInputParams

func (r *Input) GetInputParams() map[string]any

func (*Input) GetLevel

func (r *Input) GetLevel() int

func (*Input) GetModDependencies

func (r *Input) GetModDependencies() map[string]string

func (*Input) GetModuleName

func (r *Input) GetModuleName() string

func (*Input) GetValue

func (r *Input) GetValue() any

func (*Input) ProcessBlock

func (r *Input) ProcessBlock(ctx context.Context, block *KformBlock) context.Context

type Kform

type Kform struct {
	Blocks []KformBlock `json:"spec" yaml:"spec"`
}

type KformBlock

type KformBlock struct {
	KformBlockContext `json:",inline" yaml:",inline"`
	NestedBlock       map[string]KformBlock `json:",inline" yaml:",inline"`
}

func GetNextBlock

func GetNextBlock(ctx context.Context, block *KformBlock) (string, *KformBlock, error)

type KformBlockAttributes

type KformBlockAttributes struct {
	Schema *KformBlockSchema `json:"schema,omitempty" yaml:"schema,omitempty"`
	Source *string           `json:"source,omitempty" yaml:"source,omitempty"`
	Alias  *string           `json:"alias,omitempty" yaml:"alias,omitempty"`
	// should be an int actually
	Count         *string           `json:"count,omitempty" yaml:"count,omitempty"`
	ForEach       *string           `json:"forEach,omitempty" yaml:"forEach,omitempty"`
	Provider      *string           `json:"provider,omitempty" yaml:"provider,omitempty"`
	Providers     map[string]string `json:"providers,omitempty" yaml:"providers,omitempty"`
	DependsOn     *string           `json:"dependsOn,omitempty" yaml:"dependsOn,omitempty"`
	Description   *string           `json:"description,omitempty" yaml:"description,omitempty"`
	Sensitive     *bool             `json:"sensitive,omitempty" yaml:"sensitive,omitempty"`
	Validation    *string           `json:"validation,omitempty" yaml:"validation,omitempty"`
	Lifecycle     *string           `json:"lifecycle,omitempty" yaml:"lifecycle,omitempty"`
	PreCondition  *string           `json:"preCondition,omitempty" yaml:"preCondition,omitempty"`
	PostCondition *string           `json:"postCondition,omitempty" yaml:"postCondition,omitempty"`
	Provisioner   *string           `json:"provisioner,omitempty" yaml:"provisioner,omitempty"`
	Connection    *string           `json:"connection,omitempty" yaml:"connection,omitempty"`
	Hostname      *string           `json:"hostname,omitempty" yaml:"hostname,omitempty"`
	Organization  *string           `json:"organization,omitempty" yaml:"organization,omitempty"`
	Workspaces    map[string]string `json:"workspaces,omitempty" yaml:"workspaces,omitempty"`
}

func (*KformBlockAttributes) GetSource

func (r *KformBlockAttributes) GetSource() string

type KformBlockContext

type KformBlockContext struct {
	Attributes *KformBlockAttributes `json:"attributes,omitempty" yaml:"attributes,omitempty"`
	//Instances  []any                 `json:"instances,omitempty" yaml:"instances,omitempty"`
	Default []any `json:"default,omitempty" yaml:"default,omitempty"`
	// NOTE: had to change to inputParams as input is a blocktype name
	InputParams map[string]any `json:"inputParams,omitempty" yaml:"inputParams,omitempty"`
	Config      any            `json:"config,omitempty" yaml:"config,omitempty"`
	Value       any            `json:"value,omitempty" yaml:"value,omitempty"`
}

type KformBlockSchema

type KformBlockSchema struct {
	ApiVersion string `json:"apiVersion,omitempty" yaml:"apiVersion,omitempty"`
	Kind       string `json:"kind,omitempty" yaml:"kind,omitempty"`
}

type Local

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

func (*Local) GetAttributes

func (r *Local) GetAttributes() *KformBlockAttributes

func (*Local) GetBlockName

func (r *Local) GetBlockName() string

func (*Local) GetBlockType

func (r *Local) GetBlockType() string

func (*Local) GetConfig

func (r *Local) GetConfig() any

func (*Local) GetContext

func (r *Local) GetContext(n string) string

func (*Local) GetDefault

func (r *Local) GetDefault() []any

func (*Local) GetDependencies

func (r *Local) GetDependencies() map[string]string

func (*Local) GetFileName

func (r *Local) GetFileName() string

func (*Local) GetInputParams

func (r *Local) GetInputParams() map[string]any

func (*Local) GetLevel

func (r *Local) GetLevel() int

func (*Local) GetModDependencies

func (r *Local) GetModDependencies() map[string]string

func (*Local) GetModuleName

func (r *Local) GetModuleName() string

func (*Local) GetValue

func (r *Local) GetValue() any

func (*Local) ProcessBlock

func (r *Local) ProcessBlock(ctx context.Context, block *KformBlock) context.Context

type MetaArgument

type MetaArgument string
const (
	MetaArgumentUnknown MetaArgument = "unknown"
	MetaArgumentSchema  MetaArgument = "schema"
	MetaArgumentSource  MetaArgument = "source"
	//MetaArgumentAlias         MetaArgument = "alias"
	//MetaArgumentAliases       MetaArgument = "aliases"
	MetaArgumentCount         MetaArgument = "count"
	MetaArgumentForEach       MetaArgument = "forEach"
	MetaArgumentProvider      MetaArgument = "provider"
	MetaArgumentProviders     MetaArgument = "providers"
	MetaArgumentDependsOn     MetaArgument = "dependsOn"
	MetaArgumentLifecycle     MetaArgument = "lifecycle"
	MetaArgumentPrecondition  MetaArgument = "precondition"
	MetaArgumentPostcondition MetaArgument = "postcondition"
	MetaArgumentConnection    MetaArgument = "connection"
	MetaArgumentProvisioner   MetaArgument = "provisioner"
	MetaArgumentDescription   MetaArgument = "description"
	MetaArgumentSensitive     MetaArgument = "sensitive"
	MetaArgumentValidation    MetaArgument = "validation"
	MetaArgumentHostname      MetaArgument = "hostname"
	MetaArgumentOrganization  MetaArgument = "organization"
	MetaArgumentWorkspaces    MetaArgument = "workspaces"
)

type Module

type Module struct {
	NSN  cache.NSN
	Kind ModuleKind

	SourceDir string
	Version   string

	Backend *Backend

	ProviderRequirements cache.Cache[kformpkgmetav1alpha1.Provider]
	ProviderConfigs      cache.Cache[*ProviderConfig]

	Inputs      cache.Cache[*Input]
	Locals      cache.Cache[*Local]
	Outputs     cache.Cache[*Output]
	Resources   cache.Cache[*Resource]
	ModuleCalls cache.Cache[*ModuleCall]

	DAG         dag.DAG[*VertexContext]
	ProviderDAG dag.DAG[*VertexContext]
	// contains filtered or unexported fields
}

func NewModule

func NewModule(nsn cache.NSN, kind ModuleKind, recorder recorder.Recorder[diag.Diagnostic]) *Module

func (*Module) GenerateDAG

func (r *Module) GenerateDAG(ctx context.Context, provider bool, unrefed []string)

func (*Module) GetModuleDependencies

func (r *Module) GetModuleDependencies(ctx context.Context) map[string]string

func (*Module) GetProviderRequirements

func (r *Module) GetProviderRequirements(ctx context.Context) map[cache.NSN]kformpkgmetav1alpha1.Provider

func (*Module) GetProvidersFromResources

func (r *Module) GetProvidersFromResources(ctx context.Context) sets.Set[cache.NSN]

func (*Module) ResolveDAGDependencies

func (r *Module) ResolveDAGDependencies(ctx context.Context)

func (*Module) ResolveResource2ProviderConfig

func (r *Module) ResolveResource2ProviderConfig(ctx context.Context)

func (*Module) ValidateChildProviderConfigs

func (r *Module) ValidateChildProviderConfigs(ctx context.Context)

type ModuleCall

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

func (*ModuleCall) GetAttributes

func (r *ModuleCall) GetAttributes() *KformBlockAttributes

func (*ModuleCall) GetBlockName

func (r *ModuleCall) GetBlockName() string

func (*ModuleCall) GetBlockType

func (r *ModuleCall) GetBlockType() string

func (*ModuleCall) GetConfig

func (r *ModuleCall) GetConfig() any

func (*ModuleCall) GetContext

func (r *ModuleCall) GetContext(n string) string

func (*ModuleCall) GetDefault

func (r *ModuleCall) GetDefault() []any

func (*ModuleCall) GetDependencies

func (r *ModuleCall) GetDependencies() map[string]string

func (*ModuleCall) GetFileName

func (r *ModuleCall) GetFileName() string

func (*ModuleCall) GetInputParams

func (r *ModuleCall) GetInputParams() map[string]any

func (*ModuleCall) GetLevel

func (r *ModuleCall) GetLevel() int

func (*ModuleCall) GetModDependencies

func (r *ModuleCall) GetModDependencies() map[string]string

func (*ModuleCall) GetModuleName

func (r *ModuleCall) GetModuleName() string

func (*ModuleCall) GetProviders

func (r *ModuleCall) GetProviders() map[string]string

func (*ModuleCall) GetValue

func (r *ModuleCall) GetValue() any

func (*ModuleCall) ProcessBlock

func (r *ModuleCall) ProcessBlock(ctx context.Context, block *KformBlock) context.Context

type ModuleKind

type ModuleKind = string
const (
	ModuleKindRoot  ModuleKind = "root"
	ModuleKindChild ModuleKind = "child"
)

type Output

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

func (*Output) GetAttributes

func (r *Output) GetAttributes() *KformBlockAttributes

func (*Output) GetBlockName

func (r *Output) GetBlockName() string

func (*Output) GetBlockType

func (r *Output) GetBlockType() string

func (*Output) GetConfig

func (r *Output) GetConfig() any

func (*Output) GetContext

func (r *Output) GetContext(n string) string

func (*Output) GetDefault

func (r *Output) GetDefault() []any

func (*Output) GetDependencies

func (r *Output) GetDependencies() map[string]string

func (*Output) GetFileName

func (r *Output) GetFileName() string

func (*Output) GetInputParams

func (r *Output) GetInputParams() map[string]any

func (*Output) GetLevel

func (r *Output) GetLevel() int

func (*Output) GetModDependencies

func (r *Output) GetModDependencies() map[string]string

func (*Output) GetModuleName

func (r *Output) GetModuleName() string

func (*Output) GetValue

func (r *Output) GetValue() any

func (*Output) ProcessBlock

func (r *Output) ProcessBlock(ctx context.Context, block *KformBlock) context.Context

type Provider

type Provider struct {
	NSN cache.NSN
	//ExecPath string
	Initializer
	Resources       sets.Set[string]
	ReadDataSources sets.Set[string]
	ListDataSources sets.Set[string]
}

func (*Provider) Init

func (r *Provider) Init(ctx context.Context, execpath string, nsn cache.NSN, reqs []v1alpha1.Provider) error

type ProviderConfig

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

func (*ProviderConfig) GetAttributes

func (r *ProviderConfig) GetAttributes() *KformBlockAttributes

func (*ProviderConfig) GetBlockName

func (r *ProviderConfig) GetBlockName() string

func (*ProviderConfig) GetBlockType

func (r *ProviderConfig) GetBlockType() string

func (*ProviderConfig) GetConfig

func (r *ProviderConfig) GetConfig() any

func (*ProviderConfig) GetContext

func (r *ProviderConfig) GetContext(n string) string

func (*ProviderConfig) GetDefault

func (r *ProviderConfig) GetDefault() []any

func (*ProviderConfig) GetDependencies

func (r *ProviderConfig) GetDependencies() map[string]string

func (*ProviderConfig) GetFileName

func (r *ProviderConfig) GetFileName() string

func (*ProviderConfig) GetInputParams

func (r *ProviderConfig) GetInputParams() map[string]any

func (*ProviderConfig) GetLevel

func (r *ProviderConfig) GetLevel() int

func (*ProviderConfig) GetModDependencies

func (r *ProviderConfig) GetModDependencies() map[string]string

func (*ProviderConfig) GetModuleName

func (r *ProviderConfig) GetModuleName() string

func (*ProviderConfig) GetName

func (r *ProviderConfig) GetName() string

func (*ProviderConfig) GetValue

func (r *ProviderConfig) GetValue() any

func (*ProviderConfig) ProcessBlock

func (r *ProviderConfig) ProcessBlock(ctx context.Context, block *KformBlock) context.Context

type Renderer

type Renderer interface {
	GatherDependencies(ctx context.Context, x any) error
	GetDependencies() map[string]string
	GetModuleOutputDependencies() map[string]string
}

func NewRenderer

func NewRenderer() Renderer

type Resource

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

func (*Resource) GetAttributes

func (r *Resource) GetAttributes() *KformBlockAttributes

func (*Resource) GetBlockName

func (r *Resource) GetBlockName() string

func (*Resource) GetBlockType

func (r *Resource) GetBlockType() string

func (*Resource) GetConfig

func (r *Resource) GetConfig() any

func (*Resource) GetContext

func (r *Resource) GetContext(n string) string

func (*Resource) GetDefault

func (r *Resource) GetDefault() []any

func (*Resource) GetDependencies

func (r *Resource) GetDependencies() map[string]string

func (*Resource) GetFileName

func (r *Resource) GetFileName() string

func (*Resource) GetInputParams

func (r *Resource) GetInputParams() map[string]any

func (*Resource) GetLevel

func (r *Resource) GetLevel() int

func (*Resource) GetModDependencies

func (r *Resource) GetModDependencies() map[string]string

func (*Resource) GetModuleName

func (r *Resource) GetModuleName() string

func (*Resource) GetProvider

func (r *Resource) GetProvider() string

func (*Resource) GetValue

func (r *Resource) GetValue() any

func (*Resource) ProcessBlock

func (r *Resource) ProcessBlock(ctx context.Context, block *KformBlock) context.Context

type VertexContext

type VertexContext struct {
	// FileName and Module provide context in which this
	FileName   string
	ModuleName string
	// BlockType determines which function we need to execute
	BlockType BlockType
	// BlockName has syntx <namespace>.<name>
	BlockName string
	// schema relevant for this blockType
	GVK schema.GroupVersionKind
	// provides the contextual data
	BlockContext    KformBlockContext
	Dependencies    map[string]string
	ModDependencies map[string]string
	// only relevaant for blocktype resource and data
	Provider string
	// only relevant for blocktype module
	// can be either a regular DAG or a provider DAG
	DAG dag.DAG[*VertexContext]
}

func (*VertexContext) AddDAG

func (r *VertexContext) AddDAG(d dag.DAG[*VertexContext])

func (*VertexContext) GetBlockDependencies

func (r *VertexContext) GetBlockDependencies() map[string]string

func (*VertexContext) GetDependencies

func (r *VertexContext) GetDependencies() map[string]string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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