forked from VipinAgarwal/azure-aks-istio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
178 lines (153 loc) · 4.62 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
resource "azurerm_resource_group" "rg" {
name = "aks-resource-group"
location = "eastus"
}
resource "azurerm_virtual_network" "vnet" {
name = "aks-vnet"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
address_space = ["192.168.0.0/16"]
}
resource "azurerm_subnet" "subnet" {
name = "aks-subnet"
resource_group_name = azurerm_resource_group.rg.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = ["192.168.1.0/24"]
service_endpoints = ["Microsoft.ContainerRegistry"]
}
resource "azuread_group" "aks-admin-group" {
name = "AKS-Aadmins"
}
resource "azurerm_kubernetes_cluster" "aks" {
name = "aks"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
dns_prefix = "someapplication"
default_node_pool {
name = "default"
vnet_subnet_id = azurerm_subnet.subnet.id
type = "VirtualMachineScaleSets"
availability_zones = ["1", "2", "3"]
enable_auto_scaling = true
enable_node_public_ip = false
max_count = 3
min_count = 1
os_disk_size_gb = 256
vm_size = "Standard_D2_v2"
}
role_based_access_control {
enabled = true
azure_active_directory {
managed = true
admin_group_object_ids = [azuread_group.aks-admin-group.id]
}
}
identity {
type = "SystemAssigned"
}
network_profile {
network_plugin = "azure"
network_policy = "azure"
load_balancer_sku = "Standard"
}
addon_profile {
aci_connector_linux {
enabled = false
}
azure_policy {
enabled = true
}
http_application_routing {
enabled = false
}
kube_dashboard {
enabled = true
}
}
}
###################Install Istio (Service Mesh) #######################################
resource "random_password" "password" {
length = 16
special = true
override_special = "_%@"
}
data "azurerm_subscription" "current" {
}
resource "local_file" "kube_config" {
content = azurerm_kubernetes_cluster.aks.kube_admin_config_raw
filename = ".kube/config"
}
resource "null_resource" "set-kube-config" {
triggers = {
always_run = "${timestamp()}"
}
provisioner "local-exec" {
command = "az aks get-credentials -n ${azurerm_kubernetes_cluster.aks.name} -g ${azurerm_resource_group.rg.name} --file \".kube/${azurerm_kubernetes_cluster.aks.name}\" --admin --overwrite-existing"
}
depends_on = [local_file.kube_config]
}
resource "kubernetes_namespace" "istio_system" {
provider = kubernetes.local
metadata {
name = "istio-system"
}
}
resource "kubernetes_secret" "grafana" {
provider = kubernetes.local
metadata {
name = "grafana"
namespace = "istio-system"
labels = {
app = "grafana"
}
}
data = {
username = "admin"
passphrase = random_password.password.result
}
type = "Opaque"
depends_on = [kubernetes_namespace.istio_system]
}
resource "kubernetes_secret" "kiali" {
provider = kubernetes.local
metadata {
name = "kiali"
namespace = "istio-system"
labels = {
app = "kiali"
}
}
data = {
username = "admin"
passphrase = random_password.password.result
}
type = "Opaque"
depends_on = [kubernetes_namespace.istio_system]
}
resource "local_file" "istio-config" {
content = templatefile("${path.module}/istio-aks.tmpl", {
enableGrafana = true
enableKiali = true
enableTracing = true
})
filename = ".istio/istio-aks.yaml"
}
resource "null_resource" "istio" {
triggers = {
always_run = "${timestamp()}"
}
provisioner "local-exec" {
command = "istioctl manifest apply -f \".istio/istio-aks.yaml\" --kubeconfig \".kube/${azurerm_kubernetes_cluster.aks.name}\""
}
depends_on = [kubernetes_secret.grafana, kubernetes_secret.kiali, local_file.istio-config]
}
################### Deploy booking info sample application with gateway #######################################
// kubectl provider can be installed from here - https://gavinbunney.github.io/terraform-provider-kubectl/docs/provider.html
data "kubectl_filename_list" "manifests" {
pattern = "samples/bookinfo/*.yaml"
}
// source of booking info application - https://istio.io/latest/docs/examples/bookinfo/
resource "kubectl_manifest" "bookinginfo" {
count = length(data.kubectl_filename_list.manifests.matches)
yaml_body = file(element(data.kubectl_filename_list.manifests.matches, count.index))
}