diff --git a/quickstart/201-k8s-cluster-with-tf-and-aks/main.tf b/quickstart/201-k8s-cluster-with-tf-and-aks/main.tf new file mode 100644 index 00000000..b012b196 --- /dev/null +++ b/quickstart/201-k8s-cluster-with-tf-and-aks/main.tf @@ -0,0 +1,77 @@ +# Generate random resource group name +resource "random_pet" "rg_name" { + prefix = var.resource_group_name_prefix +} + +resource "azurerm_resource_group" "rg" { + name = random_pet.rg_name.id + location = var.resource_group_location +} + +resource "random_id" "log_analytics_workspace_name_suffix" { + byte_length = 8 +} + +resource "azurerm_log_analytics_workspace" "test" { + # The WorkSpace name has to be unique across the whole of azure, not just the current subscription/tenant. + name = "${var.log_analytics_workspace_name}-${random_id.log_analytics_workspace_name_suffix.dec}" + location = var.log_analytics_workspace_location + resource_group_name = azurerm_resource_group.k8s.name + sku = var.log_analytics_workspace_sku +} + +resource "azurerm_log_analytics_solution" "test" { + solution_name = "ContainerInsights" + location = azurerm_log_analytics_workspace.test.location + resource_group_name = azurerm_resource_group.k8s.name + workspace_resource_id = azurerm_log_analytics_workspace.test.id + workspace_name = azurerm_log_analytics_workspace.test.name + + plan { + publisher = "Microsoft" + product = "OMSGallery/ContainerInsights" + } +} + +resource "azurerm_kubernetes_cluster" "k8s" { + name = var.cluster_name + location = azurerm_resource_group.k8s.location + resource_group_name = azurerm_resource_group.k8s.name + dns_prefix = var.dns_prefix + + linux_profile { + admin_username = "ubuntu" + + ssh_key { + key_data = file(var.ssh_public_key) + } + } + + default_node_pool { + name = "agentpool" + node_count = var.agent_count + vm_size = "Standard_D2_v2" + } + + service_principal { + client_id = var.aks_service_principal_app_id + client_secret = var.aks_service_principal_client_secret + } + + addon_profile { + oms_agent { + enabled = true + log_analytics_workspace_id = azurerm_log_analytics_workspace.test.id + } + } + + network_profile { + load_balancer_sku = "Standard" + network_plugin = "kubenet" + } + + tags = { + Environment = "Development" + } +} + \ No newline at end of file diff --git a/quickstart/201-k8s-cluster-with-tf-and-aks/outputs.tf b/quickstart/201-k8s-cluster-with-tf-and-aks/outputs.tf new file mode 100644 index 00000000..9ee2d871 --- /dev/null +++ b/quickstart/201-k8s-cluster-with-tf-and-aks/outputs.tf @@ -0,0 +1,33 @@ +output "resource_group_name" { + value = azurerm_resource_group.rg.name +} + +output "client_key" { + value = azurerm_kubernetes_cluster.k8s.kube_config.0.client_key +} + +output "client_certificate" { + value = azurerm_kubernetes_cluster.k8s.kube_config.0.client_certificate +} + +output "cluster_ca_certificate" { + value = azurerm_kubernetes_cluster.k8s.kube_config.0.cluster_ca_certificate +} + +output "cluster_username" { + value = azurerm_kubernetes_cluster.k8s.kube_config.0.username +} + +output "cluster_password" { + value = azurerm_kubernetes_cluster.k8s.kube_config.0.password +} + +output "kube_config" { + value = azurerm_kubernetes_cluster.k8s.kube_config_raw + sensitive = true +} + +output "host" { + value = azurerm_kubernetes_cluster.k8s.kube_config.0.host +} + \ No newline at end of file diff --git a/quickstart/201-k8s-cluster-with-tf-and-aks/providers.tf b/quickstart/201-k8s-cluster-with-tf-and-aks/providers.tf new file mode 100644 index 00000000..cbe3e719 --- /dev/null +++ b/quickstart/201-k8s-cluster-with-tf-and-aks/providers.tf @@ -0,0 +1,14 @@ +terraform { + required_version = ">=1.0" + + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~>3.0" + } + } +} + +provider "azurerm" { + features {} +} diff --git a/quickstart/201-k8s-cluster-with-tf-and-aks/readme.md b/quickstart/201-k8s-cluster-with-tf-and-aks/readme.md new file mode 100644 index 00000000..e69de29b diff --git a/quickstart/201-k8s-cluster-with-tf-and-aks/terraform.tfvars b/quickstart/201-k8s-cluster-with-tf-and-aks/terraform.tfvars new file mode 100644 index 00000000..5e0e0e0f --- /dev/null +++ b/quickstart/201-k8s-cluster-with-tf-and-aks/terraform.tfvars @@ -0,0 +1,5 @@ +aks_service_principal_app_id = "" + +aks_service_principal_client_secret = "" + +aks_service_principal_object_id = "" diff --git a/quickstart/201-k8s-cluster-with-tf-and-aks/variables.tf b/quickstart/201-k8s-cluster-with-tf-and-aks/variables.tf new file mode 100644 index 00000000..e9e948cb --- /dev/null +++ b/quickstart/201-k8s-cluster-with-tf-and-aks/variables.tf @@ -0,0 +1,61 @@ +variable "resource_group_name_prefix" { + default = "rg" + description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." +} + +variable "resource_group_location" { + default = "eastus" + description = "Location of the resource group." +} + +variable "agent_count" { + default = 3 +} + +variable "ssh_public_key" { + default = "~/.ssh/id_rsa.pub" +} + +variable "dns_prefix" { + default = "k8stest" +} + +variable "cluster_name" { + default = "k8stest" +} + +variable "resource_group_name" { + default = "azure-k8stest" +} + +variable "location" { + default = "Central US" +} + +variable "log_analytics_workspace_name" { + default = "testLogAnalyticsWorkspaceName" +} + +# refer https://azure.microsoft.com/global-infrastructure/services/?products=monitor for log analytics available regions +variable "log_analytics_workspace_location" { + default = "eastus" +} + +# refer https://azure.microsoft.com/pricing/details/monitor/ for log analytics pricing +variable "log_analytics_workspace_sku" { + default = "PerGB2018" +} + +# these following three entries are placeholder references; we will specify values later in terraform.tfvars +variable "aks_service_principal_app_id" { + default = "" +} + +variable "aks_service_principal_client_secret" { + default = "" +} + +variable "aks_service_principal_object_id" { + default = "" +} + \ No newline at end of file