I have file variables.tf:
variable "do_token" {
description = "set DO token value"
type = string
}
variable "ssh_pub_key_fingerprint" {
description = "Set ssh key fingerprint stored in DO"
type = string
}
...
and i want to write script for export variables names with desctiptions like comment, to file terraform.tfvars. But first line must be #description, and second line variable with empty value and double quotes, like this:
cat terraform.tfvars
#set DO token value
do_token = ""
#Set ssh key fingerprint stored in DO
ssh_pub_key_fingerprint = ""
I tryed write bash script test.sh like this:
#!/bin/bash
echo -n "" > test.txt
grep 'description\|variable' variables.tf | while read line; do
OUTPUT=$(echo $line | sed 's/ =//g; s/ {//g' );
# echo $OUTPUT
case "$OUTPUT" in
*description*)
DESCRIPTION=$(echo $OUTPUT | awk -F "\"" '{print $2}')
echo "#"$DESCRIPTION >> terraform.tfvars
;;
*variable*)
VARIABLE=$(echo $OUTPUT | awk -F "\"" '{print $2}')
echo $VARIABLE " = \"\"">> terraform.tfvars
;;
esac
done
but when i show file terraform.tfvars values line is a 1st, and description line 2nd but must be conversely
do_token = ""
#set DO token value
ssh_pub_key_fingerprint = ""
#Set ssh key fingerprint stored in DO
how i can do this properly? Thanks