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

Add Consul Helm chart for cluster #2

Merged
merged 2 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
63 changes: 63 additions & 0 deletions consul/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions consul/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Consul `doks`

> This directory contains [Digital Ocean](https://registry.terraform.io/providers/digitalocean/digitalocean) Resources.

## Requirements

* Terraform CLI `1.0.8` or newer
* a Digital Ocean [account](https://m.do.co/c/b73b4af31c09)

## TODO
ksatirli marked this conversation as resolved.
Show resolved Hide resolved

18 changes: 18 additions & 0 deletions consul/data-sources.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# see https://www.terraform.io/docs/language/state/remote-state-data.html#example-usage-remote-backend-
data "terraform_remote_state" "clusters" {
backend = "remote"

config = {
organization = "a-demo-organization"

workspaces = {
name = "multi-cloud-k8s-outputs"
}
}
}

# see https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs/data-sources/kubernetes_cluster
data "digitalocean_kubernetes_cluster" "cluster" {
# dynamically retrieve the DOKS Cluster Name from Terraform State from the `outputs` Workspace
name = data.terraform_remote_state.clusters.outputs.clusters.doks.cluster_name
}
20 changes: 20 additions & 0 deletions consul/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module "consul_on_doks" {
source = "./modules/consul"

providers = {
helm = helm.doks
kubernetes = kubernetes.doks
}

# NOTE: this is NOT the version of Vault to use
chart_version = "0.34.1"
}

#module "consul_on_gke" {
ksatirli marked this conversation as resolved.
Show resolved Hide resolved
# source = "./modules/consul"
#
# providers = {
# helm = helm.gke
# kubernetes = kubernetes.gke
# }
#}
18 changes: 18 additions & 0 deletions consul/modules/consul/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Helm Deployment of HashiCorp Consul

See [hashicorp/consul-k8s](https://github.com/hashicorp/consul-k8s) for more information.

It enables the following:

### Consul

- Access control lists
- Agent metrics
- Proxy metrics
- Transparent proxy
- Consul UI at a load balancer
- Controller for CRDs

### Prometheus

- For collecting metrics from applications and Consul.
13 changes: 13 additions & 0 deletions consul/modules/consul/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# see https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release
resource "helm_release" "consul" {
chart = "consul"
name = "consul"
repository = "https://helm.releases.hashicorp.com/"

# see https://github.com/hashicorp/consul-k8s/tags
version = var.chart_version # NOTE: this is NOT the version of Consul to use

values = [
file("${path.module}/values.yml")
]
}
16 changes: 16 additions & 0 deletions consul/modules/consul/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
terraform {
# see https://www.terraform.io/docs/language/settings/index.html#specifying-provider-requirements
required_providers {
# see https://registry.terraform.io/providers/hashicorp/helm/2.3.0/docs
helm = {
source = "hashicorp/helm"
version = "2.3.0"
}

# see https://registry.terraform.io/providers/hashicorp/kubernetes/2.5.0/docs
kubernetes = {
source = "hashicorp/kubernetes"
version = "2.5.0"
}
}
}
30 changes: 30 additions & 0 deletions consul/modules/consul/values.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
joatmon08 marked this conversation as resolved.
Show resolved Hide resolved
global:
name: consul
acls:
manageSystemACLs: true
metrics:
enabled: true
enableAgentMetrics: true

prometheus:
enabled: true

server:
replicas: 1

client:
enabled: true

connectInject:
enabled: true
transparentProxy:
defaultEnabled: true

ui:
enabled: true
service:
type: LoadBalancer

controller:
enabled: true
4 changes: 4 additions & 0 deletions consul/modules/consul/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "chart_version" {
type = string
description = "Specify the exact chart version to install."
joatmon08 marked this conversation as resolved.
Show resolved Hide resolved
}
27 changes: 27 additions & 0 deletions consul/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# see https://registry.terraform.io/providers/digitalocean/digitalocean/latest
provider "digitalocean" {
token = var.do_token
api_endpoint = "https://api.digitalocean.com"
}

# see https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs
provider "kubernetes" {
# see https://www.terraform.io/docs/language/providers/configuration.html#alias-multiple-provider-configurations
alias = "doks"

cluster_ca_certificate = base64decode(data.digitalocean_kubernetes_cluster.cluster.kube_config[0].cluster_ca_certificate)
host = data.digitalocean_kubernetes_cluster.cluster.endpoint
token = data.digitalocean_kubernetes_cluster.cluster.kube_config[0].token
}

# see https://registry.terraform.io/providers/hashicorp/helm/latest/docs
provider "helm" {
# see https://www.terraform.io/docs/language/providers/configuration.html#alias-multiple-provider-configurations
alias = "doks"

kubernetes {
cluster_ca_certificate = base64decode(data.digitalocean_kubernetes_cluster.cluster.kube_config[0].cluster_ca_certificate)
host = data.digitalocean_kubernetes_cluster.cluster.endpoint
token = data.digitalocean_kubernetes_cluster.cluster.kube_config[0].token
}
}
35 changes: 35 additions & 0 deletions consul/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
terraform {
# see https://www.terraform.io/docs/language/settings/backends/remote.html
backend "remote" {
hostname = "app.terraform.io"
organization = "a-demo-organization"

workspaces {
name = "multi-cloud-consul-doks"
}
}

# see https://www.terraform.io/docs/language/settings/index.html#specifying-provider-requirements
required_providers {
# see https://registry.terraform.io/providers/digitalocean/digitalocean/2.14.0
digitalocean = {
source = "digitalocean/digitalocean"
version = "2.14.0"
}

# see https://registry.terraform.io/providers/hashicorp/helm/2.3.0/docs
helm = {
source = "hashicorp/helm"
version = "2.3.0"
}

# see https://registry.terraform.io/providers/hashicorp/kubernetes/2.5.0/docs
kubernetes = {
source = "hashicorp/kubernetes"
version = "2.5.0"
}
}

# see https://www.terraform.io/docs/language/settings/index.html#specifying-a-required-terraform-version
required_version = "1.0.8"
}
1 change: 1 addition & 0 deletions consul/terraform.tfvars.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
do_token = "..."
11 changes: 11 additions & 0 deletions consul/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
variable "do_region" {
type = string
description = "he slug identifier for the region where the resources will be created."
default = "sfo3" # San Francisco, CA
}

variable "do_token" {
type = string
description = "This is the DO API token."
sensitive = true
}