0

Objective: Checking whether a resource group exist in given subscription on Azure with shell script (azure cli command) (runs as part of terraform deployment)

Context: This piece of code runs on a docker based image (Ubuntu). The below is part of my CI pipeline

Code I use:

#!/bin/bash
echo "export ARM_SUBSCRIPTION_ID=${subscriptionid}" >> $BASH_ENV
source $BASH_ENV
printenv
apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo make
apk add py3-pip
pip install azure-cli
az login --service-principal -u $ARM_CLIENT_ID -p $ARM_CLIENT_SECRET --tenant $ARM_TENANT_ID
az account set -s $ARM_SUBSCRIPTION_ID
if [$(az group exists --name *orp*)]; then
    az group create --name test --location westeurope
fi
terraform -chdir=Terraform init -input=false -backend-config="resource_group_name=${TF_RESOURCE_GROUP_NAME}" \
-backend-config="storage_account_name=${TF_STORAGE_ACCOUNT_NAME}" \
-backend-config="container_name=<<pipeline.parameters.clientcode>>" \
-backend-config="key=<<pipeline.parameters.environment>>/${TF_KEY_NAME}" 

Error I get:

./scripts/check.sh: line 10: []: not found 

Can some one suggest what wrong with this ?

I tried with below, then also same error saying bad request.

if [$(az group exists --name *orp*) = false ]; then
    az group create --name test --location eastus
fi

I am trying to use wildcard to search for resource groups that may be available in subscritpion. is this * xxx * is correct pattern to search ?

asp
  • 777
  • 3
  • 14
  • 33

0 Answers0