drift

package
v0.20.4 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2022 License: MPL-2.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EqualAttributes added in v0.15.11

func EqualAttributes(a []interface{}, b []interface{}, alist AttrList) bool

func EqualSets added in v0.15.11

func EqualSets(a []interface{}, b []interface{}) bool

func RenderDriftTable added in v0.15.11

func RenderDriftTable(resName string, resources map[string]*ResourceConfig, cloudName string, alist AttrList, differentIDs, tfRes ResourceList) error

Types

type AttrList added in v0.15.11

type AttrList []Attribute

func (AttrList) SQLs added in v0.15.11

func (a AttrList) SQLs() []string

func (AttrList) TypeOf added in v0.15.11

func (a AttrList) TypeOf(id string) schema.ValueType

type Attribute added in v0.15.11

type Attribute struct {
	ID        string           // Identifier from config
	SQL       string           // SQL expression
	Type      schema.ValueType // Type in DB as reported by provider
	TFName    string           // TF attribute name
	Unordered bool             // True if unordered slice
}

type BaseConfig

type BaseConfig struct {
	WildProvider *ProviderConfig
	Providers    []*ProviderConfig      `hcl:"provider,block"`
	Terraform    *TerraformSourceConfig `hcl:"terraform,block"`
}

func (*BaseConfig) FindProvider added in v0.15.11

func (b *BaseConfig) FindProvider(name string) *ProviderConfig

type Drift

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

func New

func New(logger hclog.Logger) *Drift

func (*Drift) Configure

func (d *Drift) Configure(ctx context.Context, profileConfig hcl.Body, runParams module.ModuleRunParams) error

func (*Drift) ExampleConfig added in v0.15.11

func (d *Drift) ExampleConfig() string

func (*Drift) Execute

func (*Drift) ID

func (d *Drift) ID() string

type IACConfig

type IACConfig struct {
	Type        string   `hcl:"type,optional"`
	Path        string   `hcl:"path,optional"`
	Identifiers []string `hcl:"identifiers,optional"`

	AttributeMap []string `hcl:"attribute_map,optional"`
	// contains filtered or unexported fields
}

type Parser

type Parser struct {
	HCLContext *hcl.EvalContext
	// contains filtered or unexported fields
}

func NewParser

func NewParser(basePath string) *Parser

func (*Parser) Decode

func (p *Parser) Decode(body hcl.Body, diags hcl.Diagnostics) (*BaseConfig, hcl.Diagnostics)

type ProviderConfig

type ProviderConfig struct {
	WildResource *ResourceConfig

	Name            string                     `hcl:"name,label"`
	Resources       map[string]*ResourceConfig `hcl:"resource,block"`
	Version         string                     `hcl:"version,optional"`
	IgnoreResources ResourceSelectors          `hcl:"ignore_resources,optional"`
	CheckResources  ResourceSelectors          `hcl:"check_resources,optional"`
	AccountIDs      []string                   `hcl:"account_ids,optional"`
	// contains filtered or unexported fields
}

type Resource

type Resource struct {
	ID         string            `json:"id"`
	Attributes []interface{}     `json:"-"`
	Tags       map[string]string `json:"-"`
}

type ResourceACL added in v0.15.11

type ResourceACL struct {
	// AllowEnabled determines whether allow list is enabled (Allow contains entries) or not
	AllowEnabled bool
	// Allow contains the allow list for resources
	Allow ResourceSelectors
	// Ignore contains the ignore list for resources
	Ignore ResourceSelectors
}

ResourceACL manages resource allow and ignore lists

func (ResourceACL) HasTagFilters added in v0.15.11

func (r ResourceACL) HasTagFilters() bool

HasTagFilters returns true if the ACL contains tag filters

func (ResourceACL) ShouldSkip added in v0.15.11

func (r ResourceACL) ShouldSkip(resource *Resource) bool

ShouldSkip gets a resource and compares it to the ACL, returning whether the given resource should be skipped or not

type ResourceConfig

type ResourceConfig struct {
	Identifiers       []string `hcl:"identifiers,optional"`
	IgnoreIdentifiers []string `hcl:"ignore_identifiers,optional"`
	Attributes        []string `hcl:"attributes,optional"`
	IgnoreAttributes  []string `hcl:"ignore_attributes,optional"`
	Deep              *bool    `hcl:"deep,optional"`    // Check attributes if true, otherwise just match identifiers
	Filters           []string `hcl:"filters,optional"` // SQL filters to exclude cloud providers default resources
	Sets              []string `hcl:"sets,optional"`    // Unordered list-attributes where item order doesn't matter

	IAC map[iacProvider]*IACConfig
	// contains filtered or unexported fields
}

