Skip to content

Commit aa3458d

Browse files
eebi-sotecmattkaem
authored andcommitted
add configurable autopilot feature
1 parent be8f445 commit aa3458d

File tree

30 files changed

+541
-270
lines changed

30 files changed

+541
-270
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
terraform {
22
backend "gcs" {
3-
bucket = "<bucket_name>" # Insert the name of the storage bucket
3+
bucket = "<bucket_name>" # Insert the name of the storage bucket
44
prefix = "terraform/infrastructure"
55
}
66
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
locals {
2-
project_id = "<project_id>" # Insert your project id
3-
region = "europe-west1" # Insert the region for your cluster
4-
zone = "europe-west1-b" # Insert the zone for your cluster and SQL database
5-
node_locations = ["europe-west1-c", "europe-west1-b", "europe-west1-d"] # Insert the node locations for your cluster
6-
enable_cert_manager = false # Toggle to enable the creation of service account needed for the cert-manager
2+
project_id = "<project_id>" # Insert your project id
3+
region = "europe-west1" # Insert the region for your cluster
4+
zone = "europe-west1-b" # Insert the zone for your cluster and SQL database
5+
node_locations = ["europe-west1-c", "europe-west1-b", "europe-west1-d"] # Insert the node locations for your cluster
6+
enable_cert_manager = false # Toggle to enable the creation of service account needed for the cert-manager
77
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
terraform {
22
backend "gcs" {
3-
bucket = "<bucket_name>" # Insert the name of the storage bucket
3+
bucket = "<bucket_name>" # Insert the name of the storage bucket
44
prefix = "terraform/software"
55
}
66
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
locals {
2-
bucket_name = "<bucket_name>" # Insert the name of the storage bucket
3-
oauth_app_name = "<oauth-app_name>" # Insert the name of your OAuth application
4-
device_communication_dns_name = "<dns_name>" # Insert the name of your API DNS (e.g. api.hono.my-domain.com)
5-
oauth_client_id = "<oauth_client_id>" # Insert the client ID of your OAuth 2.0 client
6-
oauth_client_secret = "<oauth_client_secret>" # Insert the client secret of your OAuth 2.0 client
7-
helm_package_repository = "<helm-package-repository>" # Insert the link to your helm chart (e.g. oci://europe-west1-docker.pkg.dev/my-project/my-repository)
8-
hono_chart_name = "<chart-name>" # Insert the name of your helm chart (e.g. hono)
9-
hono_chart_version = "<chart-version>" # Insert the version of your helm chart (e.g. 2.5.0-1)
2+
bucket_name = "<bucket_name>" # Insert the name of the storage bucket
3+
oauth_app_name = "<oauth-app_name>" # Insert the name of your OAuth application
4+
device_communication_dns_name = "<dns_name>" # Insert the name of your API DNS (e.g. api.hono.my-domain.com)
5+
oauth_client_id = "<oauth_client_id>" # Insert the client ID of your OAuth 2.0 client
6+
oauth_client_secret = "<oauth_client_secret>" # Insert the client secret of your OAuth 2.0 client
7+
helm_package_repository = "<helm-package-repository>" # Insert the link to your helm chart (e.g. oci://europe-west1-docker.pkg.dev/my-project/my-repository)
8+
hono_chart_name = "<chart-name>" # Insert the name of your helm chart (e.g. hono)
9+
hono_chart_version = "<chart-version>" # Insert the version of your helm chart (e.g. 2.5.0-1)
1010

11-
enable_cert_manager = false # Toggle the use of the cert-manager
11+
enable_cert_manager = false # Toggle the use of the cert-manager
1212

1313
# In case enable_cert_manager is set to false:
1414
#
@@ -21,6 +21,6 @@ locals {
2121
# note: this is only needed to create the secret or to change it. Otherwise the key and certificate can be omitted.
2222

2323
# The following variable only have to be given values if enable_cert_manager is set to true!
24-
cert_manager_email = "<email>" # Insert an E-Mail address to contact in case something goes wrong with the certificate renewal
25-
wildcard_domain = "<wildcard-domain>" # Insert your root domain with a wildcard character as a sub domain (e.g. *.my-domain.com)
24+
cert_manager_email = "<email>" # Insert an E-Mail address to contact in case something goes wrong with the certificate renewal
25+
wildcard_domain = "<wildcard-domain>" # Insert your root domain with a wildcard character as a sub domain (e.g. *.my-domain.com)
2626
}

terraform/environment-template/software/providers.tf

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@ terraform {
2121

2222
provider "helm" {
2323
kubernetes {
24-
host = "https://${data.google_container_cluster.default.endpoint}"
25-
token = data.google_client_config.default.access_token
24+
host = "https://${data.google_container_cluster.default.endpoint}"
25+
token = data.google_client_config.default.access_token
2626
cluster_ca_certificate = base64decode(
2727
data.google_container_cluster.default.master_auth[0].cluster_ca_certificate,
2828
)
2929
}
3030
}
3131

3232
provider "kubernetes" {
33-
host = "https://${data.google_container_cluster.default.endpoint}"
34-
token = data.google_client_config.default.access_token
33+
host = "https://${data.google_container_cluster.default.endpoint}"
34+
token = data.google_client_config.default.access_token
3535
cluster_ca_certificate = base64decode(
3636
data.google_container_cluster.default.master_auth[0].cluster_ca_certificate,
3737
)
3838
}
3939

4040
provider "kubectl" {
41-
host = "https://${data.google_container_cluster.default.endpoint}"
42-
token = data.google_client_config.default.access_token
41+
host = "https://${data.google_container_cluster.default.endpoint}"
42+
token = data.google_client_config.default.access_token
4343
cluster_ca_certificate = base64decode(
4444
data.google_container_cluster.default.master_auth[0].cluster_ca_certificate,
4545
)

terraform/infrastructure/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ No requirements.
3434
| <a name="input_enable_cert_manager"></a> [enable\_cert\_manager](#input\_enable\_cert\_manager) | Enables the service account needed for the use of cert manager | `bool` | `false` | no |
3535
| <a name="input_enable_http_ip_creation"></a> [enable\_http\_ip\_creation](#input\_enable\_http\_ip\_creation) | Used to enable the creation of a static ip for the http adapter | `string` | `false` | no |
3636
| <a name="input_enable_mqtt_ip_creation"></a> [enable\_mqtt\_ip\_creation](#input\_enable\_mqtt\_ip\_creation) | Used to enable the creation of a static ip for the mqtt adapter | `string` | `true` | no |
37-
| <a name="input_gke_cluster_maintenance_policy_recurring_window"></a> [gke\_cluster\_maintenance\_policy\_recurring\_window](#input\_gke\_cluster\_maintenance\_policy\_recurring\_window) | The recurring window maintenance policy for the cluster. For details see: https://registry.terraform.io/providers/hashicorp/google/5.15.0/docs/resources/container_cluster#nested_maintenance_policy | <pre>object({<br> start_time = string,<br> end_time = string,<br> recurrence = string<br> })</pre> | `null` | no |
37+
| <a name="input_gke_autopilot_enabled"></a> [gke\_autopilot\_enabled](#input\_gke\_autopilot\_enabled) | If autopilot mode should be enabled for the GKE cluster. | `bool` | `false` | no |
38+
| <a name="input_gke_cluster_maintenance_policy_recurring_window"></a> [gke\_cluster\_maintenance\_policy\_recurring\_window](#input\_gke\_cluster\_maintenance\_policy\_recurring\_window) | The recurring window maintenance policy for the cluster. For details see: https://registry.terraform.io/providers/hashicorp/google/5.15.0/docs/resources/container_cluster#nested_maintenance_policy | <pre>object({<br/> start_time = string,<br/> end_time = string,<br/> recurrence = string<br/> })</pre> | `null` | no |
3839
| <a name="input_gke_cluster_name"></a> [gke\_cluster\_name](#input\_gke\_cluster\_name) | Name of the GKE Cluster | `string` | `"hono-cluster"` | no |
3940
| <a name="input_gke_machine_type"></a> [gke\_machine\_type](#input\_gke\_machine\_type) | Machine Type for node\_pools | `string` | `"c2-standard-8"` | no |
4041
| <a name="input_gke_node_pool_name"></a> [gke\_node\_pool\_name](#input\_gke\_node\_pool\_name) | The name of the Node Pool in the Hono Cluster | `string` | `"standard-node-pool"` | no |
4142
| <a name="input_gke_release_channel"></a> [gke\_release\_channel](#input\_gke\_release\_channel) | Which Release Channel to use for the Cluster | `string` | `"STABLE"` | no |
4243
| <a name="input_grafana_expose_externally"></a> [grafana\_expose\_externally](#input\_grafana\_expose\_externally) | Whether or not Grafana should be exposed externally. | `bool` | `false` | no |
44+
| <a name="input_helm_release_name"></a> [helm\_release\_name](#input\_helm\_release\_name) | Name of the helm realease | `string` | `"eclipse-hono"` | no |
4345
| <a name="input_ip_cidr_range"></a> [ip\_cidr\_range](#input\_ip\_cidr\_range) | The range of internal addresses that are owned by this subnetwork. Provide this property when you create the subnetwork.Ranges must be unique and non-overlapping within a network. Only IPv4 is supported. | `string` | `"10.10.1.0/24"` | no |
4446
| <a name="input_node_locations"></a> [node\_locations](#input\_node\_locations) | List of Strings for the Node Locations | `list(string)` | n/a | yes |
4547
| <a name="input_node_pool_autoscaling_enabled"></a> [node\_pool\_autoscaling\_enabled](#input\_node\_pool\_autoscaling\_enabled) | If node autoscaling should be enabled | `string` | `false` | no |
@@ -71,7 +73,7 @@ No requirements.
7173
| <a name="input_sql_instance_disk_type"></a> [sql\_instance\_disk\_type](#input\_sql\_instance\_disk\_type) | Disk Type of the SQL Instance | `string` | `"PD-SSD"` | no |
7274
| <a name="input_sql_instance_ipv4_enable"></a> [sql\_instance\_ipv4\_enable](#input\_sql\_instance\_ipv4\_enable) | Whether this Cloud SQL instance should be assigned a public IPV4 address. At least ipv4\_enabled must be enabled or a private\_network must be configured. | `bool` | `false` | no |
7375
| <a name="input_sql_instance_machine_type"></a> [sql\_instance\_machine\_type](#input\_sql\_instance\_machine\_type) | Machine Type of the SQL Instance | `string` | `"db-custom-1-3840"` | no |
74-
| <a name="input_sql_instance_maintenance_window"></a> [sql\_instance\_maintenance\_window](#input\_sql\_instance\_maintenance\_window) | The maintenance window settings for the cloud sql instance. For details see: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance | <pre>object({<br> day = number,<br> hour = number,<br> update_track = optional(string, "stable")<br> })</pre> | `null` | no |
76+
| <a name="input_sql_instance_maintenance_window"></a> [sql\_instance\_maintenance\_window](#input\_sql\_instance\_maintenance\_window) | The maintenance window settings for the cloud sql instance. For details see: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance | <pre>object({<br/> day = number,<br/> hour = number,<br/> update_track = optional(string, "stable")<br/> })</pre> | `null` | no |
7577
| <a name="input_sql_instance_name"></a> [sql\_instance\_name](#input\_sql\_instance\_name) | Name of the SQL Instance | `string` | `"hono-sql"` | no |
7678
| <a name="input_sql_instance_version"></a> [sql\_instance\_version](#input\_sql\_instance\_version) | Database Version | `string` | `"POSTGRES_14"` | no |
7779
| <a name="input_ssl_policy_min_tls_version"></a> [ssl\_policy\_min\_tls\_version](#input\_ssl\_policy\_min\_tls\_version) | The minimum TLS version the SSL policy should allow | `string` | `"TLS_1_2"` | no |

terraform/infrastructure/main.tf

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ module "gke" {
7979
region = var.region
8080
network_name = module.networking.network_name
8181
subnetwork_name = module.networking.subnetwork_name
82+
gke_autopilot_enabled = var.gke_autopilot_enabled
8283
gke_release_channel = var.gke_release_channel
8384
ip_ranges_services = module.networking.ip_ranges_services_name
8485
ip_ranges_pods = module.networking.ip_ranges_pods_name
@@ -98,6 +99,7 @@ module "gke" {
9899
node_pool_batch_node_count = var.node_pool_batch_node_count
99100
node_pool_batch_soak_duration = var.node_pool_batch_soak_duration
100101
node_pool_soak_duration = var.node_pool_soak_duration
102+
helm_release_name = var.helm_release_name
101103

102104
depends_on = [
103105
google_project_service.project

terraform/infrastructure/outputs.tf

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ output "gke_cluster_name_endpoint" {
4747
output "gke_cluster_ca_certificate" {
4848
value = module.gke.gke_cluster_ca_certificate
4949
description = "CA-Certificate for the cluster."
50+
sensitive = true
5051
}
5152

5253
output "service_name_communication" {

terraform/infrastructure/variables.tf

+12
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ variable "service_account_roles_gke_sa" {
137137
default = []
138138
}
139139

140+
variable "gke_autopilot_enabled" {
141+
type = bool
142+
description = "If autopilot mode should be enabled for the GKE cluster."
143+
default = false
144+
}
145+
140146
variable "gke_release_channel" {
141147
type = string
142148
description = "Which Release Channel to use for the Cluster"
@@ -296,3 +302,9 @@ variable "grafana_expose_externally" {
296302
description = "Whether or not Grafana should be exposed externally."
297303
default = false
298304
}
305+
306+
variable "helm_release_name" {
307+
type = string
308+
description = "Name of the helm realease"
309+
default = "eclipse-hono"
310+
}

terraform/modules/cert_manager/main.tf

+12-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ resource "helm_release" "cert-manager" {
1919
name = "installCRDs"
2020
value = "true"
2121
}
22+
set {
23+
name = "global.leaderElection.namespace"
24+
value = var.cert_manager_namespace
25+
}
2226
}
2327

2428
resource "kubernetes_secret" "cert_manager_sa_key_secret" {
@@ -35,21 +39,22 @@ resource "kubectl_manifest" "issuer_letsencrypt_prod" {
3539
yaml_body = yamlencode({
3640
"apiVersion" = "cert-manager.io/v1"
3741
"kind" = var.cert_manager_issuer_kind
38-
"metadata" = {
42+
"metadata" = {
3943
"name" = var.cert_manager_issuer_name
4044
}
4145
"spec" = {
4246
"acme" = {
43-
"email" = var.cert_manager_email
47+
"email" = var.cert_manager_email
4448
"privateKeySecretRef" = {
4549
"name" = var.cert_manager_issuer_name
4650
}
47-
"server" = "https://acme-v02.api.letsencrypt.org/directory"
51+
# "server" = "https://acme-staging-v02.api.letsencrypt.org/directory" # use this for testing
52+
"server" = "https://acme-v02.api.letsencrypt.org/directory"
4853
"solvers" = [
4954
{
5055
"dns01" = {
5156
"cloudDNS" = {
52-
"project" = var.cert_manager_issuer_project_id
57+
"project" = var.cert_manager_issuer_project_id
5358
"serviceAccountSecretRef" = {
5459
"name" = var.cert_manager_sa_account_id
5560
"key" = "key.json"
@@ -68,15 +73,15 @@ resource "kubectl_manifest" "certificate" {
6873
yaml_body = yamlencode({
6974
"apiVersion" = "cert-manager.io/v1"
7075
"kind" = "Certificate"
71-
"metadata" = {
76+
"metadata" = {
7277
"name" = var.hono_domain_managed_secret_name
7378
"namespace" = var.hono_namespace
7479
}
7580
"spec" = {
7681
"secretName" = var.hono_domain_managed_secret_name
7782
"duration" = var.cert_manager_cert_duration
7883
"renewBefore" = var.cert_manager_cert_renew_before
79-
"issuerRef" = {
84+
"issuerRef" = {
8085
"name" = var.cert_manager_issuer_name
8186
"kind" = var.cert_manager_issuer_kind
8287
}
@@ -102,7 +107,7 @@ resource "kubectl_manifest" "trust-bundle" {
102107
yaml_body = yamlencode({
103108
"apiVersion" = "trust.cert-manager.io/v1alpha1"
104109
"kind" = "Bundle"
105-
"metadata" = {
110+
"metadata" = {
106111
"name" = var.hono_trust_store_config_map_name
107112
}
108113
"spec" = {

terraform/modules/cloud_sql/main.tf

+3
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,17 @@ resource "google_sql_user" "hono-sql-user" {
4747
name = var.sql_db_user_name
4848
instance = google_sql_database_instance.hono_sql.id
4949
password = random_password.password.result
50+
project = var.project_id
5051
}
5152

5253
resource "google_sql_database" "hono_sql_db" {
5354
name = var.sql_hono_database_name
5455
instance = google_sql_database_instance.hono_sql.id
56+
project = var.project_id
5557
}
5658

5759
resource "google_sql_database" "grafana_sql_db" {
5860
name = var.sql_grafana_database_name
5961
instance = google_sql_database_instance.hono_sql.id
62+
project = var.project_id
6063
}

terraform/modules/gke/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,22 @@ No modules.
1616

1717
| Name | Type |
1818
|------|------|
19+
| [google_container_cluster.hono_autopilot_cluster](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster) | resource |
1920
| [google_container_cluster.hono_cluster](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster) | resource |
2021
| [google_container_node_pool.standard_node_pool](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_node_pool) | resource |
2122

2223
## Inputs
2324

2425
| Name | Description | Type | Default | Required |
2526
|------|-------------|------|---------|:--------:|
26-
| <a name="input_gke_cluster_maintenance_policy_recurring_window"></a> [gke\_cluster\_maintenance\_policy\_recurring\_window](#input\_gke\_cluster\_maintenance\_policy\_recurring\_window) | The recurring window maintenance policy for the cluster. For details see: https://registry.terraform.io/providers/hashicorp/google/5.15.0/docs/resources/container_cluster#nested_maintenance_policy | <pre>object({<br> start_time = string,<br> end_time = string,<br> recurrence = string<br> })</pre> | n/a | yes |
27+
| <a name="input_gke_autopilot_enabled"></a> [gke\_autopilot\_enabled](#input\_gke\_autopilot\_enabled) | If autopilot mode should be enabled for the GKE cluster. | `bool` | n/a | yes |
28+
| <a name="input_gke_cluster_maintenance_policy_recurring_window"></a> [gke\_cluster\_maintenance\_policy\_recurring\_window](#input\_gke\_cluster\_maintenance\_policy\_recurring\_window) | The recurring window maintenance policy for the cluster. For details see: https://registry.terraform.io/providers/hashicorp/google/5.15.0/docs/resources/container_cluster#nested_maintenance_policy | <pre>object({<br/> start_time = string,<br/> end_time = string,<br/> recurrence = string<br/> })</pre> | n/a | yes |
2729
| <a name="input_gke_cluster_name"></a> [gke\_cluster\_name](#input\_gke\_cluster\_name) | Name of the GKE Cluster | `string` | n/a | yes |
2830
| <a name="input_gke_machine_type"></a> [gke\_machine\_type](#input\_gke\_machine\_type) | Machine Type for node\_pools | `string` | n/a | yes |
2931
| <a name="input_gke_node_pool_name"></a> [gke\_node\_pool\_name](#input\_gke\_node\_pool\_name) | The name of the Node Pool in the Hono Cluster | `string` | n/a | yes |
3032
| <a name="input_gke_release_channel"></a> [gke\_release\_channel](#input\_gke\_release\_channel) | Which Release Channel to use for the Cluster | `string` | n/a | yes |
3133
| <a name="input_gke_service_account_email"></a> [gke\_service\_account\_email](#input\_gke\_service\_account\_email) | Email of the GKE Service Account | `string` | n/a | yes |
34+
| <a name="input_helm_release_name"></a> [helm\_release\_name](#input\_helm\_release\_name) | Name of the helm realease | `string` | n/a | yes |
3235
| <a name="input_ip_ranges_pods"></a> [ip\_ranges\_pods](#input\_ip\_ranges\_pods) | Secondary IP Ranges in Subnetwork for Pods | `string` | n/a | yes |
3336
| <a name="input_ip_ranges_services"></a> [ip\_ranges\_services](#input\_ip\_ranges\_services) | Secondary IP Ranges in Subnetwork for Services | `string` | n/a | yes |
3437
| <a name="input_network_name"></a> [network\_name](#input\_network\_name) | name of the network | `string` | n/a | yes |

0 commit comments

Comments
 (0)