Skip to content

Commit 5cec1fb

Browse files
committed
special chars in vars
1 parent 2089440 commit 5cec1fb

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

operations/automation-script/loadAndRunWorkspace.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,20 @@ else
234234
variables_file=variables.csv
235235
fi
236236

237+
# Function to process special characters in sed
238+
escape_string()
239+
{
240+
printf '%s' "$1" | sed -e 's/\([&\]\)/\\\1/g'
241+
}
242+
243+
sedDelim=$(printf '\001')
244+
237245
# Add variables to workspace
238246
while IFS=',' read -r key value category hcl sensitive
239247
do
240-
sed -e "s/my-organization/$organization/" -e "s/my-workspace/${workspace}/" -e "s/my-key/$key/" -e "s/my-value/$value/" -e "s/my-category/$category/" -e "s/my-hcl/$hcl/" -e "s/my-sensitive/$sensitive/" < variable.template.json > variable.json
248+
fixedkey=$(escape_string "$key")
249+
fixedvalue=$(escape_string "$value")
250+
sed -e "s/my-organization/$organization/" -e "s/my-workspace/${workspace}/" -e "s${sedDelim}my-key${sedDelim}$fixedkey${sedDelim}" -e "s${sedDelim}my-value${sedDelim}$fixedvalue${sedDelim}" -e "s/my-category/$category/" -e "s/my-hcl/$hcl/" -e "s/my-sensitive/$sensitive/" < variable.template.json | sed -e 's|\\|\\\\|g' > variable.json
241251
echo "Adding variable $key with value $value in category $category with hcl $hcl and sensitive $sensitive"
242252
upload_variable_result=$(curl -s --header "Authorization: Bearer $TFE_TOKEN" --header "Content-Type: application/vnd.api+json" --data @variable.json "https://${address}/api/v2/vars?filter%5Borganization%5D%5Bname%5D=${organization}&filter%5Bworkspace%5D%5Bname%5D=${workspace}")
243253
done < ${variables_file}

0 commit comments

Comments
 (0)