type ResourceList

type ResourceList []*Resource

func (ResourceList) IDs

func (r ResourceList) IDs(exclude ...*Resource) []string

func (ResourceList) Map added in v0.15.11

func (r ResourceList) Map() map[string][]interface{}

Map returns a map of ID vs. attributes

func (ResourceList) Walk added in v0.15.11

func (r ResourceList) Walk(fn func(*Resource), skipper func(*Resource) bool)

type ResourceSelector added in v0.15.11

type ResourceSelector struct {
	Type string
	ID   *string
	Tags *map[string]string
}

type ResourceSelectors added in v0.15.11

type ResourceSelectors []*ResourceSelector

func (ResourceSelectors) AllInstances added in v0.15.11

func (t ResourceSelectors) AllInstances() bool

func (ResourceSelectors) ByType added in v0.15.11

func (t ResourceSelectors) ByType(resourceType string) ResourceSelectors

func (ResourceSelectors) ContainsInstance added in v0.15.11

func (t ResourceSelectors) ContainsInstance(id string) bool

func (ResourceSelectors) ContainsTags added in v0.15.11

func (t ResourceSelectors) ContainsTags(tags map[string]string) bool

func (ResourceSelectors) HasTags added in v0.15.11

func (t ResourceSelectors) HasTags() bool

type Result

type Result struct {
	Provider     string `json:"provider"`
	ResourceType string `json:"resource_type"`

	// Deep mode
	Different ResourceList `json:"diff,omitempty"`       // Resources don't match fully (id + attributes don't match)
	DeepEqual ResourceList `json:"deep_equal,omitempty"` // Resource exists in both places (attributes match)

	// Shallow mode
	Equal ResourceList `json:"equal,omitempty"` // Resource exists in both places (attributes not checked)

	// Both modes
	Missing ResourceList `json:"missing"` // Missing in cloud provider, defined in iac
	Extra   ResourceList `json:"extra"`   // Exists in cloud provider, not defined in iac
}

func (*Result) String

func (r *Result) String() string

type Results

type Results struct {
	IACName string    `json:"iac"`
	Data    []*Result `json:"data"`

	// Options
	ListManaged bool `json:"-"` // Show or hide Equal/DeepEqual output
	Debug       bool `json:"-"` // Print debug output regarding results

	// These fields are calculated
	Drifted  int     `json:"drifted_res"`
	Covered  int     `json:"covered_res"`
	Total    int     `json:"total_res"`
	Coverage float64 `json:"coverage_pct"`

	Text string `json:"-"`
}

func (*Results) ExitCode added in v0.15.11

func (rs *Results) ExitCode() int

func (*Results) String

func (rs *Results) String() string

type RunParams

type RunParams struct {
	Debug bool

	TfMode      string
	ForceDeep   bool
	ListManaged bool

	IACName    string
	StateFiles []string
}

type TFInstances added in v0.15.11

type TFInstances []terraform.Instance

func (TFInstances) AsResourceList added in v0.15.11

func (r TFInstances) AsResourceList(identifiers []string, alist AttrList, path string) ResourceList

AsResourceList returns a map of resource ID vs. attributes

type TFStates added in v0.15.11

type TFStates []*terraform.Data

func (TFStates) FindType added in v0.15.11

func (t TFStates) FindType(tfType string, tfMode terraform.Mode) TFInstances

FindType returns all instances of the given type under a given mode

type TerraformBackend added in v0.15.11

type TerraformBackend string
const (
	TFLocal TerraformBackend = "local"
	TFS3    TerraformBackend = "s3"
)

func (TerraformBackend) Valid added in v0.15.11

func (t TerraformBackend) Valid() bool

type TerraformSourceConfig added in v0.15.11

type TerraformSourceConfig struct {
	Backend TerraformBackend `hcl:"backend"`

	// S3 backend
	Bucket  string   `hcl:"bucket,optional"`
	Keys    []string `hcl:"keys,optional"`
	Region  string   `hcl:"region,optional"`
	RoleARN string   `hcl:"role_arn,optional"`

	// Local backend
	Files []string `hcl:"files,optional"`
}

func (TerraformSourceConfig) Validate added in v0.15.11

func (c TerraformSourceConfig) Validate() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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