Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite759b4a

Browse files
bpmctkylecarbs
andauthored
feat: Add aws-windows and aws-linux examples (#730)
* add readme for samples* add sample of importing from repo* add aws-linux and aws-windows examples* cleanup* cleanup* sign* fix grammar and comments from feedback* use descript workspace name* use TF version* Fix requested changes on READMECo-authored-by: Kyle Carberry <kyle@coder.com>
1 parentf5757ff commite759b4a

File tree

5 files changed

+272
-0
lines changed

5 files changed

+272
-0
lines changed

‎examples/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#Examples
2+
3+
List examples in our CLI with`coder projects init`.
4+
5+
>[Submit an issue](https://github.com/coder/coder/issues/new) if you encounter any issues!
6+
7+
##Getting Started
8+
9+
Clone this repository to create a project from any example listed here:
10+
11+
```sh
12+
git clone https://github.com/coder/coder
13+
cd examples/aws-macos
14+
coder projects create
15+
```

‎examples/aws-linux/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
name:Develop in Linux on AWS EC2
3+
description:Get started with Linux development on AWS EC2.
4+
tags:[cloud, aws]
5+
---

‎examples/aws-linux/main.tf

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

‎examples/aws-windows/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
name:Develop in Windows on AWS
3+
description:Get started with Windows development on AWS.
4+
tags:[cloud, aws]
5+
---

‎examples/aws-windows/main.tf

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp