github.com/terraform-modules-krish/terratest@v0.29.0/examples/terraform-azure-aks-example/README.md (about)

     1  # Terraform Azure AKS Example
     2  
     3  This folder contains a Terraform module that deploys a basic AKS cluster in [Azure](https://azure.microsoft.com/) to demonstrate how you can use Terratest to write automated tests for your Azure Terraform code. 
     4  
     5  This module deploys [Azure Kubenetes Service](https://azure.microsoft.com/en-us/services/kubernetes-service/), then deploys nginx by a kubernetes yaml file with a Public IP Address using the `Service` resource.
     6  
     7  Check out [test/terraform_azure_aks_example_test.go](https://github.com/terraform-modules-krish/terratest/blob/v0.29.0/test/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. 
     8  
     9  **WARNING**: This module and the automated tests for it deploy real resources into your Azure account which can cost you money. 
    10  
    11  ## Prerequisite: Setup Azure CLI access
    12  1. Sign up for [Azure](https://azure.microsoft.com/).
    13  1. Install [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest)
    14  1. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH`.
    15  1. Install [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) and make sure it's on your `PATH`.
    16  1. Login to Azure on the CLI with `az login` or `az login --use-device`, and then configure the CLI.
    17  
    18  ## Running this module manually
    19  1. Create [Service Principal](https://docs.microsoft.com/en-us/cli/azure/create-an-azure-service-principal-azure-cli?view=azure-cli-latest) then set the value to the environment variables. 
    20  1. Run `terraform init`
    21  1. Run `terraform apply`
    22  1. Apply `nginx-deployment.yml`
    23  1. Watch the service until Public IPAddress is assigned.
    24  1. Send http request to the Public IPAddress, make sure it returns 200.
    25  1. When you're done, run `terraform destroy`.
    26  
    27  ### Example
    28  
    29  ```bash
    30  $ az login 
    31  $ export ARM_SUBSCRIPTION_ID={YOUR_SUBSCRIPTION_ID} 
    32  $ az ad sp create-for-rbac
    33  $ export TF_VAR_client_id={YOUR_SERVICE_PRINCIPAL_APP_ID}
    34  $ export TF_VAR_client_secret={YOUR_SERVICE_PRINCIPAL_PASSWORD}
    35  $ terraform init
    36  $ terraform apply
    37  $ kubectl --kubeconfig ./kubeconfig -f ./nginx-deployment.yml
    38  $ kubectl --kubeconfig ./kubeconfig get svc -w
    39  // Open browser and access the Nginx Service IPAddress
    40  $ terraform destroy
    41  ```
    42  
    43  ## Running automated tests against this module
    44  1. Create [Service Principal](https://docs.microsoft.com/en-us/cli/azure/create-an-azure-service-principal-azure-cli?view=azure-cli-latest) then set the value to the environment variables. 
    45  1. Install [Golang](https://golang.org/) version `1.13+` required. 
    46  1. `cd test`
    47  1. `go test -v -timeout 60m -tags azure -run TestTerraformAzureAKS`
    48  
    49  
    50  ### Example
    51  
    52  ```bash
    53  $ az login 
    54  $ export ARM_SUBSCRIPTION_ID={YOUR_SUBSCRIPTION_ID} 
    55  $ export TF_VAR_client_id={YOUR_SERVICE_PRINCIPAL_APP_ID}
    56  $ export TF_VAR_client_secret={YOUR_SERVICE_PRINCIPAL_PASSWORD}
    57  $ cd test
    58  $ go test -v -timeout 60m -tags azure -run TestTerraformAzureAKS
    59  ```