Skip to content

Commit

Permalink
🎉 initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
colinwilson committed May 6, 2022
0 parents commit f893b7d
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/terraform.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: 'Terraform GitHub Actions'

on:
pull_request:

jobs:
terraform-fmt:
name: Terraform Format
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]

- name: Setup Terraform
uses: hashicorp/setup-terraform@v1

- name: Terraform Format
id: fmt
run: terraform fmt -diff -check -no-color -recursive
continue-on-error: true

- uses: actions/github-script@v4
if: github.event_name == 'pull_request' && steps.fmt.outputs.exitcode != 0
env:
TF_FMT_STDOUT: "${{ steps.fmt.outputs.stdout }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Terraform Format and Style 🖌 - \`${{ steps.fmt.outcome }}\`
\`\`\`diff
${process.env.TF_FMT_STDOUT}
\`\`\`
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Workflow: \`${{ github.workflow }}\`*`;
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
throw "failed to run `terraform fmt -check -recursive -diff`"
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.terraform.*
.terraform/
terraform.tfstate*
terraform.tfvars
terraform.txt
.auto.tfvars
creds/
.vscode/
.idea
debug.log
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 AIGIS UK (Lotus Labs Ltd)

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.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Terraform Helm InfluxDB v2 Module
A Terraform module to deploy [InfluxDB v2](https://github.com/influxdata/influxdb) on a Kubernetes Cluster using the [Helm Provider](https://registry.terraform.io/providers/hashicorp/helm).

![Concept Flow Illustration](https://user-images.githubusercontent.com/12916656/167049505-1a2c7aa6-d605-49d8-b295-83a69e2c8973.svg)

## Default Admin Password & Token

If the `admin_password` or `admin-token` input variables are **not** set, the initial password & token for the `admin` user account are auto-generated and stored as clear text in the `admin-password` and `admin-token` fields of a secret named `influxdb2-auth`[^1] in your InfluxDB installation namespace (`influxdb` by default). You can retrieve these values via the `kubectl` command:

```
kubectl -n influxdb get secret influxdb2-auth -o jsonpath="{.data.admin-password}" | base64 -d; echo
```

Substitute `admin-password` in the above command with `admin-token` to retrieve the default Admin user token.

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| release_name | Helm release name | string | `influxdb2` | no |
| namespace | Namespace to install InfluxDB chart into (created if non-existent on target cluster) | string | `influxdb` | no |
| influxdb_chart_version | Version of InfluxDB chart to install | string | `2.0.12` | no |
| timeout_seconds | Helm chart deployment can sometimes take longer than the default 5 minutes. Set a custom timeout (secs) | number | `800` | no |
| admin_password | Default Admin password (minimum 8 chars) | string | empty | no |
| admin_token | Default Admin token | string | empty | no |
| enable_persistence | Persist data to a persistent volume? | bool | `false` | no |
| pv_size | Size persistent volume to provision | bool | `false` | no |
| values_file | Name of the InfluxDB helm chart values file to use | string | `values.yaml` | no |


[^1]: [InfluxDB v2 Helm Chart - Fixed Auth Credentials](https://artifacthub.io/packages/helm/influxdata/influxdb2#fixed-auth-credentials)
36 changes: 36 additions & 0 deletions chart.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Install InfluxDB v2 helm_chart
resource "helm_release" "influxdb2" {
namespace = var.namespace
create_namespace = true
name = var.release_name
repository = "https://helm.influxdata.com"
chart = "influxdb2"
version = var.influxdb_chart_version

# Helm chart deployment can sometimes take longer than the default 5 minutes
timeout = var.timeout_seconds

# If values file specified by the var.values_file input variable exists then apply the values from this file
# else apply the default values from the chart
values = [fileexists("${path.root}/${var.values_file}") == true ? file("${path.root}/${var.values_file}") : ""]

set_sensitive {
name = "adminUser.password"
value = var.admin_password
}

set_sensitive {
name = "adminUser.token"
value = var.admin_token
}

set {
name = "persistence.enabled"
value = var.enable_persistence
}

set {
name = "persistence.size"
value = var.pv_size
}
}
20 changes: 20 additions & 0 deletions examples/default/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Default Deployment Example

This example illustrates how to use the `terraform-kubernetes-influxdb` module.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| release_name | Helm release name | string | `influxdb2` | no |
| namespace | Namespace to install InfluxDB chart into (created if non-existent on target cluster) | string | `influxdb` | no |
| influxdb_chart_version | Version of InfluxDB chart to install | string | `2.0.12` | no |
| timeout_seconds | Helm chart deployment can sometimes take longer than the default 5 minutes. Set a custom timeout (secs) | number | `800` | no |
| admin_password | Default Admin password (minimum 8 chars) | string | empty | no |
| admin_token | Default Admin token | string | empty | no |
| enable_persistence | Persist data to a persistent volume? | bool | `false` | no |
| pv_size | Size persistent volume to provision | bool | `false` | no |
| values_file | Name of the InfluxDB helm chart values file to use | string | `values.yaml` | no |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
19 changes: 19 additions & 0 deletions examples/default/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
terraform {
required_providers {
helm = {
source = "hashicorp/helm"
version = ">= 2.0.1"
}
}
}

provider "helm" {
kubernetes {
config_path = "~/.kube/config" # path to your kubeconfig file
}
}

module "argocd" {
//source = "github.com/aigisuk/terraform-kuberenetes-influxdb"
source = "aigisuk/influxdb/kubernetes"
}
2 changes: 2 additions & 0 deletions examples/default/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
variable "admin_password" {}
variable "admin_token" {}
Empty file added outputs.tf
Empty file.
57 changes: 57 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
variable "release_name" {
type = string
description = "Helm release name"
default = "influxdb2"
}
variable "namespace" {
description = "Namespace to install InfluxDB chart into"
type = string
default = "influxdb"
}

variable "influxdb_chart_version" {
description = "Version of InfluxDB chart to install"
type = string
default = "2.0.12" # See https://artifacthub.io/packages/helm/influxdata/influxdb2 for latest version(s)
}

# Helm chart deployment can sometimes take longer than the default 5 minutes
variable "timeout_seconds" {
type = number
description = "Helm chart deployment can sometimes take longer than the default 5 minutes. Set a custom timeout here."
default = 800 # 10 minutes
}

variable "admin_password" {
description = "Default Admin Password"
type = string
default = ""
validation {
condition = var.admin_password != "" ? length(var.admin_password) >= 8 : true
error_message = "Admin password must be at least 8 characters in length."
}
}

variable "admin_token" {
description = "Default Admin Token"
type = string
default = ""
}

variable "values_file" {
description = "The name of the InfluxDB helm chart values file to use"
type = string
default = "values.yaml"
}

variable "enable_persistence" {
description = "Persist data to a persistent volume?"
type = bool
default = false
}

variable "pv_size" {
type = string
description = "Size of the persistent volume (if persistence is enabled)"
default = "0.5Gi"
}
9 changes: 9 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_providers {
helm = {
source = "hashicorp/helm"
version = ">= 2.0.1"
}
}
required_version = ">= 0.15"
}

0 comments on commit f893b7d

Please sign in to comment.