depgen

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2019 License: BSD-3-Clause Imports: 25 Imported by: 0

Documentation

Overview

Package depgen extracts resource dependency information from Terraform provider documentation and test files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attr

type Attr struct {
	AttrSchema

	Key     string
	Type    string
	Name    string
	Simple  []*Val
	Complex []*Val
}

Attr contains all discovered values for one attribute. Attr may refer to a nested attribute within the type (e.g. "attr1.attr2.attr3"). Simple values are those composed of exactly one managed resource interpolation, such as "${resource_type.name.attr}". Complex values may include literal text, multiple interpolations, function calls, etc. These can normally be ignored for the purposes of dependency inference, but sometimes may require provider-specific logic to generate the correct DepSpec.

func (*Attr) Explain

func (t *Attr) Explain() string

Explain returns a string explaining why this attribute should not be included in a DepMap.

func (*Attr) Keep

func (t *Attr) Keep()

Keep hides all but the first simple value from view, allowing the attribute to be included in a DepMap if there are no other problems.

func (*Attr) String

func (t *Attr) String() string

String implements fmt.Stringer.

type AttrMap

type AttrMap map[string]*Attr

AttrMap associates attributes of one resource type with their interpolated values.

type AttrSchema

type AttrSchema struct {
	Resource *schema.Resource
	Schema   *schema.Schema
	Hier     []*schema.Schema
}

AttrSchema describes the schema of a resource attribute. Hier will contain multiple schemas for nested attributes.

func (*AttrSchema) IsScalar

func (s *AttrSchema) IsScalar() bool

IsScalar returns true if s refers to exactly one value. It returns false if the attribute is part of a list or set, or if it refers to a map without an explicit key.

func (*AttrSchema) IsString

func (s *AttrSchema) IsString() bool

IsString returns true if s refers to a string attribute.

type Model

type Model struct {
	Out     string
	Sources []string
	Pkg     string
	MapVar  string
	DepMap  tfx.DepMap
}

Model is passed to a template to generate Go source code for the dependency map.

func (*Model) DepMapType

func (m *Model) DepMapType() reflect.Type

DepMapType returns tfx.DepMap type.

func (*Model) Write

func (m *Model) Write()

Write generates Go source code from the model and writes the output to m.Out.

type Parser

type Parser struct {
	Provider *schema.Provider
	Sources  []string
	TypeMap  map[string]AttrMap
	// contains filtered or unexported fields
}

Parser extracts interpolated attribute values from HCL examples.

func (*Parser) Apply

func (p *Parser) Apply(rules map[string]bool) *Parser

Apply removes or keeps attributes in p.TypeMap by looking up rules in a map. Keys may be "<type>.<attr>", "<type>", or ".<attr>", with lookups performed in that order. First match wins.

func (*Parser) Call

func (p *Parser) Call(fn func(*Attr) bool) *Parser

Call calls fn for each attribute in p.TypeMap and removes those for which fn returns false.

func (*Parser) Model

func (p *Parser) Model() *Model

Model converts parsed attribute information into a dependency map.

func (*Parser) Parse

func (p *Parser) Parse(fn func() tf.ResourceProvider) *Parser

Parse calls ParseDir on the module root directory of the specified provider.

func (*Parser) ParseDir

func (p *Parser) ParseDir(root string) *Parser

ParseDir recursively parses all supported file types in the specified directory. It may be called multiple times for different roots.

func (*Parser) Schema

func (p *Parser) Schema(typ, attr string) (s AttrSchema)

Schema returns the schema of the specified resource attribute ("type.name").

type Val

type Val struct {
	AttrSchema

	File string
	Raw  string
	Type string
	Attr string
	Root *hast.Output
}

Val is an attribute value that contains interpolations. AttrSchema, Type, and Attr are set only for simple interpolations.

func NewVal

func NewVal(file, raw string) (*Val, error)

NewVal parses a HashiCorp Interpolation Language (HIL) string and returns a new Val if it contains at least one interpolated resource expression.

func (*Val) IsSimple

func (v *Val) IsSimple() bool

IsSimple returns true for values with just one resource interpolation.

func (*Val) String

func (v *Val) String() string

String implements fmt.Stringer.

Jump to

Keyboard shortcuts

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