No description
Find a file
Alexander Redinger 3e5760e34e
Merge pull request #23 from hashicorp/avoid_panic
minimal update to avoid panic from go-yaml
2025-04-15 13:18:19 -04:00
.github Update workflow go version 2025-04-08 09:40:46 -04:00
address.go Initial check-in 2020-07-28 13:54:29 -07:00
address.peg Initial check-in 2020-07-28 13:54:29 -07:00
address_ast.go [COMPLIANCE] Add Copyright and License Headers 2024-12-02 16:27:03 +00:00
address_test.go [COMPLIANCE] Add Copyright and License Headers 2024-12-02 16:27:03 +00:00
CODEOWNERS Update CODEOWNERS (#22) 2024-11-27 07:23:53 -08:00
gen.go [COMPLIANCE] Add Copyright and License Headers 2024-12-02 16:27:03 +00:00
go.mod tidy up 2025-03-20 14:45:57 -04:00
go.sum tidy up 2025-03-20 14:45:57 -04:00
LICENSE [COMPLIANCE] Update MPL 2.0 LICENSE 2022-10-12 21:00:05 +00:00
README.md Update README.md 2021-05-06 13:38:13 -07:00

tf-address

CircleCI

This package provides utilities for properly parsing Terraform addresses.

The parser is implemented using pigeon, a PEG implementation.

Addresses

Resource addresses are described by the Terraform documentation.

Identifiers are described in the Terraform Configuration Syntax document

Generating

If you change the peg, please regenerate the go code with:

go get -u github.com/mna/pigeon
go generate .

You may need to clean up the go.mod with:

go mod tidy

Examples

package main

import (
	"fmt"

	address "github.com/hashicorp/go-terraform-address"
)

func main() {

	a, err := address.NewAddress(`module.first.module.second["xyz"].resource.name[2]`)
	if err != nil {
		panic(err)
	}

	fmt.Println(len(a.ModulePath))                  // 2
	fmt.Println(a.ModulePath[0].Name)               // "first"
	fmt.Println(a.ModulePath[1].Index.String())     // "xyz"
	fmt.Printf("%T\n", a.ModulePath[1].Index.Value) // string
	fmt.Println(a.ResourceSpec.Type)                // "resource"
	fmt.Println(a.ResourceSpec.Name)                // "name"
	fmt.Printf("%T\n", a.ResourceSpec.Index.Value)  // int
}