tfschema

package
v0.7.9 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2024 License: MIT Imports: 22 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAttributes

func NewAttributes(as map[string]*configschema.Attribute) map[string]*Attribute

NewAttributes creates a new map of Attributes.

func NewBlockTypes

func NewBlockTypes(bs map[string]*configschema.NestedBlock) map[string]*NestedBlock

NewBlockTypes creates a new map of NestedBlocks.

Types

type Attribute

type Attribute struct {
	// Type is a type of the attribute's value.
	// Note that Type is not cty.Type to customize string representation.
	Type Type `json:"type"`
	// Required is a flag whether this attribute is required.
	Required bool `json:"required"`
	// Optional is a flag whether this attribute is optional.
	// This field conflicts with Required.
	Optional bool `json:"optional"`
	// Computed is a flag whether this attribute is computed.
	// If true, the value may come from provider rather than configuration.
	// If combined with Optional, then the config may optionally provide an
	// overridden value.
	Computed bool `json:"computed"`
	// Sensitive is a flag whether this attribute may contain sensitive information.
	Sensitive bool `json:"sensitive"`
}

Attribute is wrapper for configschema.Attribute.

func NewAttribute

func NewAttribute(a *configschema.Attribute) *Attribute

NewAttribute creates a new Attribute instance.

type Block

type Block struct {
	// Attributes is a map of any attributes.
	Attributes map[string]*Attribute `json:"attributes"`
	// BlockTypes is a map of any nested block types.
	BlockTypes map[string]*NestedBlock `json:"block_types"`
}

Block is wrapper for configschema.Block. This ia a layer for customization not enough for Terraform's core. Most of the structure is the smae as the core, but some are different.

func NewBlock

func NewBlock(b *configschema.Block) *Block

NewBlock creates a new Block instance.

type Client

type Client interface {
	// GetProviderSchema returns a type definiton of provider schema.
	GetProviderSchema() (*Block, error)

	// GetResourceTypeSchema returns a type definiton of resource type.
	GetResourceTypeSchema(resourceType string) (*Block, error)

	// GetDataSourceSchema returns a type definiton of data source.
	GetDataSourceSchema(dataSource string) (*Block, error)

	// ResourceTypes returns a list of resource types.
	ResourceTypes() ([]string, error)

	// DataSources returns a list of data sources.
	DataSources() ([]string, error)

	// Close closes a connection and kills a process of the plugin.
	Close()
}

Client represents a set of methods required to get a type definition of schema from Terraform providers. This is a compatibility layer for supporting multiple Terraform versions.

func NewClient

func NewClient(providerName string, options Option) (Client, error)

NewClient creates a new Client instance.

func NewGRPCClient added in v0.3.0

func NewGRPCClient(providerName string, options Option) (Client, error)

NewGRPCClient creates a new GRPCClient instance.

type GRPCClient added in v0.3.0

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

GRPCClient implements Client interface. This implementaion is for Terraform v0.12+.

func (*GRPCClient) Close added in v0.3.0

func (c *GRPCClient) Close()

Close closes a connection and kills a process of the plugin.

func (*GRPCClient) DataSources added in v0.3.0

func (c *GRPCClient) DataSources() ([]string, error)

DataSources returns a list of data sources.

func (*GRPCClient) GetDataSourceSchema added in v0.3.0

func (c *GRPCClient) GetDataSourceSchema(dataSource string) (*Block, error)

GetDataSourceSchema returns a type definiton of data source.

func (*GRPCClient) GetProviderSchema added in v0.3.0

func (c *GRPCClient) GetProviderSchema() (*Block, error)

GetProviderSchema returns a type definiton of provider schema.

func (*GRPCClient) GetResourceTypeSchema added in v0.3.0

func (c *GRPCClient) GetResourceTypeSchema(resourceType string) (*Block, error)

GetResourceTypeSchema returns a type definiton of resource type.

func (*GRPCClient) ResourceTypes added in v0.3.0

func (c *GRPCClient) ResourceTypes() ([]string, error)

ResourceTypes returns a list of resource types.

type Lock added in v0.6.0

type Lock struct {
	// A list of providers.
	Providers []Provider `hcl:"provider,block"`
	// The rest of body we don't need.
	Remain hcl.Body `hcl:",remain"`
}

Lock represents a lock file written in HCL.

type NestedBlock

type NestedBlock struct {
	// Block is a nested child block.
	Block
	// Nesting is a nesting mode.
	Nesting configschema.NestingMode `json:"nesting"`
	// MinItems is a lower limit on number of nested child blocks.
	MinItems int `json:"min_items"`
	// MaxItems is a upper limit on number of nested child blocks.
	MaxItems int `json:"max_items"`
}

NestedBlock is wrapper for configschema.NestedBlock

func NewNestedBlock

func NewNestedBlock(b *configschema.NestedBlock) *NestedBlock

NewNestedBlock creates a new NestedBlock instance.

type Option added in v0.5.0

type Option struct {
	RootDir string
	Logger  hclog.Logger
}

Option is an options struct for extra options for NewClient

type Provider added in v0.6.0

type Provider struct {
	// A fully qualified provider name. (e.g. registry.terraform.io/hashicorp/aws)
	Address string `hcl:"address,label"`
	// A selected version.
	Version string `hcl:"version"`
	// The rest of body we don't need.
	Remain hcl.Body `hcl:",remain"`
}

Provider represents a provider block in HCL.

type Type

type Type struct {
	// We embed cty.Type to customize string representation.
	cty.Type
}

Type is a type of the attribute's value.

func NewType

func NewType(t cty.Type) *Type

NewType creates a new Type instance.

func (*Type) MarshalJSON

func (t *Type) MarshalJSON() ([]byte, error)

MarshalJSON returns a encoded string in JSON.

func (*Type) Name

func (t *Type) Name() string

Name returns a name of type. Terraform v0.12 introduced a new `SchemaConfigModeAttr` feature. Most attributes have simple types, but if `SchemaConfigModeAttr` is set for an attribute, it is syntactically NestedBlock but semantically interpreted as an Attribute. In this case, Attribute has a complex data type. It is reasonable to use the same notation as the type annotation in HCL2 to represent the correct data type. So we use typeexpr.TypeString(cty.Type) in HCL2

See also: - https://github.com/minamijoyo/tfschema/issues/9 - https://github.com/terraform-providers/terraform-provider-aws/pull/8187 - https://github.com/hashicorp/terraform/pull/20626 - https://www.terraform.io/docs/configuration/types.html

Jump to

Keyboard shortcuts

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