Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: modular folder structure to install infra-helm-chart dependency #3

Merged
merged 2 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/tf-helm-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ jobs:
- name: Setup `Terraform`
uses: hashicorp/setup-terraform@v2

- name: Enter root tf directory
run: |
cd root

- name: Terraform fmt
id: fmt
run: terraform fmt -check
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Terraform Helm Provider

This terraform code is to deploy Helm charts on GKE(GCP) cluster using terraform [`Terraform Helm Provider`](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release)
This terraform code is to deploy Helm charts on GKE(GCP) cluster in prod OR minikube cluster locally using terraform [`Terraform Helm Provider`](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release)

The helm chart installation cluster depends on the `kubernetes` `config_path` in the `helm` provider.

```tf
provider "helm" {
kubernetes {
config_path = "~/.kube/config"
}
}
```

Based on the `KUBECONFIG` value, the helm chart will be installed on that particular cluster.

> Due to an on-going issue with Terraform Helm Provider [[reference](https://github.com/hashicorp/terraform-provider-helm/issues/932)] which prevents the Terraform resource to pull a chart from a private GitHub repository (even after providing a GitHub PAT), we are forced to install the Helm chart locally.
2 changes: 0 additions & 2 deletions example.tfvars

This file was deleted.

10 changes: 0 additions & 10 deletions main.tf

This file was deleted.

Binary file not shown.
12 changes: 12 additions & 0 deletions modules/infra_helm/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# https://github.com/hashicorp/terraform-provider-helm/issues/467#issuecomment-617856419
resource "helm_release" "infra_dependencies" {
name = var.release_name
namespace = var.namespace
create_namespace = true
repository = "https://github.com/csye7125-fall2023-group05/infra-helm-chart.git"
chart = "${var.chart_path}/infra-helm-chart-1.1.0.tar.gz"
wait = false # prevents "pending-install" helm install state
version = "1.1.0"
values = ["${file(var.values_file)}"]
timeout = var.timeout
}
Empty file added modules/infra_helm/output.tf
Empty file.
5 changes: 5 additions & 0 deletions modules/infra_helm/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "namespace" {}
variable "timeout" {}
variable "values_file" {}
variable "chart_path" {}
variable "release_name" {}
3 changes: 2 additions & 1 deletion .gitignore → root/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ override.tf.json

# variables
dev.tfvars
prod.tfvars
prod.tfvars
values.yaml
8 changes: 8 additions & 0 deletions root/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# terraform {
# backend "s3" {
# bucket = "tfstate-sid"
# key = "backend/infra-jenkins.tfstate"
# region = "us-east-1"
# dynamodb_table = "infra-state"
# }
# }
5 changes: 5 additions & 0 deletions root/example.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace = "webapp"
timeout = 600
values_file = "./values.yaml"
chart_path = "../modules/infra_helm/charts"
release_name = "infra-helm-release"
8 changes: 8 additions & 0 deletions root/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module "infra_dependencies" {
source = "../modules/infra_helm"
namespace = var.namespace
timeout = var.timeout
values_file = var.values_file
chart_path = var.chart_path
release_name = var.release_name
}
6 changes: 3 additions & 3 deletions provider.tf → root/provider.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "4.63.1"
helm = {
source = "hashicorp/helm"
version = "2.11.0"
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions root/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
variable "namespace" {
default = "default"
type = string
description = "Namespace in which to deploy the chart"
}

variable "timeout" {
type = number
description = "The max time to run the helm release"
default = 30
}

variable "values_file" {
type = string
description = "The path to the values.yaml file for the helm chart"
default = "./values.yaml"
}

variable "chart_path" {
type = string
description = "The path to the charts/ directory to install local charts"
default = "../modules/infra_helm/charts"
}

variable "release_name" {
type = string
description = "The name of the helm chart release"
default = "infra-helm-release"
}
10 changes: 0 additions & 10 deletions variables.tf

This file was deleted.