-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
44 lines (38 loc) · 864 Bytes
/
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
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "~> 3.0.2"
}
}
}
provider "docker" {}
resource "docker_image" "default" {
name = var.image
count = var.context != null ? 0 : 1
}
resource "docker_image" "base" {
name = var.workspace_name
count = var.context != null ? 1 : 0
build {
context = var.context
build_args = {
USER = var.user
PACKAGES = join(" ", var.packages)
}
}
}
resource "docker_container" "base" {
image = var.context != null ? docker_image.base[0].image_id : docker_image.default[0].image_id
name = var.workspace_name
hostname = var.hostname
privileged = true
dynamic "volumes" {
for_each = var.volumes
content {
volume_name = volumes.key
container_path = volumes.value
read_only = false
}
}
}