Skip to content

Commit 65c9860

Browse files
committed
add aws-linux and aws-windows examples
1 parent fbfb19a commit 65c9860

File tree

4 files changed

+279
-0
lines changed

4 files changed

+279
-0
lines changed

examples/aws-linux/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
name: Develop in Linux on AWS
3+
description: Get started with Linux development on AWS (EC2).
4+
tags: [cloud, aws]
5+
---
6+
7+
## Supported features
8+
9+
- Persistent storage
10+
- Start/stop
11+
12+
## User preferences
13+
14+
- Region

examples/aws-linux/main.tf

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
terraform {
2+
required_providers {
3+
coder = {
4+
source = "coder/coder"
5+
}
6+
}
7+
}
8+
9+
variable "access_key" {
10+
description = <<EOT
11+
Create an AWS access key to provision resources with Coder:
12+
- https://console.aws.amazon.com/iam/home#/users
13+
14+
AWS Access Key
15+
EOT
16+
sensitive = true
17+
}
18+
19+
variable "secret_key" {
20+
description = <<EOT
21+
AWS Secret Key
22+
EOT
23+
sensitive = true
24+
}
25+
26+
variable "region" {
27+
description = "What region should your workspace live in?"
28+
default = "us-east-1"
29+
validation {
30+
condition = contains(["us-east-1", "us-east-2", "us-west-1", "us-west-2"], var.region)
31+
error_message = "Invalid region!"
32+
}
33+
}
34+
35+
variable "disk_size" {
36+
description = "Specify your disk size (GiBs)"
37+
default = "20"
38+
type = number
39+
validation {
40+
condition = (
41+
var.disk_size >= 8 &&
42+
var.disk_size <= 256
43+
)
44+
error_message = "Disk size must be between 8 and 256."
45+
}
46+
}
47+
48+
provider "aws" {
49+
region = var.region
50+
access_key = var.access_key
51+
secret_key = var.secret_key
52+
}
53+
54+
data "coder_workspace" "me" {
55+
}
56+
57+
data "coder_agent_script" "dev" {
58+
arch = "amd64"
59+
auth = "aws-instance-identity"
60+
os = "linux"
61+
}
62+
63+
# assign a random name for the workspace
64+
resource "random_string" "random" {
65+
length = 8
66+
special = false
67+
}
68+
69+
data "aws_ami" "ubuntu" {
70+
most_recent = true
71+
filter {
72+
name = "name"
73+
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
74+
}
75+
filter {
76+
name = "virtualization-type"
77+
values = ["hvm"]
78+
}
79+
owners = ["099720109477"] # Canonical
80+
}
81+
82+
resource "coder_agent" "dev" {
83+
count = data.coder_workspace.me.transition == "start" ? 1 : 0
84+
instance_id = aws_instance.dev[0].id
85+
}
86+
87+
locals {
88+
user_data_start = <<EOT
89+
Content-Type: multipart/mixed; boundary="//"
90+
MIME-Version: 1.0
91+
92+
--//
93+
Content-Type: text/cloud-config; charset="us-ascii"
94+
MIME-Version: 1.0
95+
Content-Transfer-Encoding: 7bit
96+
Content-Disposition: attachment; filename="cloud-config.txt"
97+
98+
#cloud-config
99+
cloud_final_modules:
100+
- [scripts-user, always]
101+
102+
--//
103+
Content-Type: text/x-shellscript; charset="us-ascii"
104+
MIME-Version: 1.0
105+
Content-Transfer-Encoding: 7bit
106+
Content-Disposition: attachment; filename="userdata.txt"
107+
108+
#!/bin/bash
109+
sudo -E -u ubuntu sh -c '${data.coder_agent_script.dev.value}'
110+
--//--
111+
EOT
112+
113+
user_data_end = <<EOT
114+
Content-Type: multipart/mixed; boundary="//"
115+
MIME-Version: 1.0
116+
117+
--//
118+
Content-Type: text/cloud-config; charset="us-ascii"
119+
MIME-Version: 1.0
120+
Content-Transfer-Encoding: 7bit
121+
Content-Disposition: attachment; filename="cloud-config.txt"
122+
123+
#cloud-config
124+
cloud_final_modules:
125+
- [scripts-user, always]
126+
127+
--//
128+
Content-Type: text/x-shellscript; charset="us-ascii"
129+
MIME-Version: 1.0
130+
Content-Transfer-Encoding: 7bit
131+
Content-Disposition: attachment; filename="userdata.txt"
132+
133+
#!/bin/bash
134+
sudo shutdown -h now
135+
--//--
136+
EOT
137+
}
138+
139+
resource "aws_instance" "dev" {
140+
# count = data.coder_workspace.me.transition == "start" ? 1 : 0
141+
ami = data.aws_ami.ubuntu.id
142+
availability_zone = "${var.region}a"
143+
instance_type = "t3.micro"
144+
count = 1
145+
146+
user_data = data.coder_workspace.me.transition == "start" ? local.user_data_start : local.user_data_end
147+
tags = {
148+
Name = "coder-${lower(random_string.random.result)}"
149+
}
150+
151+
}

