mkdir $HOME/go/src/tek
cd $HOME/go/src/tek
go run main.go
Last active
April 11, 2019 00:16
-
-
Save nodox/59fa75126e9ac6dc95bbac6a1aceff1b to your computer and use it in GitHub Desktop.
Output terraform file from go template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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