Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a0e096b

Browse files
authored
chore: update templates to use rich parameters (#6397)
1 parent 3cf235c commit a0e096b

File tree

21 files changed

+1253
-360
lines changed

21 files changed

+1253
-360
lines changed

examples/templates/aws-ecs-container/main.tf

+26-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
coder = {
44
source = "coder/coder"
5-
version = "~> 0.6.12"
5+
version = "~> 0.6.17"
66
}
77
aws = {
88
source = "hashicorp/aws"
@@ -11,16 +11,28 @@ terraform {
1111
}
1212
}
1313

14+
provider "coder" {
15+
feature_use_managed_variables = true
16+
}
17+
1418
variable "ecs-cluster" {
1519
description = "Input the ECS cluster ARN to host the workspace"
16-
default = ""
1720
}
18-
variable "cpu" {
19-
default = "1024"
21+
22+
data "coder_parameter" "cpu" {
23+
name = "cpu"
24+
description = "The number of CPU units to reserve for the container"
25+
type = "number"
26+
default = "1024"
27+
mutable = true
2028
}
2129

22-
variable "memory" {
23-
default = "2048"
30+
data "coder_parameter" "memory" {
31+
name = "memory"
32+
description = "The amount of memory (in MiB) to allow the container to use"
33+
type = "number"
34+
default = "2048"
35+
mutable = true
2436
}
2537

2638
# configure AWS provider with creds present on Coder server host
@@ -34,14 +46,14 @@ resource "aws_ecs_task_definition" "workspace" {
3446
family = "coder"
3547

3648
requires_compatibilities = ["EC2"]
37-
cpu = var.cpu
38-
memory = var.memory
49+
cpu = data.coder_parameter.cpu.value
50+
memory = data.coder_parameter.memory.value
3951
container_definitions = jsonencode([
4052
{
4153
name = "coder-workspace-${data.coder_workspace.me.id}"
4254
image = "codercom/enterprise-base:ubuntu"
43-
cpu = 1024
44-
memory = 2048
55+
cpu = tonumber(data.coder_parameter.cpu.value)
56+
memory = tonumber(data.coder_parameter.memory.value)
4557
essential = true
4658
user = "coder"
4759
command = ["sh", "-c", coder_agent.coder.init_script]
@@ -92,11 +104,10 @@ resource "aws_ecs_service" "workspace" {
92104
data "coder_workspace" "me" {}
93105

94106
resource "coder_agent" "coder" {
95-
arch = "amd64"
96-
auth = "token"
97-
os = "linux"
98-
dir = "/home/coder"
99-
107+
arch = "amd64"
108+
auth = "token"
109+
os = "linux"
110+
dir = "/home/coder"
100111
login_before_ready = false
101112
startup_script_timeout = 180
102113
startup_script = <<-EOT

examples/templates/aws-linux/main.tf

+123-44
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
coder = {
44
source = "coder/coder"
5-
version = "~> 0.6.12"
5+
version = "~> 0.6.17"
66
}
77
aws = {
88
source = "hashicorp/aws"
@@ -11,53 +11,133 @@ terraform {
1111
}
1212
}
1313

14-
# Last updated 2022-05-31
14+
# Last updated 2023-03-14
1515
# aws ec2 describe-regions | jq -r '[.Regions[].RegionName] | sort'
16-
variable "region" {
17-
description = "What region should your workspace live in?"
16+
data "coder_parameter" "region" {
17+
name = "Region"
18+
description = "The region to deploy the workspace in."
1819
default = "us-east-1"
19-
validation {
20-
condition = contains([
21-
"ap-northeast-1",
22-
"ap-northeast-2",
23-
"ap-northeast-3",
24-
"ap-south-1",
25-
"ap-southeast-1",
26-
"ap-southeast-2",
27-
"ca-central-1",
28-
"eu-central-1",
29-
"eu-north-1",
30-
"eu-west-1",
31-
"eu-west-2",
32-
"eu-west-3",
33-
"sa-east-1",
34-
"us-east-1",
35-
"us-east-2",
36-
"us-west-1",
37-
"us-west-2"
38-
], var.region)
39-
error_message = "Invalid region!"
20+
mutable = false
21+
option {
22+
name = "Asia Pacific (Tokyo)"
23+
value = "ap-northeast-1"
24+
icon = "/emojis/1f1ef-1f1f5.png"
25+
}
26+
option {
27+
name = "Asia Pacific (Seoul)"
28+
value = "ap-northeast-2"
29+
icon = "/emojis/1f1f0-1f1f7.png"
30+
}
31+
option {
32+
name = "Asia Pacific (Osaka-Local)"
33+
value = "ap-northeast-3"
34+
icon = "/emojis/1f1f0-1f1f7.png"
35+
}
36+
option {
37+
name = "Asia Pacific (Mumbai)"
38+
value = "ap-south-1"
39+
icon = "/emojis/1f1f0-1f1f7.png"
40+
}
41+
option {
42+
name = "Asia Pacific (Singapore)"
43+
value = "ap-southeast-1"
44+
icon = "/emojis/1f1f0-1f1f7.png"
45+
}
46+
option {
47+
name = "Asia Pacific (Sydney)"
48+
value = "ap-southeast-2"
49+
icon = "/emojis/1f1f0-1f1f7.png"
50+
}
51+
option {
52+
name = "Canada (Central)"
53+
value = "ca-central-1"
54+
icon = "/emojis/1f1e8-1f1e6.png"
55+
}
56+
option {
57+
name = "EU (Frankfurt)"
58+
value = "eu-central-1"
59+
icon = "/emojis/1f1ea-1f1fa.png"
60+
}
61+
option {
62+
name = "EU (Stockholm)"
63+
value = "eu-north-1"
64+
icon = "/emojis/1f1ea-1f1fa.png"
65+
}
66+
option {
67+
name = "EU (Ireland)"
68+
value = "eu-west-1"
69+
icon = "/emojis/1f1ea-1f1fa.png"
70+
}
71+
option {
72+
name = "EU (London)"
73+
value = "eu-west-2"
74+
icon = "/emojis/1f1ea-1f1fa.png"
75+
}
76+
option {
77+
name = "EU (Paris)"
78+
value = "eu-west-3"
79+
icon = "/emojis/1f1ea-1f1fa.png"
80+
}
81+
option {
82+
name = "South America (São Paulo)"
83+
value = "sa-east-1"
84+
icon = "/emojis/1f1e7-1f1f7.png"
85+
}
86+
option {
87+
name = "US East (N. Virginia)"
88+
value = "us-east-1"
89+
icon = "/emojis/1f1fa-1f1f8.png"
90+
}
91+
option {
92+
name = "US East (Ohio)"
93+
value = "us-east-2"
94+
icon = "/emojis/1f1fa-1f1f8.png"
95+
}
96+
option {
97+
name = "US West (N. California)"
98+
value = "us-west-1"
99+
icon = "/emojis/1f1fa-1f1f8.png"
100+
}
101+
option {
102+
name = "US West (Oregon)"
103+
value = "us-west-2"
104+
icon = "/emojis/1f1fa-1f1f8.png"
40105
}
41106
}
42107

43-
variable "instance_type" {
108+
data "coder_parameter" "instance_type" {
109+
name = "Instance Type"
44110
description = "What instance type should your workspace use?"
45111
default = "t3.micro"
46-
validation {
47-
condition = contains([
48-
"t3.micro",
49-
"t3.small",
50-
"t3.medium",
51-
"t3.large",
52-
"t3.xlarge",
53-
"t3.2xlarge",
54-
], var.instance_type)
55-
error_message = "Invalid instance type!"
112+
mutable = false
113+
option {
114+
name = "2 vCPU, 1 GiB RAM"
115+
value = "t3.micro"
116+
}
117+
option {
118+
name = "2 vCPU, 2 GiB RAM"
119+
value = "t3.small"
120+
}
121+
option {
122+
name = "2 vCPU, 4 GiB RAM"
123+
value = "t3.medium"
124+
}
125+
option {
126+
name = "2 vCPU, 8 GiB RAM"
127+
value = "t3.large"
128+
}
129+
option {
130+
name = "4 vCPU, 16 GiB RAM"
131+
value = "t3.xlarge"
132+
}
133+
option {
134+
name = "8 vCPU, 32 GiB RAM"
135+
value = "t3.2xlarge"
56136
}
57137
}
58138

59139
provider "aws" {
60-
region = var.region
140+
region = data.coder_parameter.region.value
61141
}
62142

63143
data "coder_workspace" "me" {
@@ -77,10 +157,9 @@ data "aws_ami" "ubuntu" {
77157
}
78158

79159
resource "coder_agent" "main" {
80-
arch = "amd64"
81-
auth = "aws-instance-identity"
82-
os = "linux"
83-
160+
arch = "amd64"
161+
auth = "aws-instance-identity"
162+
os = "linux"
84163
login_before_ready = false
85164
startup_script_timeout = 180
86165
startup_script = <<-EOT
@@ -174,8 +253,8 @@ EOT
174253

175254
resource "aws_instance" "dev" {
176255
ami = data.aws_ami.ubuntu.id
177-
availability_zone = "${var.region}a"
178-
instance_type = var.instance_type
256+
availability_zone = "${data.coder_parameter.region.value}a"
257+
instance_type = data.coder_parameter.instance_type.value
179258

180259
user_data = data.coder_workspace.me.transition == "start" ? local.user_data_start : local.user_data_end
181260
tags = {
@@ -189,7 +268,7 @@ resource "coder_metadata" "workspace_info" {
189268
resource_id = aws_instance.dev.id
190269
item {
191270
key = "region"
192-
value = var.region
271+
value = data.coder_parameter.region.value
193272
}
194273
item {
195274
key = "instance type"

0 commit comments

Comments
 (0)