addrs

package
v2.18.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package addrs contains types that represent "addresses", which are references to specific objects within a Terraform configuration or state.

All addresses have string representations based on HCL traversal syntax which should be used in the user-interface, and also in-memory representations that can be used internally.

For object types that exist within Terraform modules a pair of types is used. The "local" part of the address is represented by a type, and then an absolute path to that object in the context of its module is represented by a type of the same name with an "Abs" prefix added, for "absolute".

All types within this package should be treated as immutable, even if this is not enforced by the Go compiler. It is always an implementation error to modify an address object in-place after it is initially constructed.

Index

Constants

View Source
const (
	// InvalidResourceMode is the zero value of ResourceMode and is not
	// a valid resource mode.
	InvalidResourceMode resourceMode = 0

	// ManagedResourceMode indicates a managed resource, as defined by
	// "resource" blocks in configuration.
	ManagedResourceMode resourceMode = 'M'

	// DataResourceMode indicates a data resource, as defined by
	// "data" blocks in configuration.
	DataResourceMode resourceMode = 'D'
)

Variables

View Source
var NoKey instanceKey

NoKey represents the absense of an instanceKey, for the single instance of a configuration object that does not use "count" or "for_each" at all.

Functions

This section is empty.

Types

type Module

type Module []string

Module is an address for a module call within configuration. This is the static counterpart of ModuleInstance, representing a traversal through the static module call tree in configuration and does not take into account the potentially-multiple instances of a module that might be created by "count" and "for_each" arguments within those calls.

This type should be used only in very specialized cases when working with the static module call tree. Type ModuleInstance is appropriate in more cases.

Although Module is a slice, it should be treated as immutable after creation.

func (Module) UnkeyedInstanceShim

func (m Module) UnkeyedInstanceShim() ModuleInstance

UnkeyedInstanceShim is a shim method for converting a Module address to the equivalent ModuleInstance address that assumes that no modules have keyed instances.

This is a temporary allowance for the fact that Terraform does not presently support "count" and "for_each" on modules, and thus graph building code that derives graph nodes from configuration must just assume unkeyed modules in order to construct the graph. At a later time when "count" and "for_each" support is added for modules, all callers of this method will need to be reworked to allow for keyed module instances.

type ModuleInstance

type ModuleInstance []ModuleInstanceStep

ModuleInstance is an address for a particular module instance within the dynamic module tree. This is an extension of the static traversals represented by type Module that deals with the possibility of a single module call producing multiple instances via the "count" and "for_each" arguments.

Although ModuleInstance is a slice, it should be treated as immutable after creation.

var RootModuleInstance ModuleInstance

RootModuleInstance is the module instance address representing the root module, which is also the zero value of ModuleInstance.

func ParseModuleInstanceStr

func ParseModuleInstanceStr(str string) (ModuleInstance, tfdiags.Diagnostics)

ParseModuleInstanceStr is a helper wrapper around ParseModuleInstance that takes a string and parses it with the HCL native syntax traversal parser before interpreting it.

This should be used only in specialized situations since it will cause the created references to not have any meaningful source location information. If a reference string is coming from a source that should be identified in error messages then the caller should instead parse it directly using a suitable function from the HCL API and pass the traversal itself to ParseProviderConfigCompact.

Error diagnostics are returned if either the parsing fails or the analysis of the traversal fails. There is no way for the caller to distinguish the two kinds of diagnostics programmatically. If error diagnostics are returned then the returned address is invalid.

func (ModuleInstance) Child

func (m ModuleInstance) Child(name string, key instanceKey) ModuleInstance

Child returns the address of a child module instance of the receiver, identified by the given name and key.

func (ModuleInstance) Resource

func (m ModuleInstance) Resource(mode resourceMode, typeName string, name string) absResource

Resource returns the address of a particular resource within the receiver.

func (ModuleInstance) ResourceInstance

func (m ModuleInstance) ResourceInstance(mode resourceMode, typeName string, name string, key instanceKey) absResourceInstance

ResourceInstance returns the address of a particular resource instance within the receiver.

func (ModuleInstance) String

func (m ModuleInstance) String() string

String returns a string representation of the receiver, in the format used within e.g. user-provided resource addresses.

The address of the root module has the empty string as its representation.

type ModuleInstanceStep

type ModuleInstanceStep struct {
	Name        string
	InstanceKey instanceKey
}

ModuleInstanceStep is a single traversal step through the dynamic module tree. It is used only as part of ModuleInstance.

Jump to

Keyboard shortcuts

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