In this step, you'll learn how to create an AKS cluster using GitHub Actions. The code can be found here
Prior to running the pipeline, you'll need to set up authentication from GitHub to Azure. To do that, you'll setup an Azure Service Principal.
Using the below Azure cli (!!! Important: write the Secret):
az ad sp create-for-rbac --name msdlcpeakit004
Alternatively - this can be done via Azure Portal
You'll need both the clientID of the service principal and secret that was created.
Note: The Service Principal needs IAM permission to the subscription/resource group to where the Azure resources are deployed. In this example, I gave contributor access to the subscription.
You'll be adding 4 secrets into the GitHub repository. These four secrets will allow you to connect to Azure from GitHub Actions.
- In the code repository, go to Settings --> Secrets
- Add to Github the Azure SP secrets:
AZURE_AD_CLIENT_ID
– Will be the service principal ID from aboveAZURE_AD_CLIENT_SECRET
– The secret that was created as part of the Azure Service PrincipalAZURE_AD_TENANT_ID
– The Azure AD tenant ID to where the service principal was createdAZURE_SUBSCRIPTION_ID
– Subscription ID of where you want to deploy the Terraform
- Add to Github the Azure Container Registry credentials
ACR_USERNAME
- usernameACR_PASSWORD
- password
- Save all the secrets
Now that the secrets are created, it's time to create the pipeline.
- Under the GitHub repository, click on the Actions tab
- You will see a workflow already called
CI
- Select
CI
workflow and then selectRun workflow
from
main branch
The pipeline does a few things:
- On line 4, you'll see
workflow_dispatch
, which means the pipeline won't automatically run unless you kick it off. You can of course change this to have the pipeline automatically run if you, for example, push code to themain
branch. - The code is checked-out
- Authentication occurs to Azure
- Terraform is set up
- Terraform format occurs
- Terraform init occurs
- Terraform plan occurs
- Terraform apply occurs
- Run the pipeline and watch as the pipeline automatically creates the AKS cluster