🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

github.com/hashicorp/go-terraform-address

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/hashicorp/go-terraform-address

v0.0.0-20250415171819-3e5760e34e4a
Source
Go
Version published
Created
Source

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
}

FAQs

Package last updated on 15 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts