terraformutils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ClosingBracketRegexp = regexp.MustCompile(`.?\\>`)
View Source
var ErrNoSchema = errors.New("resource has no schema")

ErrNoSchema means a resource was loaded from a plan file, which does not carry the provider schema; the legacy printer handles those.

View Source
var OpeningBracketRegexp = regexp.MustCompile(`.?\\<`)

Functions

func ConnectServices

func ConnectServices(importResources map[string][]Resource, isServicePath bool, resourceConnections map[string]map[string][]string) map[string][]Resource

func ContainsResource

func ContainsResource(s []Resource, e Resource) bool

func FilterCleanup

func FilterCleanup(s *Service, isInitial bool)

func FixInvalidConfig

func FixInvalidConfig(resources []*Resource, v ConfigValidator)

FixInvalidConfig asks the provider to validate every generated resource and drops the optional arguments it rejects. State written by the legacy plugin SDK holds zero values for arguments that were never set, and writing those back breaks rules the schema does not expose ("conflicts with", "all of ... must be specified"). Dropping an optional argument leaves it to the provider, which reads it back as the same zero value.

func HclPrintResource

func HclPrintResource(resources []Resource, providerData map[string]interface{}, output string, sort bool) ([]byte, error)

Print hcl file from TerraformResource + provider

func IgnoreKeys

func IgnoreKeys(resourcesTypes []string, p *providerwrapper.ProviderWrapper) map[string][]string

func ItemValue

func ItemValue(item map[string]interface{}, b *schema.Block) (cty.Value, error)

ItemValue converts a generated resource body into a value of the schema's type, the form providers validate. Interpolations such as "${aws_vpc.main.id}" become unknown values, as they are during `plan`.

func LinkByID

func LinkByID(resources []*Resource)

LinkByID replaces literal IDs of other generated resources with references, so that the configuration keeps the relationships between objects: `vpc_id = aws_vpc.tfer--vpc-1.id` instead of a hard-coded ID.

Only arguments named "*_id" or "*_ids" are considered, and only exact matches of another resource's ID; an ID shared by two resources is left alone because the reference would be ambiguous.

func ParseFilterValues

func ParseFilterValues(value string) []string

func Print

func Print(data interface{}, mapsObjects map[string]struct{}, format string, sort bool) ([]byte, error)

func RefreshResourceWorker

func RefreshResourceWorker(input chan *Resource, wg *sync.WaitGroup, provider *providerwrapper.ProviderWrapper)

func RefreshResourcesByProvider

func RefreshResourcesByProvider(providersMapping *ProvidersMapping, providerWrapper *providerwrapper.ProviderWrapper) error

func TfSanitize

func TfSanitize(name string) string

Sanitize name for terraform style

func WalkAndCheckField

func WalkAndCheckField(path string, data interface{}) bool

func WalkAndGet

func WalkAndGet(path string, data interface{}) []interface{}

func WalkAndOverride

func WalkAndOverride(path, oldValue, newValue string, data interface{})

func WriteResourcesHCL

func WriteResourcesHCL(resources []Resource) ([]byte, error)

WriteResourcesHCL renders resources as HCL using the provider schema to tell nested blocks from arguments. Terraformer's printer guessed from the data and wrote maps inside blocks as labelled blocks (for example `selector "match_labels" { ... }` for Kubernetes), which does not parse.

String values are HCL template source, as everywhere in Item: "${...}" is an interpolation and "$${" a literal "${". A value that is exactly one interpolation, such as "${aws_vpc.main.id}", is written as a bare expression.

Types

type ApplicableFilter

type ApplicableFilter interface {
	IsApplicable(resourceName string) bool
}

type BaseResource

type BaseResource struct {
	Tags map[string]string `json:"tags,omitempty"`
}

type ConfigValidator

type ConfigValidator interface {
	GetSchema() *schema.Provider
	ValidateResourceConfig(typeName string, config cty.Value) ([]plugin.Diagnostic, error)
}

ConfigValidator is what FixInvalidConfig needs from a running provider.

type FlatmapParser

type FlatmapParser struct {
	Flatmapper
	// contains filtered or unexported fields
}

func NewFlatmapParser

func NewFlatmapParser(attributes map[string]string, ignoreKeys []*regexp.Regexp, allowEmptyValues []*regexp.Regexp) *FlatmapParser

func (*FlatmapParser) Parse

