Skip to content

Commit c9c9e06

Browse files
committed
[azure] Single-cluster usage guide for AKS TF module
1 parent 7c354c9 commit c9c9e06

23 files changed

+538
-45
lines changed

install/infra/modules/aks/database.tf

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
resource "random_integer" "db" {
2-
count = var.enable_external_database ? 1 : 0
2+
count = var.create_external_database ? 1 : 0
33

44
min = 10000
55
max = 99999
66
}
77

88
resource "random_password" "db" {
9-
count = var.enable_external_database ? 1 : 0
9+
count = var.create_external_database ? 1 : 0
1010

1111
length = 32
1212
}
1313

1414
resource "azurerm_mysql_server" "db" {
15-
count = var.enable_external_database ? 1 : 0
15+
count = var.create_external_database ? 1 : 0
1616

1717
name = "gitpod-${random_integer.db[count.index].result}"
1818
location = azurerm_resource_group.gitpod.location
@@ -30,7 +30,7 @@ resource "azurerm_mysql_server" "db" {
3030
}
3131

3232
resource "azurerm_mysql_firewall_rule" "db" {
33-
count = var.enable_external_database ? 1 : 0
33+
count = var.create_external_database ? 1 : 0
3434

3535
name = "Azure_Resource"
3636
resource_group_name = azurerm_resource_group.gitpod.name
@@ -40,7 +40,7 @@ resource "azurerm_mysql_firewall_rule" "db" {
4040
}
4141

4242
resource "azurerm_mysql_database" "db" {
43-
count = var.enable_external_database ? 1 : 0
43+
count = var.create_external_database ? 1 : 0
4444

4545
name = "gitpod"
4646
resource_group_name = azurerm_resource_group.gitpod.name

install/infra/modules/aks/kubernetes.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
resource "azurerm_role_assignment" "k8s" {
2-
count = var.dns_enabled ? 1 : 0
2+
count = local.dns_enabled ? 1 : 0
33

44
principal_id = azurerm_kubernetes_cluster.k8s.kubelet_identity[count.index].object_id
55
role_definition_name = "DNS Zone Contributor"
66
scope = azurerm_dns_zone.dns[count.index].id
77
}
88

99
resource "azurerm_role_assignment" "k8s_reader" {
10-
count = var.dns_enabled ? 1 : 0
10+
count = local.dns_enabled ? 1 : 0
1111

1212
principal_id = azurerm_kubernetes_cluster.k8s.kubelet_identity[count.index].object_id
1313
role_definition_name = "Reader"

install/infra/modules/aks/local.tf

+3-6
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,12 @@ locals {
77
workspace_headless : "gitpod.io/workload_workspace_headless"
88
})
99
dns_enabled = var.domain_name != null
10+
1011
name_format = join("-", [
11-
"test",
12+
var.resource_group_name,
1213
"%s", # name
13-
local.workspace_name
14-
])
15-
name_format_global = join("-", [
16-
"sh-test",
17-
local.workspace_name
1814
])
15+
1916
workspace_name = replace(terraform.workspace, "/[\\W\\-]/", "") # alphanumeric workspace name
2017
db = "GP_Gen5_2"
2118
location = substr(var.location, 0, 3) # Short code for location

install/infra/modules/aks/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ provider "azurerm" {
1414
data "azurerm_client_config" "current" {}
1515

1616
resource "azurerm_resource_group" "gitpod" {
17-
name = local.name_format_global
17+
name = var.resource_group_name
1818
location = var.location
1919
}

install/infra/modules/aks/networks.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ resource "azurerm_subnet" "network" {
1313
}
1414

1515
resource "azurerm_dns_zone" "dns" {
16-
count = var.dns_enabled ? 1 : 0
16+
count = local.dns_enabled ? 1 : 0
1717

1818
name = var.domain_name
1919
resource_group_name = azurerm_resource_group.gitpod.name

install/infra/modules/aks/output.tf

+5-3
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,18 @@ output "region" {
8888
output "registry" {
8989
sensitive = true
9090
value = try({
91+
url = azurerm_container_registry.registry.0.login_server
9192
server = azurerm_container_registry.registry.0.login_server
92-
password = azurerm_container_registry.registry.0.admin_password
9393
username = azurerm_container_registry.registry.0.admin_username
94+
password = azurerm_container_registry.registry.0.admin_password
9495
}, {})
9596
}
9697

9798
output "storage" {
9899
sensitive = true
99100
value = try({
100-
username = azurerm_storage_account.storage.0.name
101-
password = azurerm_storage_account.storage.0.primary_access_key
101+
storage_region = var.location
102+
account_name = azurerm_storage_account.storage.0.name
103+
account_key = azurerm_storage_account.storage.0.primary_access_key
102104
}, {})
103105
}

install/infra/modules/aks/registry.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
resource "random_integer" "registry" {
2-
count = var.enable_external_registry ? 1 : 0
2+
count = var.create_external_registry ? 1 : 0
33

44
min = 10000
55
max = 99999
66
}
77

88
resource "azurerm_container_registry" "registry" {
9-
count = var.enable_external_registry ? 1 : 0
9+
count = var.create_external_registry ? 1 : 0
1010

1111
name = "gitpod${random_integer.registry[count.index].result}"
1212
resource_group_name = azurerm_resource_group.gitpod.name
@@ -16,7 +16,7 @@ resource "azurerm_container_registry" "registry" {
1616
}
1717

1818
resource "azurerm_role_assignment" "registry" {
19-
count = var.enable_external_registry ? 1 : 0
19+
count = var.create_external_registry ? 1 : 0
2020

2121
principal_id = azurerm_kubernetes_cluster.k8s.kubelet_identity[0].object_id
2222
role_definition_name = "AcrPush"

install/infra/modules/aks/storage.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
resource "random_integer" "storage" {
2-
count = var.enable_external_storage ? 1 : 0
2+
count = var.create_external_storage ? 1 : 0
33

44
min = 10000
55
max = 99999
66
}
77

88
resource "azurerm_storage_account" "storage" {
9-
count = var.enable_external_storage ? 1 : 0
9+
count = var.create_external_storage ? 1 : 0
1010

1111
name = "gitpod${random_integer.storage[count.index].result}"
1212
resource_group_name = azurerm_resource_group.gitpod.name

install/infra/modules/aks/variables.tf

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ variable "cluster_version" {
77
description = "kubernetes version of to create the cluster with"
88
}
99

10-
variable "dns_enabled" {}
1110
variable "domain_name" {}
12-
variable "enable_airgapped" {}
13-
variable "enable_external_database" {}
14-
variable "enable_external_registry" {}
15-
variable "enable_external_storage" {}
16-
variable "workspace_name" {
11+
variable "enable_airgapped" {
12+
default = false
1713
}
1814

15+
variable "create_external_database" {}
16+
variable "create_external_registry" {}
17+
variable "create_external_storage" {}
18+
variable "resource_group_name" {}
19+
1920
// Azure-specific variables
2021
variable "location" {
2122
default = "northeurope"

install/infra/single-cluster/aws/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ If you wish to create cloud specific database, storage and registry backend to b
6767
with `Gitpod`, leave the following 3 booleans set:
6868
6969
``` sh
70-
enable_external_database = true
71-
enable_external_storage = true
72-
enable_external_storage_for_registry_backend = true
70+
create_external_database = true
71+
create_external_storage = true
72+
create_external_storage_for_registry_backend = true
7373
```
7474
7575
The corresponding resources will be created by the terraform script which
7676
inclustes an `RDS` mysql database, an `S3` bucket and another `S3` bucket to
77-
be used as registry backend. By default `enable_external_storage_for_registry_backend`
77+
be used as registry backend. By default `create_external_storage_for_registry_backend`
7878
is set to `false`. One can re-use the same `S3` bucket for both object storage and registry backend.
7979
8080
The expectation is that you can use the credentials to these setups(provided later
@@ -202,7 +202,7 @@ gitpod kotsadm-minio-0 0/1 ContainerCreat
202202
gitpod kotsadm-postgres-0 0/1 Init:0/2 0 2m28s
203203
```
204204
205-
This can happen when the wrong `image_id` was used in the `.tfvars` file. The ID needs to respect both the region as well as the Kubernetes version and can be found [here](https://cloud-images.ubuntu.com/docs/aws/eks/).
205+
This can happen when the wrong `image_id` was used in the `.tfvars` file. The ID needs to respect both the region as well as the Kubernetes version and can be found [here](https://cloud-images.ubuntu.com/docs/aws/eks/).
206206
207207
### Some pods never start (Init state)
208208
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export ARM_CLIENT_ID=
2+
export ARM_CLIENT_SECRET=
3+
export ARM_SUBSCRIPTION_ID=
4+
export ARM_TENANT_ID=
5+
6+
export ARM_ACCESS_KEY= # Access key created for Blob Storage Account
+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
##
2+
# Terraform AWS reference architecture
3+
#
4+
5+
.PHONY: init
6+
init:
7+
@terraform init
8+
9+
touch-kubeconfig:
10+
@touch kubeconfig
11+
12+
cleanup-kubeconfig:
13+
@rm kubeconfig
14+
15+
.PHONY: plan
16+
plan: touch-kubeconfig plan-cluster plan-cm-edns cleanup-kubeconfig
17+
18+
.PHONY: apply
19+
apply: apply-cluster apply-tools
20+
21+
.PHONY: destroy
22+
destroy: destroy-tools destroy-cluster
23+
24+
.PHONY: plan-cluster
25+
plan-cluster:
26+
@terraform plan -target=module.aks
27+
28+
.PHONY: plan-tools
29+
plan-tools: plan-cm-edns plan-cluster-issuer
30+
31+
.PHONY: plan-cm-edns
32+
plan-cm-edns:
33+
@terraform plan -target=module.certmanager -target=module.externaldns
34+
35+
.PHONY: plan-cluster-issuer
36+
plan-cluster-issuer:
37+
@terraform plan -target=module.cluster-issuer
38+
39+
.PHONY: apply-cluster
40+
apply-cluster:
41+
@terraform apply -target=module.aks --auto-approve
42+
43+
.PHONY: apply-tools
44+
apply-tools: install-cm-edns install-cluster-issuer
45+
46+
.PHONY: install-cm-edns
47+
install-cm-edns:
48+
@terraform apply -target=module.certmanager -target=module.externaldns --auto-approve
49+
50+
PHONY: install-cluster-issuer
51+
install-cluster-issuer:
52+
@terraform apply -target=module.cluster-issuer --auto-approve
53+
54+
.PHONY: destroy-cluster
55+
destroy-cluster:
56+
@terraform destroy -target=module.aks --auto-approve
57+
58+
.PHONY: destroy-tools
59+
destroy-tools: destroy-cluster-issuer destroy-cm-edns
60+
61+
.PHONY: destroy-cm-edns
62+
destroy-cm-edns:
63+
@terraform destroy -target=module.certmanager -target=module.externaldns --auto-approve
64+
65+
.PHONY: destroy-cluster-issuer
66+
destroy-cluster-issuer:
67+
@terraform destroy -target=module.cluster-issuer --auto-approve || echo "Could not remove cluster-issuer"
68+
69+
## Output targets
70+
71+
.PHONY: refresh
72+
refresh:
73+
@echo "Refreshing terraform state"
74+
@terraform refresh
75+
@echo ""
76+
@echo "Done!"
77+
78+
.PHONY: output
79+
output: refresh output-done-msg output-url output-nameservers output-registry output-database output-storage output-issuer
80+
81+
output-done-msg:
82+
@echo ""
83+
@echo ""
84+
@echo "=========================="
85+
@echo "🎉🥳🔥🧡🚀"
86+
@echo "Your AWS cloud infrastructure is ready to install Gitpod. Please visit"
87+
@echo "https://www.gitpod.io/docs/self-hosted/latest/getting-started#step-4-install-gitpod"
88+
@echo "for your next steps."
89+
@echo "================="
90+
@echo "Config Parameters"
91+
@echo "================="
92+
93+
output-url:
94+
@echo ""
95+
@echo "Gitpod domain name:"
96+
@echo "================="
97+
@terraform output -json url | jq
98+
99+
output-nameservers:
100+
@echo ""
101+
@echo "Nameservers for the domain(to be added as NS records in your domain provider):"
102+
@echo "================="
103+
@terraform output -json nameservers | jq
104+
105+
output-storage:
106+
@echo ""
107+
@echo "Azure Object storage:"
108+
@echo "=============="
109+
@terraform output -json storage | jq
110+
111+
output-registry:
112+
@echo ""
113+
@echo "Container registry:"
114+
@echo "=================="
115+
@terraform output -json registry | jq
116+
117+
output-database:
118+
@echo ""
119+
@echo "Database:"
120+
@echo "========"
121+
@terraform output -json database | jq
122+
123+
output-issuer:
124+
@echo ""
125+
@echo "ClusterIssuer name:"
126+
@echo "================="
127+
@terraform output -json cluster_issuer | jq
128+
129+
# end

0 commit comments

Comments
 (0)