-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
62 lines (56 loc) · 1.34 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "3.0.1"
}
}
}
provider "docker" {}
resource "docker_network" "private_network" {
name = "my_network"
driver = "bridge"
}
resource "docker_image" "postgres" {
name = "postgres:latest"
}
resource "docker_volume" "db_data" {
name = "db_data"
}
resource "docker_container" "db" {
name = "db"
image = docker_image.postgres.image_id
env = ["POSTGRES_USER=${var.username}", "POSTGRES_PASSWORD=${var.password}", "POSTGRES_DB=${var.dbname}"]
healthcheck {
test = ["CMD", "pg_isready", "-d", "${var.dbname}", "-U", "${var.username}"]
timeout = "30s"
interval = "10s"
retries = 3
}
networks_advanced {
name = docker_network.private_network.name
}
ports {
internal = 5432
external = 5432
}
volumes {
host_path = "${abspath(path.root)}/data/db"
container_path = "/var/lib/postgresql/data"
}
}
resource "docker_container" "api" {
name = "api"
image = "myapi"
env = ["POSTGRES_USER=${var.username}", "POSTGRES_PASSWORD=${var.password}", "POSTGRES_DB=${var.dbname}", "POSTGRES_HOST=${docker_container.db.name}"]
ports {
internal = 8000
external = 8000
}
networks_advanced {
name = docker_network.private_network.name
}
depends_on = [
docker_container.db
]
}