Skip to content

Commit e472f88

Browse files
committed
🎉 initial commit
0 parents  commit e472f88

File tree

9 files changed

+140
-0
lines changed

9 files changed

+140
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
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.

outputs.tf

Whitespace-only changes.

service.tf

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
}

service_conf.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
}

variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
}

vault-config.hcl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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

vault_tpl.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
}

version.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
terraform {
2+
required_providers {
3+
docker = {
4+
source = "terraform-providers/docker"
5+
}
6+
}
7+
required_version = ">= 0.13, <= 0.14"
8+
}

volume.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
}

0 commit comments

Comments
 (0)