Documentation
¶
Overview ¶
Package terraform includes functionality related to reading Terraform plan files. The plan schema is defined here according to the JSON output format described at https://www.terraform.io/docs/internals/json-format.html
The found resources are then transformed into query.Resource that can be utilized further.
Index ¶
- Variables
- func ExtractQueriesFromHCL(fs afero.Fs, providerInitializers []ProviderInitializer, modPath string, ...) ([]query.Resource, string, error)
- type Configuration
- type ConfigurationModule
- type ConfigurationResource
- type Module
- type Plan
- type Provider
- type ProviderConfig
- type ProviderConfigExpression
- type ProviderInitializer
- type Resource
- type State
- type Values
- type Variable
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoQueries = errors.New("no terraform entities found, looks empty") ErrNoKnownProvider = errors.New("terraform providers are not yet supported") ErrNoProviders = errors.New("no valid providers found") )
Errors that might be returned from procesing the HCL
Functions ¶
func ExtractQueriesFromHCL ¶ added in v0.3.0
func ExtractQueriesFromHCL(fs afero.Fs, providerInitializers []ProviderInitializer, modPath string, u usage.Usage, inputs map[string]interface{}) ([]query.Resource, string, error)
ExtractQueriesFromHCL returns the resources found in the module identified by the modPath.
Types ¶
type Configuration ¶
type Configuration struct { ProviderConfig map[string]ProviderConfig `json:"provider_config"` RootModule ConfigurationModule `json:"root_module"` }
Configuration is a Terraform plan configuration.
type ConfigurationModule ¶
type ConfigurationModule struct { Resources []ConfigurationResource `json:"resources"` Variables map[string]Variable `json:"variables"` ModuleCalls map[string]struct { Module *ConfigurationModule `json:"module"` } `json:"module_calls"` }
ConfigurationModule is used to configure a module.
type ConfigurationResource ¶
type ConfigurationResource struct { Address string `json:"address"` ProviderConfigKey string `json:"provider_config_key"` // Expressions are really similar to the ProviderConfigExpression but we cannot use it (as map[string]ProviderConfigExpression) // as some examples do not match, some are not map[string]ProviderConfigExpression but map[string][]interface{} and some constant_value are not // string but other types Expressions map[string]interface{} `json:"expressions"` }
ConfigurationResource is used to configure a single reosurce.
type Module ¶
type Module struct { Address string `json:"address"` Resources []Resource `json:"resources"` ChildModules []*Module `json:"child_modules"` }
Module is a collection of resources.
type Plan ¶
type Plan struct { Configuration Configuration `json:"configuration"` PriorState *State `json:"prior_state"` PlannedValues Values `json:"planned_values"` Variables map[string]Variable `json:"variables"` // contains filtered or unexported fields }
Plan is a representation of a Terraform plan file.
func NewPlan ¶
func NewPlan(providerInitializers ...ProviderInitializer) *Plan
NewPlan returns an empty Plan.
func (*Plan) ExtractPlannedQueries ¶
ExtractPlannedQueries extracts a query.Resource slice from the `planned_values` part of the Plan.
func (*Plan) ExtractPriorQueries ¶
ExtractPriorQueries extracts a query.Resource slice from the `prior_state` part of the Plan.
type Provider ¶
type Provider interface { // Name returns the common name of this Provider. Name() string // ResourceComponents returns price component queries for the given Resource. Nil may be returned // which signifies a resource that is not supported by this Provider. // It also expects all the resources in case it needs to check the configuration of another // resource ResourceComponents(rss map[string]Resource, res Resource) []query.Component }
Provider represents a Terraform provider. It extracts price queries from Terraform resources.
type ProviderConfig ¶
type ProviderConfig struct { Name string `json:"name"` Alias string `json:"alias"` Expressions map[string]ProviderConfigExpression `json:"expressions"` }
ProviderConfig is configuration of a provider with the given Name.
func (*ProviderConfig) UnmarshalJSON ¶ added in v0.5.0
func (cfg *ProviderConfig) UnmarshalJSON(b []byte) error
UnmarshalJSON handles the logic of Unmarshaling a ProviderConfig as we have some edge cases we want to not unmarshal as they are not standard/needed and would make things more complex
type ProviderConfigExpression ¶
type ProviderConfigExpression struct { ConstantValue string `json:"constant_value" mapstructure:"constant_value"` References []string `json:"references" mapstructure:"references"` }
ProviderConfigExpression is a single configuration variable of a ProviderConfig.
type ProviderInitializer ¶
type ProviderInitializer struct { // MatchNames contains the names that this ProviderInitializer will match. Most providers will only // have one name (such as `aws`) but some might use multiple names to refer to the same provider // implementation (such as `google` and `google-beta`). MatchNames []string // Provider initializes a Provider instance given the values defined in the config and returns it. // If a provider must be ignored (related to version constraints, etc), please return nil to avoid using it. Provider func(values map[string]interface{}) (Provider, error) }
ProviderInitializer is used to initialize a Provider for each provider name that matches one of the MatchNames.
type Resource ¶
type Resource struct { Address string `json:"address"` // This value is 99% of the time an integer, but it can also be // a string, the implementation on TF side is of 'addrs.InstanceKey' // which can be of type 'IntKey' or 'StringKey' Index interface{} `json:"index"` Mode string `json:"mode"` Type string `json:"type"` Name string `json:"name"` ProviderName string `json:"provider_name"` Values map[string]interface{} `json:"values"` }
Resource is a single Terraform resource definition.
type State ¶
type State struct {
Values Values `json:"values"`
}
State is a collection of resource modules.