Skip to content

brunokino/terratest-terraform-AKS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terraform Azure AKS Example

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.

Prerequisite: Setup Azure CLI access

  1. Sign up for Azure.
  2. Install Azure CLI
  3. Install Terraform and make sure it's on your PATH.
  4. Install kubectl and make sure it's on your PATH.
  5. Login to Azure on the CLI with az login or az login --use-device, and then configure the CLI.

Running this module manually

  1. Create Service Principal then set the value to the environment variables.
  2. Run terraform init
  3. Run terraform apply
  4. Apply nginx-deployment.yml
  5. Watch the service until Public IPAddress is assigned.
  6. Send http request to the Public IPAddress, make sure it returns 200.
  7. When you're done, run terraform destroy.

Example

$ 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

Running automated tests against this module

  1. Create Service Principal then set the value to the environment variables.
  2. Install Golang version 1.13+ required.
  3. cd test
  4. go test -v -timeout 60m -tags azure -run TestTerraformAzureAKS

Example

$ 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published