Skip to content

Instantly share code, notes, and snippets.

@nodox nodox/README.md
Last active Apr 11, 2019

Embed
What would you like to do?
Output terraform file from go template
  • mkdir $HOME/go/src/tek
  • cd $HOME/go/src/tek
  • go run main.go
package main
import (
"html/template"
"log"
"os"
)
func check(err error) {
if err != nil {
panic(err)
}
}
func main() {
var myMap = map[string]string{"Name": "email_developers", "Detail": "a policy to email developers"}
const terraform = `
resource "aws_iam_policy" "{{.Name}}_policy" {
name = "{{.Name}}"
description = "{{.Detail}}"
}`
t := template.Must(template.New("t1").
Parse(terraform))
f, err := os.Create("roles.tf")
if err != nil {
log.Println("create file: ", err)
return
}
defer f.Close()
err = t.Execute(f, myMap)
if err != nil {
log.Print("execute: ", err)
return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.