-
Notifications
You must be signed in to change notification settings - Fork 984
/
main.tf
93 lines (77 loc) · 2.74 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
locals {
random_prefix = "${var.prefix}-${random_id.tf-k8s-acc.hex}"
}
resource "random_id" "tf-k8s-acc" {
byte_length = 3
}
resource "azurerm_resource_group" "tf-k8s-acc" {
name = "${local.random_prefix}-rsg"
location = "${var.location}"
}
resource "azurerm_route_table" "tf-k8s-acc" {
name = "${local.random_prefix}-rt"
location = "${azurerm_resource_group.tf-k8s-acc.location}"
resource_group_name = "${azurerm_resource_group.tf-k8s-acc.name}"
route {
name = "default"
address_prefix = "10.100.0.0/14"
next_hop_type = "VirtualAppliance"
next_hop_in_ip_address = "10.10.1.1"
}
}
resource "azurerm_virtual_network" "tf-k8s-acc" {
name = "${local.random_prefix}-network"
location = "${azurerm_resource_group.tf-k8s-acc.location}"
resource_group_name = "${azurerm_resource_group.tf-k8s-acc.name}"
address_space = ["10.1.0.0/16"]
}
resource "azurerm_subnet" "tf-k8s-acc" {
name = "${local.random_prefix}-internal"
resource_group_name = "${azurerm_resource_group.tf-k8s-acc.name}"
address_prefix = "10.1.0.0/24"
virtual_network_name = "${azurerm_virtual_network.tf-k8s-acc.name}"
# this field is deprecated and will be removed in 2.0 - but is required until then
route_table_id = "${azurerm_route_table.tf-k8s-acc.id}"
}
resource "azurerm_subnet_route_table_association" "tf-k8s-acc" {
subnet_id = "${azurerm_subnet.tf-k8s-acc.id}"
route_table_id = "${azurerm_route_table.tf-k8s-acc.id}"
}
resource "azurerm_kubernetes_cluster" "tf-k8s-acc" {
name = "${local.random_prefix}-cluster"
resource_group_name = "${azurerm_resource_group.tf-k8s-acc.name}"
location = "${azurerm_resource_group.tf-k8s-acc.location}"
dns_prefix = "${local.random_prefix}-cluster"
kubernetes_version = "${var.kubernetes_version}"
# Uncomment to enable SSH access to nodes
#
# linux_profile {
# admin_username = "acctestuser1"
# ssh_key {
# key_data = "${file(var.public_ssh_key_path)}"
# }
# }
agent_pool_profile {
name = "agentpool"
count = "${var.workers_count}"
vm_size = "${var.workers_type}"
os_type = "Linux"
os_disk_size_gb = 30
# Required for advanced networking
vnet_subnet_id = "${azurerm_subnet.tf-k8s-acc.id}"
}
service_principal {
client_id = "${var.aks_client_id}"
client_secret = "${var.aks_client_secret}"
}
role_based_access_control {
enabled = true
}
network_profile {
network_plugin = "azure"
}
}
resource "local_file" "kubeconfig" {
content = "${azurerm_kubernetes_cluster.tf-k8s-acc.kube_config_raw}"
filename = "${path.module}/kubeconfig"
}