File tree Expand file tree Collapse file tree 9 files changed +140
-0
lines changed
Expand file tree Collapse file tree 9 files changed +140
-0
lines changed Original file line number Diff line number Diff line change 1+ # terraform-docker-vault-dev
2+ A Terraform module to provision a HashiCorp [ Vault] ( https://learn.hashicorp.com/vault ) development container on a Docker host proxied by Traefik v2.3 (see https://github.com/colinwilson/terraform-docker-traefik-v2 ). See the variables file for the available configuration options.
Original file line number Diff line number Diff line change 1+ # Create Vault service
2+ resource "docker_service" "vault-dev" {
3+ name = " vault-dev"
4+
5+ task_spec {
6+ container_spec {
7+ image = " vault:${ var . image_version } "
8+
9+ args = [" server" ] # automatically loads mounted vault-config.hcl
10+
11+ env = {
12+ VAULT_ADDR = " http://127.0.0.1:8200"
13+ VAULT_API_ADDR = " http://127.0.0.1:8200"
14+ SKIP_SETCAP = true
15+ }
16+
17+ labels {
18+ label = " traefik.enable"
19+ value = true
20+ }
21+
22+ labels {
23+ label = " traefik.http.routers.vault-dev.rule"
24+ value = " Host(`${ var . hostname } `)"
25+ }
26+
27+ labels {
28+ label = " traefik.http.routers.vault-dev.entrypoints"
29+ value = " https"
30+ }
31+
32+ labels {
33+ label = " traefik.http.services.vault-dev.loadbalancer.server.port"
34+ value = " 8200"
35+ }
36+
37+ labels {
38+ label = " traefik.http.routers.vault-dev.tls.certresolver"
39+ value = " letsEncrypt"
40+ }
41+
42+ configs {
43+ config_id = docker_config. vault_hcl . id
44+ config_name = docker_config. vault_hcl . name
45+ file_name = " /vault/config/vault-config.hcl"
46+ }
47+
48+ mounts {
49+ source = docker_volume. vault_data . name
50+ target = " /vault/file"
51+ type = " volume"
52+ read_only = false
53+ }
54+
55+ mounts {
56+ source = docker_volume. vault_logs . name
57+ target = " /vault/logs"
58+ type = " volume"
59+ read_only = false
60+ }
61+
62+ mounts {
63+ source = docker_volume. vault_policies . name
64+ target = " /vault/policies"
65+ type = " volume"
66+ read_only = false
67+ }
68+ }
69+ networks = var. networks
70+ }
71+ }
Original file line number Diff line number Diff line change 1+ resource "docker_config" "vault_hcl" {
2+ name = " vault_hcl-${ replace (timestamp (), " :" , " ." )} "
3+ data = base64encode (data. template_file . vault_hcl . rendered )
4+
5+ lifecycle {
6+ ignore_changes = [name ]
7+ create_before_destroy = true
8+ }
9+ }
Original file line number Diff line number Diff line change 1+ # Required variables
2+ variable "hostname" {
3+ type = string
4+ description = " Hostname for traefik route"
5+ }
6+
7+ # Optional variables
8+ variable "networks" {
9+ type = list
10+ description = " List of networks to connect Vault to."
11+ default = [" traefik" ]
12+ }
13+
14+ variable "image_version" {
15+ type = string
16+ description = " Vault Docker image version."
17+ default = " 1.6.0"
18+ }
Original file line number Diff line number Diff line change 1+ storage "file" {
2+ path = " /vault/file"
3+ }
4+
5+ listener "tcp" {
6+ address = " 0.0.0.0:8200"
7+ tls_disable = true
8+ }
9+
10+ ui = true
11+ disable_mlock = true
Original file line number Diff line number Diff line change 1+ data "local_file" "vault_hcl" {
2+ filename = " ${ path . module } /vault-config.hcl"
3+ }
4+ data "template_file" "vault_hcl" {
5+ template = " ${ file (" ${ path . module } /vault-config.hcl" )} "
6+
7+ # vars = {
8+ # traefik_network = var.traefik_network
9+ # }
10+ }
Original file line number Diff line number Diff line change 1+ terraform {
2+ required_providers {
3+ docker = {
4+ source = " terraform-providers/docker"
5+ }
6+ }
7+ required_version = " >= 0.13, <= 0.14"
8+ }
Original file line number Diff line number Diff line change 1+ resource "docker_volume" "vault_data" {
2+ name = " vault_data"
3+ }
4+
5+ resource "docker_volume" "vault_logs" {
6+ name = " vault_logs"
7+ }
8+
9+ resource "docker_volume" "vault_policies" {
10+ name = " vault_polices"
11+ }
You can’t perform that action at this time.
0 commit comments