@@ -2,7 +2,7 @@ terraform {
2
2
required_providers {
3
3
coder = {
4
4
source = " coder/coder"
5
- version = " 0.4.3 "
5
+ version = " 0.4.5 "
6
6
}
7
7
docker = {
8
8
source = " kreuzwerker/docker"
@@ -11,62 +11,18 @@ terraform {
11
11
}
12
12
}
13
13
14
- # Admin parameters
15
-
16
- # Comment this out if you are specifying a different docker
17
- # host on the "docker" provider below.
18
- variable "step1_docker_host_warning" {
19
- description = <<- EOF
20
- This template will use the Docker socket present on
21
- the Coder host, which is not necessarily your local machine.
22
-
23
- You can specify a different host in the template file and
24
- suppress this warning.
25
- EOF
26
- validation {
27
- condition = contains ([" Continue using /var/run/docker.sock on the Coder host" ], var. step1_docker_host_warning )
28
- error_message = " Cancelling template create."
29
- }
30
-
31
- sensitive = true
32
- }
33
- variable "step2_arch" {
34
- description = <<- EOF
35
- arch: What architecture is your Docker host on?
36
-
37
- note: codercom/enterprise-* images are only built for amd64
38
- EOF
39
-
40
- validation {
41
- condition = contains ([" amd64" , " arm64" , " armv7" ], var. step2_arch )
42
- error_message = " Value must be amd64, arm64, or armv7."
43
- }
44
- sensitive = true
45
- }
46
- variable "step3_OS" {
47
- description = <<- EOF
48
- What operating system is your Coder host on?
49
- EOF
50
-
51
- validation {
52
- condition = contains ([" MacOS" , " Windows" , " Linux" ], var. step3_OS )
53
- error_message = " Value must be MacOS, Windows, or Linux."
54
- }
55
- sensitive = true
14
+ data "coder_provisioner" "me" {
56
15
}
57
16
58
17
provider "docker" {
59
- host = var. step3_OS == " Windows" ? " npipe:////.//pipe//docker_engine" : " unix:///var/run/docker.sock"
60
- }
61
-
62
- provider "coder" {
18
+ host = data. coder_provisioner . me . os == " windows" ? " npipe:////.//pipe//docker_engine" : " unix:///var/run/docker.sock"
63
19
}
64
20
65
21
data "coder_workspace" "me" {
66
22
}
67
23
68
24
resource "coder_agent" "main" {
69
- arch = var . step2_arch
25
+ arch = data . coder_provisioner . me . arch
70
26
os = " linux"
71
27
startup_script = << EOF
72
28
#!/bin/sh
@@ -104,11 +60,10 @@ variable "docker_image" {
104
60
" codercom/enterprise-intellij:ubuntu" , " codercom/enterprise-golang:ubuntu" ], var. docker_image )
105
61
error_message = " Invalid Docker image!"
106
62
}
107
-
108
63
}
109
64
110
65
resource "docker_volume" "home_volume" {
111
- name = " coder-${ data . coder_workspace . me . owner } -${ data . coder_workspace . me . name } -home"
66
+ name = " coder-${ data . coder_workspace . me . owner_id } -${ data . coder_workspace . me . id } -home"
112
67
}
113
68
114
69
resource "docker_container" "workspace" {
@@ -121,12 +76,7 @@ resource "docker_container" "workspace" {
121
76
dns = [" 1.1.1.1" ]
122
77
# Use the docker gateway if the access URL is 127.0.0.1
123
78
command = [
124
- " sh" , " -c" ,
125
- << EOT
126
- trap '[ $? -ne 0 ] && echo === Agent script exited with non-zero code. Sleeping infinitely to preserve logs... && sleep infinity' EXIT
127
- ${ replace (coder_agent. main . init_script , " localhost" , " host.docker.internal" )}
128
- EOT
129
- ]
79
+ " sh" , " -c" , replace (coder_agent. main . init_script , " localhost" , " host.docker.internal" )]
130
80
env = [" CODER_AGENT_TOKEN=${ coder_agent . main . token } " ]
131
81
host {
132
82
host = " host.docker.internal"
0 commit comments