-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.tf
120 lines (96 loc) · 3.34 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
locals {
cluster_name = "aks-${random_integer.random_int.result}"
agents_resource_group_name = "MC_${var.resource_group_name}_${local.cluster_name}_${azurerm_resource_group.cluster.location}"
}
resource "azurerm_resource_group" "cluster" {
name = "${var.resource_group_name}"
location = "${var.resource_group_location}"
}
# Create a SP for use in the cluster
module "service_principal" {
source = "service_principal"
sp_least_privilidge = "${var.sp_least_privilidge}"
sp_name = "${local.cluster_name}"
}
# Keep the AKS name (and dns label) somewhat unique
resource "random_integer" "random_int" {
min = 100
max = 999
}
resource "azurerm_kubernetes_cluster" "aks" {
name = "${local.cluster_name}"
location = "${azurerm_resource_group.cluster.location}"
dns_prefix = "${local.cluster_name}"
resource_group_name = "${azurerm_resource_group.cluster.name}"
kubernetes_version = "${var.kubetnetes_version}"
linux_profile {
admin_username = "${var.linux_admin_username}"
ssh_key {
// If the user hasn't set a key the default will be "user_users_ssh_key", here we check for that and
// load the ssh from file if this is the case.
key_data = "${var.linux_admin_ssh_publickey}"
}
}
agent_pool_profile {
name = "agentpool"
count = "${var.node_count}"
vm_size = "${var.vm_size}"
os_type = "Linux"
}
service_principal {
client_id = "${module.service_principal.client_id}"
client_secret = "${module.service_principal.client_secret}"
}
}
data "azurerm_resource_group" "agents" {
name = "${local.agents_resource_group_name}"
depends_on = [
"azurerm_kubernetes_cluster.aks",
]
}
resource "azurerm_role_assignment" "aks_service_principal_role_agents" {
count = "${var.sp_least_privilidge}"
scope = "${data.azurerm_resource_group.agents.id}"
role_definition_name = "${module.service_principal.aks_role_name}"
principal_id = "${module.service_principal.sp_id}"
depends_on = [
"module.service_principal",
]
}
resource "random_id" "redis" {
keepers = {
azi_id = 1
}
byte_length = 8
}
provider "kubernetes" {
host = "${azurerm_kubernetes_cluster.aks.kube_config.0.host}"
client_certificate = "${base64decode(azurerm_kubernetes_cluster.aks.kube_config.0.client_certificate)}"
client_key = "${base64decode(azurerm_kubernetes_cluster.aks.kube_config.0.client_key)}"
cluster_ca_certificate = "${base64decode(azurerm_kubernetes_cluster.aks.kube_config.0.cluster_ca_certificate)}"
}
resource "azurerm_redis_cache" "redis" {
name = "redis${random_id.redis.hex}"
location = "${azurerm_resource_group.cluster.location}"
resource_group_name = "${azurerm_resource_group.cluster.name}"
capacity = 0
family = "C"
sku_name = "Basic"
enable_non_ssl_port = false
redis_configuration {}
}
resource "kubernetes_secret" "redis_secret" {
metadata {
name = "rediskeys"
}
data {
host = "${azurerm_redis_cache.redis.hostname}"
port = "${azurerm_redis_cache.redis.port}"
key = "${azurerm_redis_cache.redis.primary_access_key}"
}
}
module "oms" {
source = "oms"
resource_group_name = "${azurerm_resource_group.cluster.name}"
resource_group_location = "${var.resource_group_location}"
}