Skip to content

Instantly share code, notes, and snippets.

@brucedkyle
Last active May 23, 2020 20:11
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save brucedkyle/6bd88a9c1be6dff0e23b9c049468a611 to your computer and use it in GitHub Desktop.
set environment variables for Terraform
## Requires jq .. to install see: https://stedolan.github.io/jq/download/
# set some environment variables to use to create the service principal
export SUBSCRIPTION_ID=3464892e-e827-4752-bad5-b4f93c00dbbe
export PROJECT_NAME="wus2-azure-aks-terraform-demo"
az account set --subscription="${SUBSCRIPTION_ID}"
# create the service principal to the subscription scope and save it to an auth file
TF_SERVICE_PRINCIPAL=$(az ad sp create-for-rbac --skip-assignment --role 'Contributor' --name rbac-tf-$PROJECT_NAME --output json --scopes="/subscriptions/${SUBSCRIPTION_ID}")
export ARM_SUBSCRIPTION_ID=$SUBSCRIPTION_ID
export ARM_CLIENT_ID=$(echo $TF_SERVICE_PRINCIPAL | jq '.appId')
export ARM_CLIENT_SECRET=$(echo $TF_SERVICE_PRINCIPAL | jq '.password')
export ARM_TENANT_ID=$(echo $TF_SERVICE_PRINCIPAL | jq '.tenant')
# Not needed for public, required for usgovernment, german, china
export ARM_ENVIRONMENT=public
ssh-keygen -t rsa -b 4096 -m PEM
# display the public key
cat $HOME/.ssh/id_rsa.pub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment