mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
example: aws-linux: resize and use non-root user (#2186)
This commit is contained in:
@@ -36,19 +36,6 @@ variable "region" {
|
||||
}
|
||||
}
|
||||
|
||||
variable "disk_size" {
|
||||
description = "Specify your disk size (GiBs)"
|
||||
default = "20"
|
||||
type = number
|
||||
validation {
|
||||
condition = (
|
||||
var.disk_size >= 8 &&
|
||||
var.disk_size <= 256
|
||||
)
|
||||
error_message = "Disk size must be between 8 and 256."
|
||||
}
|
||||
}
|
||||
|
||||
provider "aws" {
|
||||
region = var.region
|
||||
}
|
||||
@@ -93,6 +80,11 @@ Content-Disposition: attachment; filename="cloud-config.txt"
|
||||
#cloud-config
|
||||
cloud_final_modules:
|
||||
- [scripts-user, always]
|
||||
hostname: ${lower(data.coder_workspace.me.name)}
|
||||
users:
|
||||
- name: ${local.linux_user}
|
||||
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||
shell: /bin/bash
|
||||
|
||||
--//
|
||||
Content-Type: text/x-shellscript; charset="us-ascii"
|
||||
@@ -101,7 +93,7 @@ Content-Transfer-Encoding: 7bit
|
||||
Content-Disposition: attachment; filename="userdata.txt"
|
||||
|
||||
#!/bin/bash
|
||||
sudo -u ubuntu sh -c '${coder_agent.dev.init_script}'
|
||||
sudo -u ${local.linux_user} sh -c '${coder_agent.dev.init_script}'
|
||||
--//--
|
||||
EOT
|
||||
|
||||
@@ -129,12 +121,16 @@ Content-Disposition: attachment; filename="userdata.txt"
|
||||
sudo shutdown -h now
|
||||
--//--
|
||||
EOT
|
||||
|
||||
# Ensure Coder username is a valid Linux username
|
||||
linux_user = lower(substr(data.coder_workspace.me.owner, 0, 32))
|
||||
|
||||
}
|
||||
|
||||
resource "aws_instance" "dev" {
|
||||
ami = data.aws_ami.ubuntu.id
|
||||
availability_zone = "${var.region}a"
|
||||
instance_type = "t3.micro"
|
||||
instance_type = "t3.xlarge"
|
||||
|
||||
user_data = data.coder_workspace.me.transition == "start" ? local.user_data_start : local.user_data_end
|
||||
tags = {
|
||||
|
||||
Reference in New Issue
Block a user