Skip to content

Commit 1f4ae04

Browse files
committed
Fixing article
1 parent 4832632 commit 1f4ae04

6 files changed

Lines changed: 190 additions & 0 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Generate random resource group name
2+
resource "random_pet" "rg_name" {
3+
prefix = var.resource_group_name_prefix
4+
}
5+
6+
resource "azurerm_resource_group" "rg" {
7+
name = random_pet.rg_name.id
8+
location = var.resource_group_location
9+
}
10+
11+
resource "random_id" "log_analytics_workspace_name_suffix" {
12+
byte_length = 8
13+
}
14+
15+
resource "azurerm_log_analytics_workspace" "test" {
16+
# The WorkSpace name has to be unique across the whole of azure, not just the current subscription/tenant.
17+
name = "${var.log_analytics_workspace_name}-${random_id.log_analytics_workspace_name_suffix.dec}"
18+
location = var.log_analytics_workspace_location
19+
resource_group_name = azurerm_resource_group.k8s.name
20+
sku = var.log_analytics_workspace_sku
21+
}
22+
23+
resource "azurerm_log_analytics_solution" "test" {
24+
solution_name = "ContainerInsights"
25+
location = azurerm_log_analytics_workspace.test.location
26+
resource_group_name = azurerm_resource_group.k8s.name
27+
workspace_resource_id = azurerm_log_analytics_workspace.test.id
28+
workspace_name = azurerm_log_analytics_workspace.test.name
29+
30+
plan {
31+
publisher = "Microsoft"
32+
product = "OMSGallery/ContainerInsights"
33+
}
34+
}
35+
36+
resource "azurerm_kubernetes_cluster" "k8s" {
37+
name = var.cluster_name
38+
location = azurerm_resource_group.k8s.location
39+
resource_group_name = azurerm_resource_group.k8s.name
40+
dns_prefix = var.dns_prefix
41+
42+
linux_profile {
43+
admin_username = "ubuntu"
44+
45+
ssh_key {
46+
key_data = file(var.ssh_public_key)
47+
}
48+
}
49+
50+
default_node_pool {
51+
name = "agentpool"
52+
node_count = var.agent_count
53+
vm_size = "Standard_D2_v2"
54+
}
55+
56+
service_principal {
57+
client_id = var.aks_service_principal_app_id
58+
client_secret = var.aks_service_principal_client_secret
59+
}
60+
61+
addon_profile {
62+
oms_agent {
63+
enabled = true
64+
log_analytics_workspace_id = azurerm_log_analytics_workspace.test.id
65+
}
66+
}
67+
68+
network_profile {
69+
load_balancer_sku = "Standard"
70+
network_plugin = "kubenet"
71+
}
72+
73+
tags = {
74+
Environment = "Development"
75+
}
76+
}
77+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
output "resource_group_name" {
2+
value = azurerm_resource_group.rg.name
3+
}
4+
5+
output "client_key" {
6+
value = azurerm_kubernetes_cluster.k8s.kube_config.0.client_key
7+
}
8+
9+
output "client_certificate" {
10+
value = azurerm_kubernetes_cluster.k8s.kube_config.0.client_certificate
11+
}
12+
13+
output "cluster_ca_certificate" {
14+
value = azurerm_kubernetes_cluster.k8s.kube_config.0.cluster_ca_certificate
15+
}
16+
17+
output "cluster_username" {
18+
value = azurerm_kubernetes_cluster.k8s.kube_config.0.username
19+
}
20+
21+
output "cluster_password" {
22+
value = azurerm_kubernetes_cluster.k8s.kube_config.0.password
23+
}
24+
25+
output "kube_config" {
26+
value = azurerm_kubernetes_cluster.k8s.kube_config_raw
27+
sensitive = true
28+
}
29+
30+
output "host" {
31+
value = azurerm_kubernetes_cluster.k8s.kube_config.0.host
32+
}
33+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
terraform {
2+
required_version = ">=1.0"
3+
4+
required_providers {
5+
azurerm = {
6+
source = "hashicorp/azurerm"
7+
version = "~>3.0"
8+
}
9+
}
10+
}
11+
12+
provider "azurerm" {
13+
features {}
14+
}

quickstart/201-k8s-cluster-with-tf-and-aks/readme.md

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
aks_service_principal_app_id = "<service_principal_app_id>"
2+
3+
aks_service_principal_client_secret = "<service_principal_password>"
4+
5+
aks_service_principal_object_id = "<service_principal_object_id>"
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
variable "resource_group_name_prefix" {
2+
default = "rg"
3+
description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription."
4+
}
5+
6+
variable "resource_group_location" {
7+
default = "eastus"
8+
description = "Location of the resource group."
9+
}
10+
11+
variable "agent_count" {
12+
default = 3
13+
}
14+
15+
variable "ssh_public_key" {
16+
default = "~/.ssh/id_rsa.pub"
17+
}
18+
19+
variable "dns_prefix" {
20+
default = "k8stest"
21+
}
22+
23+
variable "cluster_name" {
24+
default = "k8stest"
25+
}
26+
27+
variable "resource_group_name" {
28+
default = "azure-k8stest"
29+
}
30+
31+
variable "location" {
32+
default = "Central US"
33+
}
34+
35+
variable "log_analytics_workspace_name" {
36+
default = "testLogAnalyticsWorkspaceName"
37+
}
38+
39+
# refer https://azure.microsoft.com/global-infrastructure/services/?products=monitor for log analytics available regions
40+
variable "log_analytics_workspace_location" {
41+
default = "eastus"
42+
}
43+
44+
# refer https://azure.microsoft.com/pricing/details/monitor/ for log analytics pricing
45+
variable "log_analytics_workspace_sku" {
46+
default = "PerGB2018"
47+
}
48+
49+
# these following three entries are placeholder references; we will specify values later in terraform.tfvars
50+
variable "aks_service_principal_app_id" {
51+
default = ""
52+
}
53+
54+
variable "aks_service_principal_client_secret" {
55+
default = ""
56+
}
57+
58+
variable "aks_service_principal_object_id" {
59+
default = ""
60+
}
61+

0 commit comments

Comments
 (0)