-
Notifications
You must be signed in to change notification settings - Fork 943
feat: Add aws-windows and aws-linux examples #730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2cbec58
add readme for samples
bpmct fbfb19a
add sample of importing from repo
bpmct 65c9860
add aws-linux and aws-windows examples
bpmct 3edebd6
cleanup
bpmct e33ed8f
cleanup
bpmct d0b43dc
Merge branch 'bpmct/add-samples' of github.com:coder/coder into bpmct…
bpmct 6d8f64a
sign
bpmct 43b5b2e
fix grammar and comments from feedback
bpmct 1764439
use descript workspace name
bpmct 788c2c5
use TF version
bpmct acedca5
Fix requested changes on README
kylecarbs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Project examples | ||
|
||
| Project name | OS, Type | Features | Status | | ||
| ---------------------------- | ----------------------------- | ------------------------------------------------------- | ------- | | ||
| [gcp-windows](./gcp-windows) | VM, Windows Server 2022 | Regions, instance type | Basic | | ||
| [gcp-linux](./gcp-linux) | VM, Ubuntu 20.04 | Regions, instance type | Basic | | ||
| [aws-linux](./aws-linux) | VM, Ubuntu 20.04 | Regions, instance type | Basic | | ||
| [aws-windows](./aws-windows) | VM, Windows Server 2019 | Regions, instance type | Basic | | ||
| [aws-macos](./aws-macos) | Mac Mini, OSX 12 Monterey | Regions, instance type | WIP | | ||
| kubernetes | Container/pod spec, any linux | Custom image, registry, provisioning ratio, PVC support | Planned | | ||
bpmct marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## How to use | ||
bpmct marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
These are embedded as examples when you run `coder projects init`. Optionally modify the terraform and use `coder projects create` or `coder projects update`, if you have already imported the project. | ||
bpmct marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
You can still use projects that are not embedded in your version of Coder: | ||
bpmct marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```sh | ||
git clone https://github.com/coder/coder | ||
cd examples/aws-macos | ||
coder projects create | ||
``` | ||
|
||
## Statuses | ||
|
||
- Planned | ||
- WIP | ||
- Basic (proof of concept) | ||
- Beta | ||
- Stable | ||
- Broken/unsupported | ||
bpmct marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Requests | ||
|
||
Submit [an issue](https://github.com/coder/coder/issues/new) or pull request to request features or more examples. | ||
bpmct marked this conversation as resolved.
Show resolved
Hide resolved
bpmct marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
name: Develop in Linux on AWS | ||
description: Get started with Linux development on AWS (EC2). | ||
tags: [cloud, aws] | ||
--- | ||
|
||
## Supported features | ||
|
||
- Persistent storage | ||
- Start/stop | ||
|
||
## User preferences | ||
|
||
- Region |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
terraform { | ||
required_providers { | ||
coder = { | ||
source = "coder/coder" | ||
bpmct marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
|
||
variable "access_key" { | ||
description = <<EOT | ||
Create an AWS access key to provision resources with Coder: | ||
- https://console.aws.amazon.com/iam/home#/users | ||
|
||
AWS Access Key | ||
EOT | ||
sensitive = true | ||
} | ||
|
||
variable "secret_key" { | ||
description = <<EOT | ||
AWS Secret Key | ||
EOT | ||
sensitive = true | ||
} | ||
|
||
variable "region" { | ||
description = "What region should your workspace live in?" | ||
default = "us-east-1" | ||
validation { | ||
condition = contains(["us-east-1", "us-east-2", "us-west-1", "us-west-2"], var.region) | ||
error_message = "Invalid 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 | ||
access_key = var.access_key | ||
secret_key = var.secret_key | ||
} | ||
|
||
data "coder_workspace" "me" { | ||
} | ||
|
||
data "coder_agent_script" "dev" { | ||
arch = "amd64" | ||
auth = "aws-instance-identity" | ||
os = "linux" | ||
} | ||
|
||
# assign a random name for the workspace | ||
resource "random_string" "random" { | ||
length = 8 | ||
special = false | ||
} | ||
|
||
data "aws_ami" "ubuntu" { | ||
most_recent = true | ||
filter { | ||
name = "name" | ||
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"] | ||
} | ||
filter { | ||
name = "virtualization-type" | ||
values = ["hvm"] | ||
} | ||
owners = ["099720109477"] # Canonical | ||
} | ||
|
||
resource "coder_agent" "dev" { | ||
count = data.coder_workspace.me.transition == "start" ? 1 : 0 | ||
instance_id = aws_instance.dev[0].id | ||
} | ||
|
||
locals { | ||
|
||
# with AWS, we are using user data | ||
# to start/stop instances with Terraform | ||
# https://github.com/hashicorp/terraform-provider-aws/issues/22 | ||
|
||
user_data_start = <<EOT | ||
Content-Type: multipart/mixed; boundary="//" | ||
MIME-Version: 1.0 | ||
|
||
--// | ||
Content-Type: text/cloud-config; charset="us-ascii" | ||
MIME-Version: 1.0 | ||
Content-Transfer-Encoding: 7bit | ||
Content-Disposition: attachment; filename="cloud-config.txt" | ||
|
||
#cloud-config | ||
cloud_final_modules: | ||
- [scripts-user, always] | ||
|
||
--// | ||
Content-Type: text/x-shellscript; charset="us-ascii" | ||
MIME-Version: 1.0 | ||
Content-Transfer-Encoding: 7bit | ||
Content-Disposition: attachment; filename="userdata.txt" | ||
|
||
#!/bin/bash | ||
sudo -E -u ubuntu sh -c '${data.coder_agent_script.dev.value}' | ||
--//-- | ||
EOT | ||
|
||
user_data_end = <<EOT | ||
Content-Type: multipart/mixed; boundary="//" | ||
MIME-Version: 1.0 | ||
|
||
--// | ||
Content-Type: text/cloud-config; charset="us-ascii" | ||
MIME-Version: 1.0 | ||
Content-Transfer-Encoding: 7bit | ||
Content-Disposition: attachment; filename="cloud-config.txt" | ||
|
||
#cloud-config | ||
cloud_final_modules: | ||
- [scripts-user, always] | ||
|
||
--// | ||
Content-Type: text/x-shellscript; charset="us-ascii" | ||
MIME-Version: 1.0 | ||
Content-Transfer-Encoding: 7bit | ||
Content-Disposition: attachment; filename="userdata.txt" | ||
|
||
#!/bin/bash | ||
sudo shutdown -h now | ||
--//-- | ||
EOT | ||
} | ||
|
||
resource "aws_instance" "dev" { | ||
ami = data.aws_ami.ubuntu.id | ||
availability_zone = "${var.region}a" | ||
instance_type = "t3.micro" | ||
count = 1 | ||
|
||
user_data = data.coder_workspace.me.transition == "start" ? local.user_data_start : local.user_data_end | ||
tags = { | ||
Name = "coder-${lower(random_string.random.result)}" | ||
bpmct marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
name: Develop in Windows on AWS | ||
description: Get started with Windows development on AWS (EC2). | ||
bpmct marked this conversation as resolved.
Show resolved
Hide resolved
|
||
tags: [cloud, aws] | ||
--- | ||
|
||
## Supported features | ||
|
||
- Persistent storage | ||
- Start/stop | ||
|
||
## User preferences | ||
|
||
- Region |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
terraform { | ||
required_providers { | ||
coder = { | ||
source = "coder/coder" | ||
} | ||
} | ||
} | ||
|
||
variable "access_key" { | ||
description = <<EOT | ||
Create an AWS access key to provision resources with Coder: | ||
- https://console.aws.amazon.com/iam/home#/users | ||
|
||
AWS Access Key | ||
EOT | ||
sensitive = true | ||
} | ||
|
||
variable "secret_key" { | ||
description = <<EOT | ||
AWS Secret Key | ||
EOT | ||
sensitive = true | ||
} | ||
|
||
variable "region" { | ||
description = "What region should your workspace live in?" | ||
default = "us-east-1" | ||
validation { | ||
condition = contains(["us-east-1", "us-east-2", "us-west-1", "us-west-2"], var.region) | ||
error_message = "Invalid region!" | ||
} | ||
} | ||
|
||
provider "aws" { | ||
region = var.region | ||
access_key = var.access_key | ||
secret_key = var.secret_key | ||
} | ||
|
||
data "coder_workspace" "me" { | ||
} | ||
|
||
data "coder_agent_script" "dev" { | ||
arch = "amd64" | ||
auth = "aws-instance-identity" | ||
os = "windows" | ||
} | ||
|
||
# assign a random name for the workspace | ||
bpmct marked this conversation as resolved.
Show resolved
Hide resolved
|
||
resource "random_string" "random" { | ||
length = 8 | ||
special = false | ||
} | ||
|
||
data "aws_ami" "windows" { | ||
most_recent = true | ||
owners = ["amazon"] | ||
|
||
filter { | ||
name = "name" | ||
values = ["Windows_Server-2019-English-Full-Base-*"] | ||
} | ||
} | ||
|
||
resource "coder_agent" "dev" { | ||
count = data.coder_workspace.me.transition == "start" ? 1 : 0 | ||
instance_id = aws_instance.dev[0].id | ||
} | ||
|
||
locals { | ||
|
||
# with AWS, we are using user data | ||
# to start/stop instances with Terraform | ||
# https://github.com/hashicorp/terraform-provider-aws/issues/22 | ||
bpmct marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
user_data_start = <<EOT | ||
<powershell> | ||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | ||
${data.coder_agent_script.dev.value} | ||
</powershell> | ||
<persist>true</persist> | ||
EOT | ||
|
||
user_data_end = <<EOT | ||
<powershell> | ||
shutdown /s | ||
</powershell> | ||
<persist>true</persist> | ||
EOT | ||
} | ||
|
||
resource "aws_instance" "dev" { | ||
# count = data.coder_workspace.me.transition == "start" ? 1 : 0 | ||
bpmct marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ami = data.aws_ami.windows.id | ||
availability_zone = "${var.region}a" | ||
instance_type = "t3.micro" | ||
count = 1 | ||
|
||
user_data = data.coder_workspace.me.transition == "start" ? local.user_data_start : local.user_data_end | ||
tags = { | ||
Name = "coder-${lower(random_string.random.result)}" | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.