Commit aeb5d4a8 authored by kawsark's avatar kawsark

added logic to delete previous policy-set

parent 8a8c8426
Pipeline #91762145 passed with stages
in 41 seconds
......@@ -22,6 +22,20 @@ then
exit
fi
# Adjust policy set name if needed. If so, please also adjust it in the delete.sh script.
policy_set_name="gitlabci-gcp-policies"
# Check for previous policy set and delete it if it exists
policy_set_id=$(curl --header "Authorization: Bearer ${TFC_TOKEN}" --header "Content-Type: application/vnd.api+json" \
"https://${TFC_ADDR}/api/v2/organizations/${TFC_ORG}/policy-sets?search%5Bname%5D=${policy_set_name}" | jq -r '.data[0].id')
if [ ! -z "policy_set_id" ]
then
echo "Found previous policy set with name: ${policy_set_name} and id: ${policy_set_id}"
echo "Deleting previous policy set."
curl --header "Authorization: Bearer ${TFC_TOKEN}" \
--request DELETE "https://${TFC_ADDR}/api/v2/policy-sets/${policy_set_id}"
fi
# Check if GOOGLE_CREDENTIALS_PATH variable is set
# If so delete existing GOOGLE_CREDENTIALS variable and set the new one
if [ ! -z "$GOOGLE_CREDENTIALS_PATH" ]; then
......
......@@ -21,9 +21,22 @@ then
exit
fi
# Create policy set
d=$(date "+%H%M%S")
sed -e "s/gcp-policies/gcp-policies-$d/" -e "s/my-workspace-id/${workspace_id}/" < ../api_templates/policysets.json.template > policysets.json
# Adjust policy set name if needed. If so, please also adjust it in the delete.sh script.
policy_set_name="gitlabci-gcp-policies"
# Check for previous policy set and delete it if it exists
policy_set_id=$(curl --header "Authorization: Bearer ${TFC_TOKEN}" --header "Content-Type: application/vnd.api+json" \
"https://${TFC_ADDR}/api/v2/organizations/${TFC_ORG}/policy-sets?search%5Bname%5D=${policy_set_name}" | jq -r '.data[0].id')
if [ ! -z "policy_set_id" ]
then
echo "Found previous policy set with name: ${policy_set_name} and id: ${policy_set_id}"
echo "Deleting previous policy set."
curl --header "Authorization: Bearer ${TFC_TOKEN}" \
--request DELETE "https://${TFC_ADDR}/api/v2/policy-sets/${policy_set_id}"
fi
# Create a new policy set
sed -e "s/gcp-policies/${policy_set_name}/" -e "s/my-workspace-id/${workspace_id}/" < ../api_templates/policysets.json.template > policysets.json
curl --header "Authorization: Bearer ${TFC_TOKEN}" \
--header "Content-Type: application/vnd.api+json" \
--request POST --data @policysets.json \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment