tfid

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SafeID

func SafeID(slug string) string

SafeID converts a slug into a terraform-safe name. This is a stateless approach that replaces unsafe characters, and can result in duplicate terraform IDs if there's multiple similar slugs. E.g., foo-bar and foo_bar would both become foo_bar.

Types

type ID

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

ID represents a Terraform ID field. It is a mutually exclusive one-of type of either slug, e.g. "my-bucket", or local Terraform reference, e.g. "chronosphere_bucket.my_bucket.id".

The core Terraform resource providers should always use slugs. Use-cases which generate HCL (e.g. scenario tests and export config) may use local references.

func LocalRef

func LocalRef(r Ref) ID

LocalRef returns a local reference ID.

func Slug

func Slug(slug string) ID

Slug returns a slug ID.

func (ID) LocalRef

func (id ID) LocalRef() Ref

LocalRef unwraps id as a local reference, else panics.

func (ID) Slug

func (id ID) Slug() string

Slug unwraps id as a slug, else panics.

func (ID) Type

func (id ID) Type() Type

Type returns the type of the id.

type Ref

type Ref struct {
	// True if the address is for a datasource and not a resource, i.e. should
	// there be a "data" prefix.
	Datasource bool

	// Resource type, required. E.g. chronosphere_bucket
	Type string

	// Resource id, required. E.g. "foo" for a chronosphere_bucket.foo address.
	ID string

	// Field name, optional, defaults to "id". E.g. "bar" for
	// chronosphere_bucket.things.bar
	Field string
}

Ref contains metadata of a local reference.

func (Ref) AsID

func (r Ref) AsID() ID

AsID is an ergonomic helper for LocalRef.

type Type

type Type int
const (
	// TypeEmpty indicates an uninitialized ID.
	TypeEmpty Type = iota

	// TypeSlug indicates a slug ID.
	TypeSlug

	// TypeLocalRef indicates a local reference ID.
	TypeLocalRef
)

Jump to

Keyboard shortcuts

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