examples/aws-windows/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
name: Develop in Windows on AWS
3+
description: Get started with Windows development on AWS (EC2).
4+
tags: [cloud, aws]
5+
---
6+
7+
## Supported features
8+
9+
- Persistent storage
10+
- Start/stop
11+
12+
## User preferences
13+
14+
- Region

examples/aws-windows/main.tf

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
terraform {
2+
required_providers {
3+
coder = {
4+
source = "coder/coder"
5+
}
6+
}
7+
}
8+
9+
variable "access_key" {
10+
description = <<EOT
11+
Create an AWS access key to provision resources with Coder:
12+
- https://console.aws.amazon.com/iam/home#/users
13+
14+
AWS Access Key
15+
EOT
16+
sensitive = true
17+
}
18+
19+
variable "secret_key" {
20+
description = <<EOT
21+
AWS Secret Key
22+
EOT
23+
sensitive = true
24+
}
25+
26+
variable "region" {
27+
description = "What region should your workspace live in?"
28+
default = "us-east-1"
29+
validation {
30+
condition = contains(["us-east-1", "us-east-2", "us-west-1", "us-west-2"], var.region)
31+
error_message = "Invalid region!"
32+
}
33+
}
34+
35+
provider "aws" {
36+
region = var.region
37+
access_key = var.access_key
38+
secret_key = var.secret_key
39+
}
40+
41+
data "coder_workspace" "me" {
42+
}
43+
44+
data "coder_agent_script" "dev" {
45+
arch = "amd64"
46+
auth = "aws-instance-identity"
47+
os = "windows"
48+
}
49+
50+
# assign a random name for the workspace
51+
resource "random_string" "random" {
52+
length = 8
53+
special = false
54+
}
55+
56+
data "aws_ami" "windows" {
57+
most_recent = true
58+
owners = ["amazon"]
59+
60+
filter {
61+
name = "name"
62+
values = ["Windows_Server-2019-English-Full-Base-*"]
63+
}
64+
}
65+
66+
resource "coder_agent" "dev" {
67+
count = data.coder_workspace.me.transition == "start" ? 1 : 0
68+
instance_id = aws_instance.dev[0].id
69+
}
70+
71+
locals {
72+
user_data_start = <<EOT
73+
<powershell>
74+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
75+
${data.coder_agent_script.dev.value}
76+
</powershell>
77+
<persist>true</persist>
78+
EOT
79+
80+
user_data_end = <<EOT
81+
<powershell>
82+
shutdown /s
83+
</powershell>
84+
<persist>true</persist>
85+
EOT
86+
}
87+
88+
resource "aws_instance" "dev" {
89+
# count = data.coder_workspace.me.transition == "start" ? 1 : 0
90+
ami = data.aws_ami.windows.id
91+
availability_zone = "${var.region}a"
92+
instance_type = "t3.micro"
93+
count = 1
94+
95+
user_data = data.coder_workspace.me.transition == "start" ? local.user_data_start : local.user_data_end
96+
tags = {
97+
Name = "coder-${lower(random_string.random.result)}"
98+
}
99+
100+
}

0 commit comments

Comments
 (0)