Skip to content

Instantly share code, notes, and snippets.

@vfarcic
Created September 9, 2020 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vfarcic/c5c927c6ac19f0bff37f87b3679cbf78 to your computer and use it in GitHub Desktop.
Save vfarcic/c5c927c6ac19f0bff37f87b3679cbf78 to your computer and use it in GitHub Desktop.
# Source: https://gist.github.com/c5c927c6ac19f0bff37f87b3679cbf78
#################################################################################################################################
# Applying GitOps And Continuous Delivery (CD) On Infrastructure Using Terraform, Codefresh, And Azure Kubernetes Service (AKS) #
#################################################################################################################################
####################
# Getting The Code #
####################
open https://github.com/vfarcic/cf-terraform-aks
# Replace `[...]` with the GitHub organization
export GH_ORG=[...]
git clone https://github.com/$GH_ORG/cf-terraform-aks
cd cf-terraform-aks
cp orig/*.tf .
cp orig/codefresh.yml .
#####################################
# Setting Up A Azure Resource Group #
#####################################
az login
az group create \
--name devops-catalog-aks \
--location eastus
az account list
export ARM_SUBSCRIPTION_ID=[...]
az account set -s $ARM_SUBSCRIPTION_ID
export SERVICE_PRINCIPAL=$(\
az ad sp create-for-rbac \
--role="Contributor" \
--scopes="/subscriptions/$ARM_SUBSCRIPTION_ID")
echo $SERVICE_PRINCIPAL
export ARM_TENANT_ID=$(
echo $SERVICE_PRINCIPAL | \
jq ".tenant")
export ARM_CLIENT_ID=$(
echo $SERVICE_PRINCIPAL | \
jq ".appId")
export ARM_CLIENT_SECRET=$(
echo $SERVICE_PRINCIPAL | \
jq ".password")
echo "export ARM_SUBSCRIPTION_ID=$ARM_SUBSCRIPTION_ID
export ARM_TENANT_ID=$ARM_TENANT_ID
export ARM_CLIENT_ID=$ARM_CLIENT_ID
export ARM_CLIENT_SECRET=$ARM_CLIENT_SECRET
" | tee creds
source creds
###################################
# Preparing Terraform Definitions #
###################################
az storage account create \
--name devopscatalog \
--resource-group devops-catalog-aks \
--location eastus \
--sku Standard_LRS
az storage container create \
--name devopscatalog \
--resource-group devops-catalog-aks \
--account-name devopscatalog \
--public-access blob
cat variables.tf
az aks get-versions --location eastus
# Replace `[...]` with any of the `orchestratorVersion`
export VERSION=[...]
cat variables.tf \
| sed -e "s@CHANGE_VERSION@$VERSION@g" \
| tee variables.tf
cat main.tf
cat output.tf
git add .
git commit -m "Initial commit"
git push
###########################################
# Defining A Continuous Delivery Pipeline #
###########################################
cat codefresh.yml
###############################################
# Creating And Configuring Codefresh Pipeline #
###############################################
open https://codefresh.io/
echo $ARM_SUBSCRIPTION_ID
echo $ARM_TENANT_ID
echo $ARM_CLIENT_ID
echo $ARM_CLIENT_SECRET
#######################################
# Applying Infrastructure Definitions #
#######################################
terraform init
terraform refresh
export KUBECONFIG=$PWD/kubeconfig
az aks get-credentials \
--name \
$(terraform output cluster_name) \
--resource-group \
$(terraform output resource_group) \
--file \
$KUBECONFIG
kubectl get nodes
############################################################
# Using Pull Requests To Preview Changes To Infrastructure #
############################################################
git checkout -b destroy
git add .
git commit -m "Destroying everything"
git push \
--set-upstream origin destroy
open https://github.com/$GH_ORG/cf-terraform-aks
git checkout master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment