Skip to content

Instantly share code, notes, and snippets.

@oniku-2929
Last active September 30, 2022 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oniku-2929/63eb8e54c9d88e5af0de9fdf1dbefd53 to your computer and use it in GitHub Desktop.
Save oniku-2929/63eb8e54c9d88e5af0de9fdf1dbefd53 to your computer and use it in GitHub Desktop.
Example terraform template for using resource "helm_release" to make jenkins environment on Minikube.
#Requirements, before applying this file, it's required below.
#1.install minikube -> https://minikube.sigs.k8s.io/docs/start/
#2.install helm -> https://helm.sh/docs/intro/install/
#3.run "helm repo add jenkins https://charts.jenkins.io" -> https://github.com/jenkinsci/helm-charts#usage
terraform {
backend "local" {}
required_providers {
helm = {
source = "hashicorp/helm"
version = ">= 2.6.0"
}
}
}
provider "helm" {
kubernetes {
config_path = "~/.kube/config"
}
}
variable "namespace" {
type = string
default = "jenkins"
}
variable "helm_release_name" {
type = string
default = "jenkins-k8s-example"
}
variable "helm_chart_version" {
type = string
default = "4.2.5"
}
variable "helm_chart_name" {
type = string
default = "jenkins/jenkins"
}
variable "helm_values" {
type = list(list(string))
default = [
["controller.serviceType", "NodePort"],
["controller.adminSecret", "true"],
]
}
variable "helm_values_file" {
type = string
default = "jenkins_minikube_values.yaml"
}
data "helm_template" "jenkins" {
name = var.helm_release_name
chart = var.helm_chart_name
namespace = var.namespace
version = var.helm_chart_version
dynamic "set" {
for_each = var.helm_values
content {
name = set.value[0]
value = set.value[1]
}
}
#if you want to use -values option on helm
#values = [
# file(var.helm_values_file)
#]
}
output "jenkins_manifests" {
value = data.helm_template.jenkins.manifests
}
resource "helm_release" "jenkins" {
name = data.helm_template.jenkins.name
chart = data.helm_template.jenkins.chart
namespace = data.helm_template.jenkins.namespace
version = data.helm_template.jenkins.version
create_namespace = true
dynamic "set" {
for_each = var.helm_values
content {
name = set.value[0]
value = set.value[1]
}
}
#if you want to use -values option on helm
#values = [
# file(var.helm_values_file)
#]
}
controller:
serviceType: NodePort
adminSecret: true
MIT License
Copyright (c) 2022 oniku-2929
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment