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

     1  # ---------------------------------------------------------------------------------------------------------------------
     2  # DEPLOY AN AZURE AKS CLUSTER
     3  # This is an example of how to deploy an Azure AKS cluster with load balancer in front of the service 
     4  # to handle providing the public interface into the cluster.
     5  # ---------------------------------------------------------------------------------------------------------------------
     6  
     7  # ------------------------------------------------------------------------------
     8  # CONFIGURE OUR AZURE CONNECTION
     9  # ------------------------------------------------------------------------------
    10  
    11  provider "azurerm" {
    12    version = "1.40.0"
    13  }
    14  
    15  # ---------------------------------------------------------------------------------------------------------------------
    16  # DEPLOY A RESOURCE GROUP
    17  # ---------------------------------------------------------------------------------------------------------------------
    18  
    19  resource "azurerm_resource_group" "k8s" {
    20    name     = var.resource_group_name
    21    location = var.location
    22  }
    23  
    24  # ---------------------------------------------------------------------------------------------------------------------
    25  # DEPLOY AN AZURE KUBERNETES CLUSTER
    26  # ---------------------------------------------------------------------------------------------------------------------
    27  
    28  resource "azurerm_kubernetes_cluster" "k8s" {
    29    name                = var.cluster_name
    30    location            = azurerm_resource_group.k8s.location
    31    resource_group_name = azurerm_resource_group.k8s.name
    32    dns_prefix          = var.dns_prefix
    33  
    34    linux_profile {
    35      admin_username = "ubuntu"
    36  
    37      ssh_key {
    38        key_data = file(var.ssh_public_key)
    39      }
    40    }
    41  
    42    default_node_pool {
    43      name       = "agentpool"
    44      node_count = var.agent_count
    45      vm_size    = "Standard_DS1_v2"
    46    }
    47  
    48    service_principal {
    49      client_id     = var.client_id
    50      client_secret = var.client_secret
    51    }
    52  
    53    tags = {
    54      Environment = "Development"
    55    }
    56  }
    57  
    58  # ---------------------------------------------------------------------------------------------------------------------
    59  # CREATE KUBECONFIG FILE
    60  # ---------------------------------------------------------------------------------------------------------------------
    61  
    62  resource "local_file" "kubeconfig" {
    63    content  = azurerm_kubernetes_cluster.k8s.kube_config_raw
    64    filename = "kubeconfig"
    65  
    66    depends_on = [
    67      azurerm_kubernetes_cluster.k8s
    68    ]
    69  }