This folder contains a Terraform module that deploys a basic AKS cluster in Azure to demonstrate how you can use Terratest to write automated tests for your Azure Terraform code.
This module deploys Azure Kubenetes Service, then deploys nginx by a kubernetes yaml file with a Public IP Address using the Service
resource.
Check out test/azure/terraform_azure_aks_example_test.go to see how you can write automated tests for this module and validate the configuration of the parameters and options.
WARNING: This module and the automated tests for it deploy real resources into your Azure account which can cost you money.
- Sign up for Azure.
- Install Azure CLI
- Install Terraform and make sure it's on your
PATH
. - Install kubectl and make sure it's on your
PATH
. - Login to Azure on the CLI with
az login
oraz login --use-device
, and then configure the CLI.
- Create Service Principal then set the value to the environment variables.
- Run
terraform init
- Run
terraform apply
- Apply
nginx-deployment.yml
- Watch the service until Public IPAddress is assigned.
- Send http request to the Public IPAddress, make sure it returns 200.
- When you're done, run
terraform destroy
.
$ az login
$ export ARM_SUBSCRIPTION_ID={YOUR_SUBSCRIPTION_ID}
$ az ad sp create-for-rbac
$ export TF_VAR_client_id={YOUR_SERVICE_PRINCIPAL_APP_ID}
$ export TF_VAR_client_secret={YOUR_SERVICE_PRINCIPAL_PASSWORD}
$ terraform init
$ terraform apply
$ kubectl --kubeconfig ./kubeconfig create -f ./nginx-deployment.yml
$ kubectl --kubeconfig ./kubeconfig get svc -w
// Open browser and access the Nginx Service IPAddress
$ terraform destroy
- Create Service Principal then set the value to the environment variables.
- Install Golang version
1.13+
required. cd test
go test -v -timeout 60m -tags azure -run TestTerraformAzureAKS
$ az login
$ export ARM_SUBSCRIPTION_ID={YOUR_SUBSCRIPTION_ID}
$ export TF_VAR_client_id={YOUR_SERVICE_PRINCIPAL_APP_ID}
$ export TF_VAR_client_secret={YOUR_SERVICE_PRINCIPAL_PASSWORD}
$ cd test
$ go test -v -timeout 60m -tags azure -run TestTerraformAzureAKS