@@ -140,8 +140,7 @@ provider "aws" {
140
140
region = data. coder_parameter . region . value
141
141
}
142
142
143
- data "coder_workspace" "me" {
144
- }
143
+ data "coder_workspace" "me" {}
145
144
data "coder_workspace_owner" "me" {}
146
145
147
146
data "aws_ami" "ubuntu" {
@@ -214,44 +213,44 @@ resource "coder_app" "code-server" {
214
213
}
215
214
216
215
locals {
216
+ hostname = lower (data. coder_workspace . me . name )
217
217
linux_user = " coder"
218
- user_data = <<- EOT
219
- Content-Type: multipart/mixed; boundary="//"
220
- MIME-Version: 1.0
218
+ }
221
219
222
- --//
223
- Content-Type: text/cloud-config; charset="us-ascii"
224
- MIME-Version: 1.0
225
- Content-Transfer-Encoding: 7bit
226
- Content-Disposition: attachment; filename="cloud-config.txt"
220
+ data "cloudinit_config" "user_data" {
221
+ gzip = false
222
+ base64_encode = false
227
223
228
- #cloud-config
229
- cloud_final_modules:
230
- - [scripts-user, always]
231
- hostname: ${ lower (data. coder_workspace . me . name )}
232
- users:
233
- - name: ${ local . linux_user }
234
- sudo: ALL=(ALL) NOPASSWD:ALL
235
- shell: /bin/bash
224
+ boundary = " //"
236
225
237
- --//
238
- Content-Type: text/x-shellscript; charset="us-ascii"
239
- MIME-Version: 1.0
240
- Content-Transfer-Encoding: 7bit
241
- Content-Disposition: attachment; filename="userdata.txt"
226
+ part {
227
+ filename = " cloud-config.yaml"
228
+ content_type = " text/cloud-config"
242
229
243
- #!/bin/bash
244
- sudo -u ${ local . linux_user } sh -c '${ try (coder_agent. dev [0 ]. init_script , " " )} '
245
- --//--
246
- EOT
230
+ content = templatefile (" ${ path . module } /cloud-init/cloud-config.yaml.tftpl" , {
231
+ hostname = local.hostname
232
+ linux_user = local.linux_user
233
+ })
234
+ }
235
+
236
+ part {
237
+ filename = " userdata.sh"
238
+ content_type = " text/x-shellscript"
239
+
240
+ content = templatefile (" ${ path . module } /cloud-init/userdata.sh.tftpl" , {
241
+ linux_user = local.linux_user
242
+
243
+ init_script = try (coder_agent. dev [0 ]. init_script , " " )
244
+ })
245
+ }
247
246
}
248
247
249
248
resource "aws_instance" "dev" {
250
249
ami = data. aws_ami . ubuntu . id
251
250
availability_zone = " ${ data . coder_parameter . region . value } a"
252
251
instance_type = data. coder_parameter . instance_type . value
253
252
254
- user_data = local . user_data
253
+ user_data = data . cloudinit_config . user_data . rendered
255
254
tags = {
256
255
Name = " coder-${ data . coder_workspace_owner . me . name } -${ data . coder_workspace . me . name } "
257
256
# Required if you are using our example policy, see template README
0 commit comments