tfstate

package module
v0.0.0-...-cd0c9da Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2020 License: MIT Imports: 5 Imported by: 0

README

tfstate add-on package

This package extends config.Loader and provides functions to reference Terform tfstate values

Usage

tfstate pakcage include MustLoad and Load. for example: config.yaml has the following content

aws_account_id: '{{ tfstate "data.aws_caller_identity.current.account_id" }}'
vpc_id: '{{ tfstate "aws_vpc.main.id" }}'

The code to load this configuration is as follows:

package main

import (
    "fmt"

	"github.com/kayac/go-config"
	"github.com/kayac/go-config/tfstate"
)

func main() {
	loader := config.New()
	loader.Funcs(tfstate.MustLoad("./testdata/terraform.tfstate"))
	var c map[string]string
	if err := loader.LoadWithEnv(&c, "./config.yaml"); err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(c["aws_account_id"])
}

Load tfstate from local file.

Note

./testdata/terraform.tfstate is the same data as testdata used in https://github.com/fujiwara/tfstate-lookup

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(stateFile string) (template.FuncMap, error)

Load tfstate based on URL and provide tamplate.FuncMap

func LoadWithName

func LoadWithName(name string, stateFile string) (template.FuncMap, error)

LoadWithName provides tamplate.FuncMap. can lockup values from tfstate.

func MustLoad

func MustLoad(stateURL string) template.FuncMap

MustLoad is similar to Load, but panics if it cannot get and parse tfstate. Simplifies registration with config.Loader

Example
loader := config.New()
loader.Funcs(tfstate.MustLoad("./testdata/terraform.tfstate"))
var c map[string]string
if err := loader.LoadWithEnv(&c, "./testdata/config.yaml"); err != nil {
	fmt.Println(err)
	return
}
fmt.Println(c["aws_account_id"])
fmt.Println(c["log_group"])
Output:

123456789012
/main/app

func MustLoadWithName

func MustLoadWithName(name string, stateURL string) template.FuncMap

MustLoadWithName is similar to LoadWithName, but panics if it cannot get and parse tfstate. Simplifies registration with config.Loader

Types

This section is empty.

Jump to

Keyboard shortcuts

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