Skip to content

Commit

Permalink
Merge pull request #25 from fuchicorp/feature/69
Browse files Browse the repository at this point in the history
Deprecate listed tools from common tools (terraform-helm-chart)
  • Loading branch information
devdot4 authored Sep 16, 2021
2 parents d59edbc + 76dd419 commit d08a607
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 122 deletions.
68 changes: 13 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ This terraform module will help you deploy the helm charts on local.

- [Custom Values](#custom-variable-deployment)



## Requirements

Terraform >= 0.11.7
Expand Down Expand Up @@ -54,9 +52,9 @@ module "helm_deploy" {
deployment_name = "example-deployment"
deployment_environment = "dev"
deployment_endpoint = "example.fuchicorp.com"
deployment_path = "example"
deployment_path = "./charts/example"
enabled = "true"
release_version = "0.0.4"
}
EOF
```
Expand All @@ -68,21 +66,18 @@ output "success" {
```

follow the file path

follow the file path:
```yaml
./module.tf
./output.tf
./charts/
/example ## Your chart location
/Chart.yaml
/charts
/templates
/values.yaml
/example ## Your chart location
/Chart.yaml
/charts
/templates
/values.yaml
```



## Variables

For more info, please see the [variables file](variables.tf).
Expand All @@ -94,7 +89,7 @@ For more info, please see the [variables file](variables.tf).
| `deployment_endpoint` | Ingress endpoint `example.fuchicorp.com` | `(Required)` | `domain/string` |
| `deployment_path` | path for helm chart on local | `(Required)` | `string` |
| `release_version` | Specify the exact chart version to install. | `(Required)` | `string` |
| `remote_chart` | Specify if you want to deploy the remote chart to `"True"` default value is `"False"`| `(Optional)` | `bool` |
| `enabled` | Specify if you want to deploy the enabled to `"true"` or `"false"` default value is `"true"`| `(Optional)` | `bool` |
| `values` | Name of the values.yaml file | `(Optional)` | `string` |
| `template_custom_vars` | Template custom veriables you can modify variables by parsting the `template_custom_vars` | `(Optional)` | `map` |
| `env_vars` | Environment veriable for the containers takes map | `(Optional)` | `map` |
Expand All @@ -108,15 +103,14 @@ For more info, please see the [variables file](variables.tf).
```
module "helm_deploy" {
# source = "git::https://github.com/fuchicorp/helm-deploy.git"
source = "fuchicorp/chart/helm"
source = "fuchicorp/chart/helm"
deployment_name = "artemis-deployment"
deployment_environment = "dev"
deployment_endpoint = "artemis.fuchicorp.com"
deployment_path = "artemis"
deployment_path = "./charts/artemis"
release_version = "0.0.4"
template_custom_vars = {
enabled = "true"
template_custom_vars = {
deployment_image = "nginx"
}
}
Expand All @@ -142,40 +136,4 @@ Output file will be:

You can see the `repository` replaced to the right value

## If you would like to deploy remote chart

REMOTE CHARTS are available on versions `"0.0.4"` and up.

In order to deploy remote charts, you should have your own `values.yaml` file,

`module.tf` and `output.tf` in the same folder.

Please follow the steps to configure `module.tf` and `output.tf`

```yaml
./module.tf
./output.tf
./values.yaml
```
`module.tf` file should look like this
```
module "helm_remote_deployment" {
source = "fuchicorp/chart/helm"
deployment_name = "example-deployment" ## The name of the deployment
deployment_environment = "dev" ## Name of the namespace
deployment_endpoint = "example.fuchicorp.com" ## Ingress endpoint
deployment_path = "stable/jenkins" ## Path for helm chart
release_version = "0.0.4" ## Chart version
remote_chart = "true"
values = "values.yaml" ## your values.yaml file
}
```
Next create an simple output file named `output.tf` and copy and paste the following:
```
output "success" {
value = "${module.helm_remote_deployment.success_output}"
}
```

Developed by FuchiCorp DevOps team, Enjoy using it.
66 changes: 22 additions & 44 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,83 +1,61 @@
locals {
required_values = {
## Deployment endpoint for ingress
# Deployment endpoint for ingress
deployment_endpoint = "${lower(var.deployment_endpoint)}"

## <deployment_name> for backend.tf and also release name
deployment_name = "${lower(var.deployment_name)}"

## <env_vars> for global environment variables takes map()
env_vars = "${trimspace(join("\n", data.template_file.env_vars.*.rendered))}"
# <deployment_name> for backend.tf and also release name
deployment_name = "${lower(var.deployment_name)}"
# <env_vars> for global environment variables takes map()
env_vars = "${trimspace(join("\n", data.template_file.env_vars.*.rendered))}"
}

## When all requred values all deffined then also will incloude users values
# When all requred values all deffined then also will incloude users values
template_all_values = "${merge(local.required_values, var.template_custom_vars)}"

timeout = "${var.timeout}"
recreate_pods = "${var.recreate_pods}"
timeout = "${var.timeout}"
recreate_pods = "${var.recreate_pods}"
}

## template_file.env_vars just converting to right values
# template_file.env_vars just converting to right values
data "template_file" "env_vars" {
count = "${length(keys(var.env_vars))}"
template = " $${key}: \"$${value}\""

vars {
key = "${element(keys(var.env_vars), count.index)}"
value = "${element(values(var.env_vars), count.index)}"
}
}

## template_file.chart_values_template actual values.yaml file from charts
# template_file.chart_values_template actual values.yaml file from charts
data "template_file" "chart_values_template" {
count = "${var.remote_chart == "true" ? 0 : 1 }"
template = "${file("charts/${var.deployment_path}/values.yaml")}"

vars = "${local.template_all_values}"
count = "${var.enabled == "true" ? 1 : 0 }"
template = "${file("${var.deployment_path}/values.yaml")}"
vars = "${local.template_all_values}"
}

## This resource was disabled and moved to output please see the ticket
## https://github.com/fuchicorp/terraform-helm-chart/issues/21
# This resource was disabled and moved to output please see the ticket
# https://github.com/fuchicorp/terraform-helm-chart/issues/21
# resource "local_file" "deployment_values" {
# content = "${trimspace(data.template_file.chart_values_template.rendered)}"
# content = "${trimspace(data.template_file.chart_values_template.0.rendered)}"
# filename = "${path.module}/${var.deployment_name}-values.yaml"
# }

output "deployment_values" {
value = "${data.template_file.chart_values_template.0.rendered}"
value = "${data.template_file.chart_values_template.*.rendered}"
description = "This output is for storing values.yaml"
}

locals {
trigger = "${var.trigger == "UUID" ? uuid() : var.trigger}"
}

## helm_release.helm_deployment is actual helm deployment
# helm_release.helm_deployment is actual helm deployment
resource "helm_release" "helm_deployment" {
count = "${var.remote_chart == "true" ? 0 : 1 }"
name = "${var.deployment_name}-${var.deployment_environment}"
namespace = "${var.deployment_environment}"
chart = "./charts/${var.deployment_path}"
timeout = "${local.timeout}"
recreate_pods = "${local.recreate_pods}"
version = "${var.release_version}"

values = [
"${trimspace(data.template_file.chart_values_template.rendered)}",
]
}

## helm_release.helm_deployment is actual helm deployment
resource "helm_release" "helm_remote_deployment" {
count = "${var.remote_chart == "true" ? 1 : 0 }"
count = "${var.enabled == "true" ? 1 : 0}"
name = "${var.deployment_name}-${var.deployment_environment}"
namespace = "${var.deployment_environment}"
chart = "${var.deployment_path}"
timeout = "${local.timeout}"
recreate_pods = "${local.recreate_pods}"
version = "${var.release_version}"
values = [
"${file("${var.values}")}"
values = [
"${trimspace(data.template_file.chart_values_template.rendered)}",
]

}
}
45 changes: 22 additions & 23 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,56 +1,55 @@
## The name of the deployment
# The name of the deployment
variable "deployment_name" {
description = "The name of the deployment"
}

## The name of the environment
# The name of the environment
variable "deployment_environment" {
description = "The name of the environment"
}

## Chart location or chart name
# Chart location or chart name
variable "deployment_path" {
description = "Chart location or chart name <stable/example>"
}

## Endpoint for the application
# Endpoint for the application
variable "deployment_endpoint" {
description = "Endpoint for the application"
}

variable "template_custom_vars" {
type = "map"
default = {}
type = "map"
default = {}
}

variable "env_vars" {
type = "map"
default = {}
type = "map"
default = {}
}

variable "trigger" {
default = "UUID"
default = "UUID"
}

variable "timeout" {
default = "400"
default = "400"
}

variable "recreate_pods" {
default = false
default = false
}
variable "release_version" {
description = "(Required) Specify the exact chart version to install"
default = " 0.1.0"

}

variable "release_version" {
description = "(Required) Specify the exact chart version to install"
default = " 0.1.0"

}

variable "enabled" {
default = "true"
}

variable "remote_chart" {
default = "false"
}

variable "values" {
default = "values.yaml"
}

default = "values.yaml"
}

0 comments on commit d08a607

Please sign in to comment.