|
| 1 | +#! /bin/bash |
| 2 | + |
| 3 | +############################################################################################################ |
| 4 | +## This script is used by the catalog pipeline to provision a new resource group and cos instance |
| 5 | +## (required as temporary workaround for issue https://github.ibm.com/GoldenEye/issues/issues/15533) |
| 6 | +############################################################################################################ |
| 7 | + |
| 8 | +set -e |
| 9 | + |
| 10 | +DA_DIR="solutions/fully-configurable" |
| 11 | +TERRAFORM_SOURCE_DIR="tests/resources/kp-cos-instance" |
| 12 | +JSON_FILE="${DA_DIR}/catalogValidationValues.json" |
| 13 | +TF_VARS_FILE="terraform.tfvars" |
| 14 | + |
| 15 | +( |
| 16 | + cwd=$(pwd) |
| 17 | + cd ${TERRAFORM_SOURCE_DIR} |
| 18 | + echo "Provisioning new resource group, kms instance and cos instance .." |
| 19 | + terraform init || exit 1 |
| 20 | + # $VALIDATION_APIKEY is available in the catalog runtime |
| 21 | + { |
| 22 | + echo "ibmcloud_api_key=\"${VALIDATION_APIKEY}\"" |
| 23 | + echo "prefix=\"wxai-$(openssl rand -hex 2)\"" |
| 24 | + echo "region=\"us-south\"" |
| 25 | + } >> ${TF_VARS_FILE} |
| 26 | + terraform apply -input=false -auto-approve -var-file=${TF_VARS_FILE} || exit 1 |
| 27 | + |
| 28 | + cos_var_name="existing_cos_instance_crn" |
| 29 | + cos_value=$(terraform output -state=terraform.tfstate -raw cos_crn) |
| 30 | + kms_var_name="existing_kms_instance_crn" |
| 31 | + kms_value=$(terraform output -state=terraform.tfstate -raw key_protect_crn) |
| 32 | + rg_var_name="existing_resource_group_name" |
| 33 | + rg_value=$(terraform output -state=terraform.tfstate -raw resource_group_name) |
| 34 | + |
| 35 | + echo "Appending '${cos_var_name}' and '${kms_var_name}', input variables to ${JSON_FILE}.." |
| 36 | + |
| 37 | + cd "${cwd}" |
| 38 | + jq -r --arg cos_var_name "${cos_var_name}" \ |
| 39 | + --arg cos_value "${cos_value}" \ |
| 40 | + '. + {($cos_var_name): $cos_value}' "${JSON_FILE}" > tmpfile && mv tmpfile "${JSON_FILE}" || exit 1 |
| 41 | + jq -r --arg kms_var_name "${kms_var_name}" \ |
| 42 | + --arg kms_value "${kms_value}" \ |
| 43 | + '. + {($kms_var_name): $kms_value}' "${JSON_FILE}" > tmpfile && mv tmpfile "${JSON_FILE}" || exit 1 |
| 44 | + jq -r --arg rg_var_name "${rg_var_name}" \ |
| 45 | + --arg rg_value "${rg_value}" \ |
| 46 | + '. + {($rg_var_name): $rg_value}' "${JSON_FILE}" > tmpfile && mv tmpfile "${JSON_FILE}" || exit 1 |
| 47 | + |
| 48 | + echo "Pre-validation complete successfully" |
| 49 | +) |
0 commit comments