func (p *FlatmapParser) Parse(ty cty.Type) (map[string]interface{}, error)

FromFlatmap converts a map compatible with what would be produced by the "flatmap" package to a map[string]interface{} object type.

The intended result type must be provided in order to guide how the map contents are decoded. This must be an object type or this function will panic.

Flatmap values can only represent maps when they are of primitive types, so the given type must not have any maps of complex types or the result is undefined.

The result may contain null values if the given map does not contain keys for all of the different key paths implied by the given type.

type Flatmapper

type Flatmapper interface {
	Parse(ty cty.Type) (map[string]interface{}, error)
}

type Provider

type Provider struct {
	Service ServiceGenerator
	Config  cty.Value
}

func (*Provider) GenerateFiles

func (p *Provider) GenerateFiles()

func (*Provider) GenerateOutputPath

func (p *Provider) GenerateOutputPath() error

func (*Provider) GetBasicConfig

func (p *Provider) GetBasicConfig() cty.Value

func (*Provider) GetConfig

func (p *Provider) GetConfig() cty.Value

func (*Provider) GetName

func (p *Provider) GetName() string

func (*Provider) GetService

func (p *Provider) GetService() ServiceGenerator

func (*Provider) GetSupportedService

func (p *Provider) GetSupportedService() map[string]ServiceGenerator

func (*Provider) Init

func (p *Provider) Init(args []string) error

func (*Provider) InitService

func (p *Provider) InitService(serviceName string) error

type ProviderGenerator

type ProviderGenerator interface {
	Init(args []string) error
	InitService(serviceName string, verbose bool) error
	GetName() string
	GetService() ServiceGenerator
	GetConfig() cty.Value
	GetBasicConfig() cty.Value
	GetSupportedService() map[string]ServiceGenerator
	GenerateFiles()
	GetProviderData(arg ...string) map[string]interface{}
	GenerateOutputPath() error
	GetResourceConnections() map[string]map[string][]string
}

type ProviderWithSource

type ProviderWithSource interface {
	GetSource() string
}

type ProvidersMapping

type ProvidersMapping struct {
	Resources map[*Resource]bool
	Services  map[string]bool
	Providers map[ProviderGenerator]bool
	// contains filtered or unexported fields
}

func NewProvidersMapping

func NewProvidersMapping(baseProvider ProviderGenerator) *ProvidersMapping

func (*ProvidersMapping) AddServiceToProvider

func (p *ProvidersMapping) AddServiceToProvider(service string) ProviderGenerator

func (*ProvidersMapping) CleanupProviders

func (p *ProvidersMapping) CleanupProviders()

func (*ProvidersMapping) ConvertTFStates

func (p *ProvidersMapping) ConvertTFStates(providerWrapper *providerwrapper.ProviderWrapper)

func (*ProvidersMapping) GetBaseProvider

func (p *ProvidersMapping) GetBaseProvider() ProviderGenerator

func (*ProvidersMapping) GetResourcesByService

func (p *ProvidersMapping) GetResourcesByService() map[string][]Resource

func (*ProvidersMapping) GetServices

func (p *ProvidersMapping) GetServices() []string

func (*ProvidersMapping) MatchProvider

func (p *ProvidersMapping) MatchProvider(resource *Resource) ProviderGenerator

func (*ProvidersMapping) ProcessResources

func (p *ProvidersMapping) ProcessResources(isCleanup bool)

func (*ProvidersMapping) RemoveServices

func (p *ProvidersMapping) RemoveServices(services []string)

func (*ProvidersMapping) SetResources

func (p *ProvidersMapping) SetResources(resourceToKeep []*Resource)

func (*ProvidersMapping) ShuffleResources

func (p *ProvidersMapping) ShuffleResources() []*Resource

type Resource

type Resource struct {
	InstanceInfo      *legacy.InstanceInfo
	InstanceState     *legacy.InstanceState
	Outputs           map[string]*legacy.OutputState `json:",omitempty"`
	ResourceName      string
	Provider          string
	Item              map[string]interface{} `json:",omitempty"`
	IgnoreKeys        []string               `json:",omitempty"`
	AllowEmptyValues  []string               `json:",omitempty"`
	AdditionalFields  map[string]interface{} `json:",omitempty"`
	SlowQueryRequired bool
	DataFiles         map[string][]byte
	// Schema is the provider schema of the resource type, set while the
	// state is converted. It is not saved in plan files.
	Schema *schema.Block `json:"-"`
	// ZeroValueKeys are patterns for keys to leave out when their value is
	// "0"; see providerwrapper.GetZeroNumberAttributes.
	ZeroValueKeys []string `json:",omitempty"`
	// ImportID is the ID an `import` block needs when it differs from the
	// ID the provider keeps in state. Empty means the state ID works.
	ImportID string `json:",omitempty"`
}

func NewResource

func NewResource(id, resourceName, resourceType, provider string,
	attributes map[string]string,
	allowEmptyValues []string,
	additionalFields map[string]interface{}) Resource

func NewSimpleResource

func NewSimpleResource(id, resourceName, resourceType, provider string, allowEmptyValues []string) Resource

func RefreshResources

func RefreshResources(resources []*Resource, provider *providerwrapper.ProviderWrapper, slowProcessingResources [][]*Resource) ([]*Resource, error)

func (*Resource) ConvertTFstate

func (r *Resource) ConvertTFstate(provider *providerwrapper.ProviderWrapper) error

func (Resource) GetIDKey

func (r Resource) GetIDKey() string

func (*Resource) GetImportID

func (r *Resource) GetImportID() string

GetImportID returns the ID to put in the resource's import block.

func (*Resource) ParseTFstate

func (r *Resource) ParseTFstate(parser Flatmapper, impliedType cty.Type) error

func (*Resource) Refresh

func (r *Resource) Refresh(provider *providerwrapper.ProviderWrapper)

func (*Resource) ServiceName

func (r *Resource) ServiceName() string

type ResourceFilter

type ResourceFilter struct {
	ApplicableFilter
	ServiceName      string
	FieldPath        string
	AcceptableValues []string
}

func (*ResourceFilter) Filter

func (rf *ResourceFilter) Filter(resource Resource) bool

func (*ResourceFilter) IsApplicable

func (rf *ResourceFilter) IsApplicable(serviceName string) bool

type Service

type Service struct {
	Name         string
	Resources    []Resource
	ProviderName string
	Args         map[string]interface{}
	Filter       []ResourceFilter
	Verbose      bool
}

func (*Service) GetArgs

func (s *Service) GetArgs() map[string]interface{}

func (*Service) GetName

func (s *Service) GetName() string

func (*Service) GetProviderName

func (s *Service) GetProviderName() string

func (*Service) GetResources

func (s *Service) GetResources() []Resource

func (*Service) InitResources

func (s *Service) InitResources() error

func (*Service) InitialCleanup

func (s *Service) InitialCleanup()

func (*Service) ParseFilter

func (s *Service) ParseFilter(rawFilter string) []ResourceFilter

func (*Service) ParseFilters

func (s *Service) ParseFilters(rawFilters []string)

func (*Service) PopulateIgnoreKeys

func (s *Service) PopulateIgnoreKeys(providerWrapper *providerwrapper.ProviderWrapper)

func (*Service) PostConvertHook

func (s *Service) PostConvertHook() error

func (*Service) PostRefreshCleanup

func (s *Service) PostRefreshCleanup()

func (*Service) SetArgs

func (s *Service) SetArgs(args map[string]interface{})

func (*Service) SetName

func (s *Service) SetName(name string)

func (*Service) SetProviderName

func (s *Service) SetProviderName(providerName string)

func (*Service) SetResources

func (s *Service) SetResources(resources []Resource)

func (*Service) SetVerbose

func (s *Service) SetVerbose(verbose bool)

type ServiceGenerator

type ServiceGenerator interface {
	InitResources() error
	GetResources() []Resource
	SetResources(resources []Resource)
	ParseFilter(rawFilter string) []ResourceFilter
	ParseFilters(rawFilters []string)
	PostConvertHook() error
	GetArgs() map[string]interface{}
	SetArgs(args map[string]interface{})
	SetName(name string)
	SetVerbose(bool)
	SetProviderName(name string)
	GetProviderName() string
	GetName() string
	InitialCleanup()
	PopulateIgnoreKeys(*providerwrapper.ProviderWrapper)
	PostRefreshCleanup()
}

Directories

Path Synopsis
Package providerwrapper runs one provider plugin for an import and hides the plugin protocol behind the flatmap-based API the importers expect.
Package providerwrapper runs one provider plugin for an import and hides the plugin protocol behind the flatmap-based API the importers expect.

Jump to

Keyboard shortcuts

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