Skip to content

Commit ac6c5a3

Browse files
nandajavarmaadrienthebo
authored andcommitted
[terraform] Add k3s setup for tests
Co-authored-by: Adrien Thebo <[email protected]>
1 parent 7ea6464 commit ac6c5a3

File tree

9 files changed

+287
-1
lines changed

9 files changed

+287
-1
lines changed

install/infra/modules/k3s/output.tf

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,25 @@ output "database" {
44
instance = "${var.gcp_project}:${var.gcp_region}:${google_sql_database_instance.gitpod.name}"
55
username = "${google_sql_user.users.name}"
66
password = random_password.password.result
7-
service_account_key = "Upload the JSON file corresponding the service account credentials"
7+
service_account_key_path = var.credentials
88
}, "No database created")
99
}
10+
11+
output "registry" {
12+
sensitive = true
13+
value = try({
14+
url = "gcr.io/${var.gcp_project}"
15+
server = "gcr.io"
16+
username = "_json_key"
17+
password_file_path = var.credentials
18+
}, "No container registry created")
19+
}
20+
21+
output "storage" {
22+
sensitive = true
23+
value = try({
24+
region = var.gcp_region
25+
project = var.gcp_project
26+
service_account_key_path = var.credentials
27+
}, "No GCS bucket created for object storage")
28+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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: refresh
25+
refresh:
26+
@echo "Refreshing terraform state"
27+
@terraform refresh
28+
@echo ""
29+
@echo "Done!"
30+
31+
.PHONY: output
32+
output: refresh output-done-msg output-url output-registry output-database output-storage output-issuer
33+
34+
output-done-msg:
35+
@echo ""
36+
@echo ""
37+
@echo "=========================="
38+
@echo "🎉🥳🔥🧡🚀"
39+
@echo "Your cloud infrastructure is ready to install Gitpod. Please visit"
40+
@echo "https://www.gitpod.io/docs/self-hosted/latest/getting-started#step-4-install-gitpod"
41+
@echo "for your next steps."
42+
@echo "================="
43+
@echo "Config Parameters"
44+
@echo "================="
45+
46+
output-url:
47+
@echo ""
48+
@echo "Gitpod domain name:"
49+
@echo "================="
50+
@terraform output -json url | jq
51+
52+
output-storage:
53+
@echo ""
54+
@echo "Object storage:"
55+
@echo "=============="
56+
@terraform output -json storage | jq
57+
58+
output-registry:
59+
@echo ""
60+
@echo "GCR registry:"
61+
@echo "=================="
62+
@terraform output -json registry | jq
63+
64+
output-database:
65+
@echo ""
66+
@echo "Database:"
67+
@echo "========"
68+
@echo "Tick the option 'Use Google Cloud SQL Proxy' if using this database"
69+
@terraform output -json database | jq
70+
@echo ""
71+
72+
output-issuer:
73+
@echo ""
74+
@echo "ClusterIssuer name:"
75+
@echo "================="
76+
@terraform output -json cluster_issuer | jq
77+
78+
.PHONY: plan-cluster
79+
plan-cluster:
80+
@terraform plan -target=module.k3s
81+
82+
.PHONY: plan-tools
83+
plan-tools: plan-cm-edns plan-cluster-issuer
84+
85+
.PHONY: plan-cm-edns
86+
plan-cm-edns:
87+
@terraform plan -target=module.certmanager -target=module.externaldns
88+
89+
.PHONY: plan-cluster-issuer
90+
plan-cluster-issuer:
91+
@terraform plan -target=module.cluster-issuer
92+
93+
.PHONY: apply-cluster
94+
apply-cluster:
95+
@terraform apply -target=module.k3s --auto-approve
96+
97+
.PHONY: apply-tools
98+
apply-tools: install-cm-edns install-cluster-issuer
99+
100+
.PHONY: install-cm-edns
101+
install-cm-edns:
102+
@terraform apply -target=module.certmanager -target=module.externaldns --auto-approve
103+
104+
.PHONY: install-cluster-issuer
105+
install-cluster-issuer:
106+
@terraform apply -target=module.cluster-issuer --auto-approve
107+
108+
.PHONY: destroy-cluster
109+
destroy-cluster:
110+
@terraform destroy -target=module.k3s --auto-approve
111+
112+
.PHONY: destroy-tools
113+
destroy-tools: destroy-cluster-issuer destroy-cm-edns
114+
115+
.PHONY: destroy-cm-edns
116+
destroy-cm-edns:
117+
@terraform destroy -target=module.certmanager -target=module.externaldns --auto-approve
118+
119+
.PHONY: destroy-cluster-issuer
120+
destroy-cluster-issuer:
121+
@terraform destroy -target=module.cluster-issuer --auto-approve || echo "Could not remove cluster-issuer"
122+
123+
# end
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module "k3s" {
2+
source = "../../modules/k3s"
3+
4+
name = var.name
5+
gcp_project = var.project
6+
gcp_region = var.region
7+
gcp_zone = var.zone
8+
credentials = var.credentials_path
9+
kubeconfig = var.kubeconfig
10+
dns_sa_creds = var.credentials_path
11+
dns_project = var.project
12+
managed_dns_zone = var.managed_dns_zone
13+
domain_name = var.domain_name
14+
cluster_version = var.cluster_version
15+
image_id = var.image_id
16+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
locals {
2+
credentials = "${file(var.credentials_path)}"
3+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
terraform {
2+
backend "gcs" {
3+
bucket = "gitpod-tf"
4+
prefix = "k3s/terraform.state"
5+
}
6+
7+
required_providers {
8+
google = {
9+
source = "hashicorp/google"
10+
}
11+
12+
kubernetes = {
13+
source = "hashicorp/kubernetes"
14+
}
15+
16+
helm = {
17+
source = "hashicorp/helm"
18+
}
19+
}
20+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
output "database" {
2+
sensitive = true
3+
value = module.k3s.database
4+
}
5+
6+
output "registry" {
7+
sensitive = true
8+
value = module.k3s.registry
9+
}
10+
11+
output "storage" {
12+
sensitive = true
13+
value = module.k3s.storage
14+
}
15+
16+
output "url" {
17+
value = var.domain_name
18+
}
19+
20+
output "cluster_issuer" {
21+
value = module.cluster-issuer.cluster_issuer
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name = "gitpod"
2+
3+
domain_name =
4+
5+
region = "europe-west1"
6+
zone = "europe-west1-b"
7+
project =
8+
credentials_path = "key.json"
9+
10+
cluster_version = "v1.22.12+k3s1"
11+
12+
image_id = "ubuntu-2204-jammy-v20220712a"
13+
14+
kubeconfig = "./kubeconfig"
15+
16+
managed_dns_zone =
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module "certmanager" {
2+
source = "../../modules/tools/cert-manager"
3+
4+
kubeconfig = var.kubeconfig
5+
}
6+
7+
module "cluster-issuer" {
8+
source = "../../modules/tools/issuer"
9+
kubeconfig = var.kubeconfig
10+
gcp_credentials = local.credentials
11+
issuer_name = "cloudDNS"
12+
cert_manager_issuer = {
13+
project = var.project
14+
serviceAccountSecretRef = {
15+
name = "clouddns-dns01-solver"
16+
key = "keys.json"
17+
}
18+
}
19+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
variable "kubeconfig" {
2+
description = "The KUBECONFIG file path to store the resulting KUBECONFIG file to"
3+
default = "./kubeconfig"
4+
}
5+
6+
variable "project" {
7+
description = "Google cloud Region to perform operations in"
8+
}
9+
10+
variable "region" {
11+
description = "Google cloud Region to perform operations in"
12+
default = "europe-west1"
13+
}
14+
15+
variable "zone" {
16+
description = "Google cloud Zone to perform operations in"
17+
default = "europe-west1-b"
18+
}
19+
20+
variable "credentials_path" {
21+
description = "Path to the JSON file storing Google service account credentials"
22+
default = ""
23+
}
24+
25+
variable "name" {
26+
description = "Prefix name for the nodes and firewall"
27+
default = "k3s"
28+
}
29+
30+
variable "image_id" {
31+
description = "Node image ID to be used to provision EC2 instances"
32+
default = "ubuntu-2004-focal-v20220419"
33+
}
34+
35+
variable "cluster_version" {
36+
description = "Kubernetes version to use to provision the cluster"
37+
default = "v1.22.12+k3s1"
38+
}
39+
40+
variable "domain_name" {
41+
description = "Domain name to add to add DNS map to"
42+
default = null
43+
}
44+
45+
variable "managed_dns_zone" {
46+
description = "The Cloud DNS managed zone where Gitpod A records will be created"
47+
default = null
48+
}

0 commit comments

Comments
 (0)