Documentation
¶
Index ¶
- Constants
- func BuildContextOptions(dir, varFile string, resolver *ProviderResolver, tsCtx *Context) (*terraform.ContextOpts, tfdiags.Diagnostics)
- func Compare(one, other tfdiags.Diagnostics) int
- func GetPluginFolder() (string, error)
- func InputValuesFromType(values map[string]cty.Value, sourceType terraform.ValueSourceType) terraform.InputValues
- func IsEmptyCollection(value cty.Value) bool
- func IsNull(val cty.Value) bool
- func LoadSchemas(opts *terraform.ContextOpts) (schemas *terraform.Schemas, diags tfdiags.Diagnostics)
- func LookupProviderSchema(schemas *terraform.Schemas, providerType string) (*terraform.ProviderSchema, error)
- func MarshalValue(value cty.Value) []byte
- func Merge(original, override cty.Value) cty.Value
- func PrimitiveValue(val cty.Value) interface{}
- func ProvidersMapFromConfig(cfg configs.Config, schema *terraform.Schemas) map[string]cty.Value
- func ProvisionersFactory() map[string]provisioners.Factory
- type Assert
- type Context
- type FakeResourceCreator
- type Mock
- type MockDataSourceReader
- func (m *MockDataSourceReader) ReadDataSource(typeName string, config cty.Value, providerConfig cty.Value) cty.Value
- func (m *MockDataSourceReader) SetMock(mocks []*Mock)
- func (m *MockDataSourceReader) SetProviderConfig(providerConfigs map[string]cty.Value)
- func (m *MockDataSourceReader) UnmatchedCalls() []cty.Value
- type MockProvisionerInterface
- func (p *MockProvisionerInterface) Close() error
- func (p *MockProvisionerInterface) GetSchema() provisioners.GetSchemaResponse
- func (p *MockProvisionerInterface) ProvisionResource(req provisioners.ProvisionResourceRequest) provisioners.ProvisionResourceResponse
- func (p *MockProvisionerInterface) Stop() error
- func (p *MockProvisionerInterface) ValidateProvisionerConfig(req provisioners.ValidateProvisionerConfigRequest) provisioners.ValidateProvisionerConfigResponse
- type ProviderInterface
- func (m *ProviderInterface) ApplyResourceChange(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse
- func (m *ProviderInterface) Close() error
- func (m *ProviderInterface) Configure(req providers.ConfigureRequest) providers.ConfigureResponse
- func (m *ProviderInterface) GetSchema() providers.GetSchemaResponse
- func (m *ProviderInterface) ImportResourceState(req providers.ImportResourceStateRequest) providers.ImportResourceStateResponse
- func (m *ProviderInterface) PlanResourceChange(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse
- func (m *ProviderInterface) PrepareProviderConfig(req providers.PrepareProviderConfigRequest) providers.PrepareProviderConfigResponse
- func (m *ProviderInterface) ReadDataSource(req providers.ReadDataSourceRequest) providers.ReadDataSourceResponse
- func (m *ProviderInterface) ReadResource(req providers.ReadResourceRequest) providers.ReadResourceResponse
- func (m *ProviderInterface) Stop() error
- func (m *ProviderInterface) UpgradeResourceState(req providers.UpgradeResourceStateRequest) providers.UpgradeResourceStateResponse
- func (m *ProviderInterface) ValidateDataSourceConfig(req providers.ValidateDataSourceConfigRequest) providers.ValidateDataSourceConfigResponse
- func (m *ProviderInterface) ValidateResourceTypeConfig(req providers.ValidateResourceTypeConfigRequest) providers.ValidateResourceTypeConfigResponse
- type ProviderResolver
- type Spec
- type TerraspecConfig
- type TerraspecDiagnostic
- func AssertErrorDiags(path cty.Path, expected, got interface{}) *TerraspecDiagnostic
- func ErrorDiags(path cty.Path, detail string) *TerraspecDiagnostic
- func RejectErrorDiags(path cty.Path, rejected, got interface{}) *TerraspecDiagnostic
- func RejectSuccessDiags(path cty.Path, message string, rejected interface{}) *TerraspecDiagnostic
- func RejectValueErrorDiags(path cty.Path, key, rejected, got cty.Value) *TerraspecDiagnostic
- func SuccessDiags(path cty.Path, value interface{}) *TerraspecDiagnostic
- type TypeName
- type WrappedProviderInterface
- func (w *WrappedProviderInterface) ApplyResourceChange(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse
- func (w *WrappedProviderInterface) Close() error
- func (w *WrappedProviderInterface) Configure(req providers.ConfigureRequest) providers.ConfigureResponse
- func (w *WrappedProviderInterface) GetSchema() providers.GetSchemaResponse
- func (w *WrappedProviderInterface) ImportResourceState(req providers.ImportResourceStateRequest) providers.ImportResourceStateResponse
- func (w *WrappedProviderInterface) PlanResourceChange(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse
- func (w *WrappedProviderInterface) PrepareProviderConfig(req providers.PrepareProviderConfigRequest) providers.PrepareProviderConfigResponse
- func (w *WrappedProviderInterface) ReadDataSource(req providers.ReadDataSourceRequest) providers.ReadDataSourceResponse
- func (w *WrappedProviderInterface) ReadResource(req providers.ReadResourceRequest) providers.ReadResourceResponse
- func (w *WrappedProviderInterface) Stop() error
- func (w *WrappedProviderInterface) UpgradeResourceState(req providers.UpgradeResourceStateRequest) providers.UpgradeResourceStateResponse
- func (w *WrappedProviderInterface) ValidateDataSourceConfig(req providers.ValidateDataSourceConfigRequest) providers.ValidateDataSourceConfigResponse
- func (w *WrappedProviderInterface) ValidateResourceTypeConfig(req providers.ValidateResourceTypeConfigRequest) providers.ValidateResourceTypeConfigResponse
Constants ¶
const Info tfdiags.Severity = 'I'
Info is an additional Severity level to display Info messages
Variables ¶
This section is empty.
Functions ¶
func BuildContextOptions ¶
func BuildContextOptions(dir, varFile string, resolver *ProviderResolver, tsCtx *Context) (*terraform.ContextOpts, tfdiags.Diagnostics)
BuildContextOptions creates a new terraform.ContextOpts ready for instanciating a terraform Context It returns the built ContextOpts or a Diagnostics if error occured
func Compare ¶
func Compare(one, other tfdiags.Diagnostics) int
Compare returns the difference in error numbers between one and other if result == 0, then the 2 diagnostics have same number of errors if result < 0, one has less error than other if result > 0, one has more error than other
func GetPluginFolder ¶
GetPluginFolder tries to compute the user plugin folder for the current user. For windows: %APPDATA%/terraform.d/plugins For linux: ~/terraform.d/plugins
func InputValuesFromType ¶
func InputValuesFromType(values map[string]cty.Value, sourceType terraform.ValueSourceType) terraform.InputValues
InputValuesFromType converts a map of values file into InputValues with the given SourceType
func IsEmptyCollection ¶
IsEmptyCollection returns true if value is a collection type of length 0
func LoadSchemas ¶
func LoadSchemas(opts *terraform.ContextOpts) (schemas *terraform.Schemas, diags tfdiags.Diagnostics)
LoadSchemas load all the schema required to parse hcl configs
func LookupProviderSchema ¶
func LookupProviderSchema(schemas *terraform.Schemas, providerType string) (*terraform.ProviderSchema, error)
LookupProviderSchema searches for the schema matching the given type in the collection of known schemas
func MarshalValue ¶
MarshalValue serializes a cty.Value in hcl format
func Merge ¶
Merge returns a new cty.Value whose attributes are set with values from override if present, or from original
func PrimitiveValue ¶
PrimitiveValue will return the implied value if it's a primitive type Number will be returned as int If a non primitive is given, nil will be returned
func ProvidersMapFromConfig ¶
func ProvisionersFactory ¶
func ProvisionersFactory() map[string]provisioners.Factory
ProvisionersFactory return a map of mock provisioners as provisioners are not meant to be called in the context of terraspec
Types ¶
type Assert ¶
Assert struct contains the definition of an assertion
type Context ¶
type Context struct { TerraformVersion *goversion.Version UserVersion *goversion.Version ConfigureProvider bool WorkaroundOnce sync.Once }
Context struct holds terraspec options and internal state
type FakeResourceCreator ¶
type FakeResourceCreator struct {
// contains filtered or unexported fields
}
FakeResourceCreator can fake a resource creation by setting all resource attributes as defined in an assertion
func (*FakeResourceCreator) GetFake ¶
GetFake return the attributes to set to the resource terraspec fakes to create
func (*FakeResourceCreator) SetFakes ¶
func (f *FakeResourceCreator) SetFakes(fakes []*Assert)
SetFakes populates fake data
type Mock ¶
type Mock struct { TypeName Query cty.Value Data cty.Value Body []byte ProviderAlias string // contains filtered or unexported fields }
Mock struct contains the definition of mocked data resources
func NewMock ¶
NewMock is a convenient method to instanciate a new Mock struct with given parameters
type MockDataSourceReader ¶
type MockDataSourceReader struct {
// contains filtered or unexported fields
}
MockDataSourceReader can mock a call to ReadDataSource and return appropriate mocked data
func (*MockDataSourceReader) ReadDataSource ¶
func (m *MockDataSourceReader) ReadDataSource(typeName string, config cty.Value, providerConfig cty.Value) cty.Value
ReadDataSource returns a mock response for the datasource call
func (*MockDataSourceReader) SetMock ¶
func (m *MockDataSourceReader) SetMock(mocks []*Mock)
SetMock populates mock data
func (*MockDataSourceReader) SetProviderConfig ¶
func (m *MockDataSourceReader) SetProviderConfig(providerConfigs map[string]cty.Value)
SetProviderConfig populates mock data
func (*MockDataSourceReader) UnmatchedCalls ¶
func (m *MockDataSourceReader) UnmatchedCalls() []cty.Value
UnmatchedCalls returns the list of all data source calls that were not mocked
type MockProvisionerInterface ¶
type MockProvisionerInterface struct { }
MockProvisionerInterface is a NoOp implementation of terraform's provisioners.Interface
func (*MockProvisionerInterface) Close ¶
func (p *MockProvisionerInterface) Close() error
Close shuts down the plugin process if applicable.
func (*MockProvisionerInterface) GetSchema ¶
func (p *MockProvisionerInterface) GetSchema() provisioners.GetSchemaResponse
GetSchema returns the schema for the provisioner configuration.
func (*MockProvisionerInterface) ProvisionResource ¶
func (p *MockProvisionerInterface) ProvisionResource(req provisioners.ProvisionResourceRequest) provisioners.ProvisionResourceResponse
ProvisionResource runs the provisioner with provided configuration. ProvisionResource blocks until the execution is complete. If the returned diagnostics contain any errors, the resource will be left in a tainted state.
func (*MockProvisionerInterface) Stop ¶
func (p *MockProvisionerInterface) Stop() error
Stop is called to interrupt the provisioner.
Stop should not block waiting for in-flight actions to complete. It should take any action it wants and return immediately acknowledging it has received the stop request. Terraform will not make any further API calls to the provisioner after Stop is called.
The error returned, if non-nil, is assumed to mean that signaling the stop somehow failed and that the user should expect potentially waiting a longer period of time.
func (*MockProvisionerInterface) ValidateProvisionerConfig ¶
func (p *MockProvisionerInterface) ValidateProvisionerConfig(req provisioners.ValidateProvisionerConfigRequest) provisioners.ValidateProvisionerConfigResponse
ValidateProvisionerConfig allows the provisioner to validate the configuration values.
type ProviderInterface ¶
type ProviderInterface struct {
// contains filtered or unexported fields
}
ProviderInterface implements providers.Interface for the purpose of testing described config
func (*ProviderInterface) ApplyResourceChange ¶
func (m *ProviderInterface) ApplyResourceChange(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse
ApplyResourceChange takes the planned state for a resource, which may yet contain unknown computed values, and applies the changes returning the final state.
func (*ProviderInterface) Close ¶
func (m *ProviderInterface) Close() error
Close shuts down the plugin process if applicable.
func (*ProviderInterface) Configure ¶
func (m *ProviderInterface) Configure(req providers.ConfigureRequest) providers.ConfigureResponse
Configure configures and initialized the provider.
func (*ProviderInterface) GetSchema ¶
func (m *ProviderInterface) GetSchema() providers.GetSchemaResponse
GetSchema returns the complete schema for the provider.
func (*ProviderInterface) ImportResourceState ¶
func (m *ProviderInterface) ImportResourceState(req providers.ImportResourceStateRequest) providers.ImportResourceStateResponse
ImportResourceState requests that the given resource be imported.
func (*ProviderInterface) PlanResourceChange ¶
func (m *ProviderInterface) PlanResourceChange(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse
PlanResourceChange takes the current state and proposed state of a resource, and returns the planned final state.
func (*ProviderInterface) PrepareProviderConfig ¶
func (m *ProviderInterface) PrepareProviderConfig(req providers.PrepareProviderConfigRequest) providers.PrepareProviderConfigResponse
PrepareProviderConfig allows the provider to validate the configuration values, and set or override any values with defaults.
func (*ProviderInterface) ReadDataSource ¶
func (m *ProviderInterface) ReadDataSource(req providers.ReadDataSourceRequest) providers.ReadDataSourceResponse
ReadDataSource returns the data source's current state.
func (*ProviderInterface) ReadResource ¶
func (m *ProviderInterface) ReadResource(req providers.ReadResourceRequest) providers.ReadResourceResponse
ReadResource refreshes a resource and returns its current state.
func (*ProviderInterface) Stop ¶
func (m *ProviderInterface) Stop() error
Stop is called when the provider should halt any in-flight actions.
Stop should not block waiting for in-flight actions to complete. It should take any action it wants and return immediately acknowledging it has received the stop request. Terraform will not make any further API calls to the provider after Stop is called.
The error returned, if non-nil, is assumed to mean that signaling the stop somehow failed and that the user should expect potentially waiting a longer period of time.
func (*ProviderInterface) UpgradeResourceState ¶
func (m *ProviderInterface) UpgradeResourceState(req providers.UpgradeResourceStateRequest) providers.UpgradeResourceStateResponse
UpgradeResourceState is called when the state loader encounters an instance state whose schema version is less than the one reported by the currently-used version of the corresponding provider, and the upgraded result is used for any further processing.
func (*ProviderInterface) ValidateDataSourceConfig ¶
func (m *ProviderInterface) ValidateDataSourceConfig(req providers.ValidateDataSourceConfigRequest) providers.ValidateDataSourceConfigResponse
ValidateDataSourceConfig allows the provider to validate the data source configuration values.
func (*ProviderInterface) ValidateResourceTypeConfig ¶
func (m *ProviderInterface) ValidateResourceTypeConfig(req providers.ValidateResourceTypeConfigRequest) providers.ValidateResourceTypeConfigResponse
ValidateResourceTypeConfig allows the provider to validate the resource configuration values.
type ProviderResolver ¶
type ProviderResolver struct { KnownPlugins map[addrs.Provider]discovery.PluginMeta DataSourceReader *MockDataSourceReader ResourceCreator *FakeResourceCreator ConfigureProvider bool }
ProviderResolver is reponsible for finding all provider implementations that can be instanciated
func BuildProviderResolver ¶
func BuildProviderResolver(dir string, configureProvider bool) (*ProviderResolver, error)
BuildProviderResolver returns a ProviderResolver able to find all providers provided by plugins
func (*ProviderResolver) ResolveProviders ¶
func (r *ProviderResolver) ResolveProviders() map[addrs.Provider]providers.Factory
ResolveProviders returns a map of factory capable of instanciating the required plugin to serve the provider
type Spec ¶
type Spec struct { Asserts []*Assert Rejects []*TypeName Mocks []*Mock DataSourceReader *MockDataSourceReader Terraspec *TerraspecConfig }
Spec struct contains the assertions described in .tfspec file
func ParseSpec ¶
ParseSpec parses the spec contained in the []byte parameter and returns the resulting Spec or a Diagnostics if error occured in the process
func ReadSpec ¶
ReadSpec reads the .tfspec file and returns the resulting Spec or a Diagnostics if error occured in the process
func (*Spec) Validate ¶
Validate checks all the assertions of this Spec against the given terraform Plan. It return all failed assertion in a Diagnostics and an error if a technical error happened while testing the plan
func (*Spec) ValidateMocks ¶
func (s *Spec) ValidateMocks() tfdiags.Diagnostics
ValidateMocks checks all mocks were called as expected
type TerraspecConfig ¶
type TerraspecConfig struct {
Workspace string
}
TerraspecConfig is a global element for a spec with common configuration similar to terraform hcl element.
type TerraspecDiagnostic ¶
type TerraspecDiagnostic struct {
tfdiags.Diagnostic
}
TerraspecDiagnostic is an assertion diagnostic, either a success or error
func AssertErrorDiags ¶
func AssertErrorDiags(path cty.Path, expected, got interface{}) *TerraspecDiagnostic
AssertErrorDiags returns a diagnostic at Error level to indicate the user a given assertion failed
func ErrorDiags ¶
func ErrorDiags(path cty.Path, detail string) *TerraspecDiagnostic
ErrorDiags returns a diagnostic at Error level with given error message
func RejectErrorDiags ¶
func RejectErrorDiags(path cty.Path, rejected, got interface{}) *TerraspecDiagnostic
RejectErrorDiags returns a diagnostic at Error level to indicate the user a given reject assertion failed
func RejectSuccessDiags ¶
func RejectSuccessDiags(path cty.Path, message string, rejected interface{}) *TerraspecDiagnostic
RejectSuccessDiags returns a diagnostic at Info level to indicate the user a given reject assertion succeeded
func RejectValueErrorDiags ¶
func RejectValueErrorDiags(path cty.Path, key, rejected, got cty.Value) *TerraspecDiagnostic
RejectValueErrorDiags returns a diagnostic at Error level toi indicate the user a reject assertion failed
func SuccessDiags ¶
func SuccessDiags(path cty.Path, value interface{}) *TerraspecDiagnostic
SuccessDiags creates a diagnostic at Info level to indicate the user a given assertion matches
type WrappedProviderInterface ¶
type WrappedProviderInterface struct {
// contains filtered or unexported fields
}
WrappedProviderInterface implements providers.Interface by wrapping a true provider.Interface and only call allowed method
func (*WrappedProviderInterface) ApplyResourceChange ¶
func (w *WrappedProviderInterface) ApplyResourceChange(req providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse
ApplyResourceChange takes the planned state for a resource, which may yet contain unknown computed values, and applies the changes returning the final state.
func (*WrappedProviderInterface) Close ¶
func (w *WrappedProviderInterface) Close() error
Close shuts down the plugin process if applicable.
func (*WrappedProviderInterface) Configure ¶
func (w *WrappedProviderInterface) Configure(req providers.ConfigureRequest) providers.ConfigureResponse
Configure configures and initialized the provider.
func (*WrappedProviderInterface) GetSchema ¶
func (w *WrappedProviderInterface) GetSchema() providers.GetSchemaResponse
GetSchema returns the complete schema for the provider.
func (*WrappedProviderInterface) ImportResourceState ¶
func (w *WrappedProviderInterface) ImportResourceState(req providers.ImportResourceStateRequest) providers.ImportResourceStateResponse
ImportResourceState requests that the given resource be imported.
func (*WrappedProviderInterface) PlanResourceChange ¶
func (w *WrappedProviderInterface) PlanResourceChange(req providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse
PlanResourceChange takes the current state and proposed state of a resource, and returns the planned final state.
func (*WrappedProviderInterface) PrepareProviderConfig ¶
func (w *WrappedProviderInterface) PrepareProviderConfig(req providers.PrepareProviderConfigRequest) providers.PrepareProviderConfigResponse
PrepareProviderConfig allows the provider to validate the configuration values, and set or override any values with defaults.
func (*WrappedProviderInterface) ReadDataSource ¶
func (w *WrappedProviderInterface) ReadDataSource(req providers.ReadDataSourceRequest) providers.ReadDataSourceResponse
ReadDataSource returns the data source's current state.
func (*WrappedProviderInterface) ReadResource ¶
func (w *WrappedProviderInterface) ReadResource(req providers.ReadResourceRequest) providers.ReadResourceResponse
ReadResource refreshes a resource and returns its current state.
func (*WrappedProviderInterface) Stop ¶
func (w *WrappedProviderInterface) Stop() error
Stop is called when the provider should halt any in-flight actions.
Stop should not block waiting for in-flight actions to complete. It should take any action it wants and return immediately acknowledging it has received the stop request. Terraform will not make any further API calls to the provider after Stop is called.
The error returned, if non-nil, is assumed to mean that signaling the stop somehow failed and that the user should expect potentially waiting a longer period of time.
func (*WrappedProviderInterface) UpgradeResourceState ¶
func (w *WrappedProviderInterface) UpgradeResourceState(req providers.UpgradeResourceStateRequest) providers.UpgradeResourceStateResponse
UpgradeResourceState is called when the state loader encounters an instance state whose schema version is less than the one reported by the currently-used version of the corresponding provider, and the upgraded result is used for any further processing.
func (*WrappedProviderInterface) ValidateDataSourceConfig ¶
func (w *WrappedProviderInterface) ValidateDataSourceConfig(req providers.ValidateDataSourceConfigRequest) providers.ValidateDataSourceConfigResponse
ValidateDataSourceConfig allows the provider to validate the data source configuration values.
func (*WrappedProviderInterface) ValidateResourceTypeConfig ¶
func (w *WrappedProviderInterface) ValidateResourceTypeConfig(req providers.ValidateResourceTypeConfigRequest) providers.ValidateResourceTypeConfigResponse
ValidateResourceTypeConfig allows the provider to validate the resource configuration values.