File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
operations/automation-script Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -234,10 +234,20 @@ else
234
234
variables_file=variables.csv
235
235
fi
236
236
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
+
237
245
# Add variables to workspace
238
246
while IFS=' ,' read -r key value category hcl sensitive
239
247
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
241
251
echo " Adding variable $key with value $value in category $category with hcl $hcl and sensitive $sensitive "
242
252
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} " )
243
253
done < ${variables_file}
You can’t perform that action at this time.
0 commit comments