Created
February 21, 2019 18:30
-
-
Save SkYNewZ/37dd08bfcdf026de57d2eaeb83369ea2 to your computer and use it in GitHub Desktop.
Simple script written in Golang to extract all variables of a given .tf file
This file contains 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 ( | |
"regexp" | |
"fmt" | |
"io/ioutil" | |
"os" | |
) | |
func main() { | |
// Get file path | |
filePath := os.Args[1] | |
// Open file | |
bytes, err := ioutil.ReadFile(filePath) | |
// if error while openning | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
// get content as string | |
content := string(bytes) | |
re, _ := regexp.Compile(`(?m)variable "([a-zA-Z_]+)"`) | |
for _, match := range re.FindAllStringSubmatch(content, -1) { | |
fmt.Println(match[1] + " =") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment