Skip to content

Commit 36bf637

Browse files
authored
feat: enable rancher helm chart values (rancher#105)
Signed-off-by: matttrach <matt.trachier@suse.com>
1 parent 3df73bf commit 36bf637

26 files changed

Lines changed: 301 additions & 355 deletions

File tree

examples/three/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Three
2+
3+
This module was developed working closely with specific customer feedback.
4+
5+
## Goals
6+
7+
- three node HA Rancher cluster where each node has all Kubernetes roles
8+
- the ability to specify a helm repo for the Rancher install (specifically the prime repo)
9+
- the ability to specify custom values for Rancher helm chart
10+
- the ability to use a remote backend, updating the infrastructure using a CI tool
11+

examples/three/main.tf

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ provider "rancher2" {
2424

2525
terraform {
2626
backend "s3" {
27-
# This needs to be set in the backend configs on the command line.
28-
# bucket = local.identifier
27+
# This needs to be set in the backend configs on the command line or somewhere that your identifier can be set.
28+
# terraform init -reconfigure -backend-config="bucket=<identifier>"
2929
# https://developer.hashicorp.com/terraform/language/backend/s3
3030
# https://developer.hashicorp.com/terraform/language/backend#partial-configuration
3131
key = "tfstate"
@@ -62,10 +62,25 @@ locals {
6262
acme_server_url = "https://acme-v02.api.letsencrypt.org"
6363
owner = var.owner
6464
rke2_version = var.rke2_version
65+
rancher_helm_repo = "https://releases.rancher.com/server-charts"
66+
rancher_helm_channel = "stable"
67+
helm_chart_strategy = "provide"
68+
# These options use the Let's Encrypt cert that the module generates for you when you deploy the VPC and Domain.
69+
# WARNING! "hostname" must be an fqdn
70+
helm_chart_values = {
71+
"hostname" = "${local.domain}.${local.zone}"
72+
"replicas" = "2"
73+
"bootstrapPassword" = "admin"
74+
"ingress.enabled" = "true"
75+
"ingress.tls.source" = "secret"
76+
"ingress.tls.secretName" = "tls-rancher-ingress"
77+
"privateCA" = "true"
78+
"agentTLSMode" = "system-store"
79+
}
6580
local_file_path = var.file_path
6681
runner_ip = chomp(data.http.myip.response_body) # "runner" is the server running Terraform
6782
rancher_version = var.rancher_version
68-
cert_manager_version = "1.16.3" # "1.13.1"
83+
cert_manager_version = "1.18.1" #"1.16.3"
6984
os = "sle-micro-61"
7085
}
7186

@@ -115,8 +130,13 @@ module "rancher" {
115130
}
116131
}
117132
# rancher
118-
cert_manager_version = local.cert_manager_version
119-
rancher_version = local.rancher_version
133+
cert_manager_version = local.cert_manager_version
134+
configure_cert_manager = false # use the cert generated at the project level
135+
rancher_version = local.rancher_version
136+
rancher_helm_repo = local.rancher_helm_repo
137+
rancher_helm_channel = local.rancher_helm_channel
138+
rancher_helm_chart_use_strategy = local.helm_chart_strategy
139+
rancher_helm_chart_values = local.helm_chart_values
120140
}
121141

122142
data "rancher2_cluster" "local" {

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

main.tf

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,19 @@ locals {
2828
cni = var.cni
2929
node_configuration = var.node_configuration
3030
# rancher
31-
cert_manager_version = var.cert_manager_version
32-
rancher_version = var.rancher_version
33-
ip_family = "ipv4"
34-
# ingress_controller = "nginx"
35-
bootstrap_rancher = var.bootstrap_rancher
36-
install_cert_manager = var.install_cert_manager
37-
configure_cert_manager = var.configure_cert_manager
38-
cert_manager_config = var.cert_manager_configuration
31+
cert_name = (var.tls_cert_name != "" ? var.tls_cert_name : module.cluster.cert.name)
32+
cert_key = (var.tls_cert_key != "" ? var.tls_cert_key : module.cluster.cert.key_id)
33+
cert_manager_version = var.cert_manager_version
34+
rancher_version = var.rancher_version
35+
rancher_helm_repo = var.rancher_helm_repo
36+
rancher_helm_channel = var.rancher_helm_channel
37+
ip_family = "ipv4"
38+
rancher_helm_chart_values = var.rancher_helm_chart_values
39+
rancher_helm_chart_use_strategy = var.rancher_helm_chart_use_strategy
40+
bootstrap_rancher = var.bootstrap_rancher
41+
install_cert_manager = var.install_cert_manager
42+
configure_cert_manager = var.configure_cert_manager
43+
cert_manager_config = var.cert_manager_configuration
3944
}
4045

4146
data "aws_route53_zone" "zone" {
@@ -59,7 +64,6 @@ module "cluster" {
5964
cni = local.cni
6065
node_configuration = local.node_configuration
6166
ip_family = local.ip_family
62-
# ingress_controller = local.ingress_controller
6367
skip_cert_creation = local.skip_cert
6468
}
6569

@@ -72,8 +76,8 @@ module "install_cert_manager" {
7276
project_domain = local.fqdn
7377
zone = local.zone
7478
zone_id = data.aws_route53_zone.zone.zone_id
75-
project_cert_name = module.cluster.cert.name
76-
project_cert_key_id = module.cluster.cert.key_id
79+
project_cert_name = local.cert_name
80+
project_cert_key_id = local.cert_key
7781
path = local.local_file_path
7882
cert_manager_version = local.cert_manager_version
7983
configure_cert_manager = local.configure_cert_manager
@@ -85,15 +89,19 @@ module "rancher_bootstrap" {
8589
module.cluster,
8690
module.install_cert_manager,
8791
]
88-
count = (local.bootstrap_rancher ? 1 : 0)
89-
source = "./modules/rancher_bootstrap"
90-
path = local.local_file_path
91-
project_domain = local.fqdn
92-
zone_id = data.aws_route53_zone.zone.zone_id
93-
region = local.cert_manager_config.aws_region
94-
email = local.cert_manager_config.acme_email
95-
acme_server_url = local.cert_manager_config.acme_server_url
96-
rancher_version = local.rancher_version
97-
cert_manager_version = local.cert_manager_version
98-
externalTLS = (local.configure_cert_manager ? false : true)
92+
count = (local.bootstrap_rancher ? 1 : 0)
93+
source = "./modules/rancher_bootstrap"
94+
path = local.local_file_path
95+
project_domain = local.fqdn
96+
zone_id = data.aws_route53_zone.zone.zone_id
97+
region = local.cert_manager_config.aws_region
98+
email = local.cert_manager_config.acme_email
99+
acme_server_url = local.cert_manager_config.acme_server_url
100+
rancher_version = local.rancher_version
101+
rancher_helm_repo = local.rancher_helm_repo
102+
rancher_helm_channel = local.rancher_helm_channel
103+
cert_manager_version = local.cert_manager_version
104+
externalTLS = (local.configure_cert_manager ? false : true)
105+
rancher_helm_chart_values = local.rancher_helm_chart_values
106+
rancher_helm_chart_use_strategy = local.rancher_helm_chart_use_strategy
99107
}

modules/cluster/main.tf

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ locals {
2525
var.file_path != "" ? (var.file_path == path.root ? "${path.root}/rke2" : var.file_path) :
2626
"${path.root}/rke2"
2727
)
28-
# # tflint-ignore: terraform_unused_declarations
29-
# local_file_path_validate = (can(regex(
30-
# "^\\.",
31-
# local.local_file_path
32-
# )) ? false : one([local.local_file_path, "local_file_path_must_be_relative"])) # used like this we can validate local variables
3328

3429
install_method = var.install_method
3530
download = (local.install_method == "tar" ? "download" : "skip")
@@ -182,8 +177,7 @@ module "deploy_initial_node" {
182177
user_workfolder = strcontains(each.value.os, "cis") ? "/var/tmp" : "/home/${local.username}"
183178
timeout = 10
184179
}))}"
185-
server_domain_name = "${substr("${local.project_name}-${md5(each.key)}", 0, 25)}"
186-
server_domain_zone = "${local.zone}"
180+
server_add_domain = false
187181
install_use_strategy = "${local.install_method}"
188182
local_file_use_strategy = "${local.download}"
189183
local_file_path = "${each.value.deploy_path}/configs"
@@ -227,7 +221,7 @@ strcontains(each.value.type, "database") ? local.database_config :
227221
}
228222

229223
# There are many ways to orchestrate Terraform configurations with the goal of breaking it down
230-
# In this example I am using Terraform resources to orchestrate Terraform
224+
# In this module I am using Terraform resources to orchestrate Terraform
231225
# I felt this was the best way to accomplish the goal without incurring additional dependencies
232226
module "deploy_additional_nodes" {
233227
source = "../deploy"
@@ -271,8 +265,7 @@ module "deploy_additional_nodes" {
271265
user_workfolder = strcontains(each.value.os, "cis") ? "/var/tmp" : "/home/${local.username}"
272266
timeout = 10
273267
}))}"
274-
server_domain_name = "${substr("${local.project_name}-${md5(each.key)}", 0, 25)}"
275-
server_domain_zone = "${local.zone}"
268+
server_add_domain = false
276269
install_use_strategy = "${local.install_method}"
277270
local_file_use_strategy = "${local.download}"
278271
local_file_path = "${each.value.deploy_path}/configs"
@@ -318,7 +311,7 @@ strcontains(each.value.type, "database") ? local.database_config :
318311
EOT
319312
}
320313

321-
resource "local_file" "kubeconfig" {
314+
resource "local_sensitive_file" "kubeconfig" {
322315
depends_on = [
323316
module.deploy_initial_node,
324317
module.deploy_additional_nodes,

modules/cluster/variables.tf

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ variable "zone" {
2828
# access
2929
variable "key_name" {
3030
type = string
31-
description = "The name of an ssh key that already exists in AWS of that you want to create."
31+
description = "The name of an ssh key that already exists in AWS."
3232
}
3333
variable "key" {
3434
type = string
@@ -112,10 +112,6 @@ variable "ip_family" {
112112
type = string
113113
description = "The IP family to use. Must be 'ipv4', 'ipv6', or 'dualstack'."
114114
}
115-
# variable "ingress_controller" {
116-
# type = string
117-
# description = "The ingress controller to use. Must be 'nginx' or 'traefik'. Currently only supports 'nginx'."
118-
# }
119115
variable "skip_cert_creation" {
120116
type = bool
121117
description = "Skip the generation of a certificate, useful when configuring cert manager."

modules/install_cert_manager/configured/variables.tf

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ variable "cert_manager_version" {
33
description = <<-EOT
44
The version of cert manager to install.
55
EOT
6-
default = "v1.13.1"
76
}
87
variable "cert_manager_configuration" {
98
type = object({
@@ -18,13 +17,7 @@ variable "cert_manager_configuration" {
1817
https://cert-manager.io/docs/configuration/acme/dns01/route53/#ambient-credentials
1918
https://docs.aws.amazon.com/sdkref/latest/guide/environment-variables.html
2019
EOT
21-
default = {
22-
aws_region = ""
23-
aws_session_token = ""
24-
aws_access_key_id = ""
25-
aws_secret_access_key = ""
26-
}
27-
sensitive = true
20+
sensitive = true
2821
}
2922
variable "zone" {
3023
type = string

modules/install_cert_manager/main.tf

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,12 @@ module "deploy_cert_manager" {
3030
KUBECONFIG = "${abspath(local.path)}/kubeconfig"
3131
}
3232
inputs = <<-EOT
33+
cert_manager_version = "${local.cert_manager_version}"
34+
project_cert_name = "${local.project_cert_name}"
35+
project_cert_key_id = "${local.project_cert_key_id}"
3336
project_domain = "${local.rancher_domain}"
3437
zone = "${local.zone}"
3538
zone_id = "${local.zone_id}"
36-
project_cert_name = "${local.project_cert_name}"
37-
project_cert_key_id = "${local.project_cert_key_id}"
38-
cert_manager_version = "${local.cert_manager_version}"
39-
configure_cert_manager = "${local.configure_cert_manager}"
4039
cert_manager_configuration = {
4140
aws_region = "${local.cert_manager_config.aws_region}"
4241
aws_session_token = "${local.cert_manager_config.aws_session_token}"

modules/install_cert_manager/unconfigured/variables.tf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,16 @@ variable "cert_manager_version" {
33
description = <<-EOT
44
The version of cert manager to install.
55
EOT
6-
default = "v1.13.1"
76
}
87
variable "project_cert_key_id" {
98
type = string
109
description = <<-EOT
1110
The key name to retrieve the project's cert's private key from AWS
1211
EOT
13-
default = ""
1412
}
1513
variable "project_cert_name" {
1614
type = string
1715
description = <<-EOT
1816
The project's cert name
1917
EOT
20-
default = ""
2118
}

modules/install_cert_manager/variables.tf

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ variable "cert_manager_version" {
4545
description = <<-EOT
4646
The version of cert manager to install.
4747
EOT
48-
default = "v1.13.1"
4948
}
5049
variable "configure_cert_manager" {
5150
type = bool
@@ -75,14 +74,3 @@ variable "cert_manager_configuration" {
7574
}
7675
sensitive = true
7776
}
78-
# variable "backend_file" {
79-
# type = string
80-
# description = <<-EOT
81-
# Path to a .tfbackend file.
82-
# This allows the user to pass a backend file.
83-
# The backend file will be added to the terraform run and will allow state data to be saved remotely.
84-
# Please note that this is a separate state file, and this backend should be independent of the main module's state and any other submodules' states.
85-
# See https://developer.hashicorp.com/terraform/language/backend#file for more information.
86-
# EOT
87-
# default = ""
88-
# }

0 commit comments

Comments
 (0)