From 2cbec585af8d66a64a061bcb128cdb78eef4a0c2 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 30 Mar 2022 12:26:17 +0000 Subject: [PATCH 01/10] add readme for samples --- examples/README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 examples/README.md diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000000000..7496e9cb20551 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,27 @@ +# 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 | + +## How to use + +These are available during `coder projects init`. Optionally modify the terraform and use `coder projects create` or `coder projects update`, if you have already imported the project. + +## Statuses + +- Planned +- WIP +- Basic (proof of concept) +- Beta +- Stable +- Broken/unsupported + +## Requests + +Submit [an issue](https://github.com/coder/coder/issues/new) or pull request to request features or more examples. From fbfb19a72494360a428307b05ee296198fe3cc88 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 30 Mar 2022 12:28:38 +0000 Subject: [PATCH 02/10] add sample of importing from repo --- examples/README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/README.md b/examples/README.md index 7496e9cb20551..81ddc90de675e 100644 --- a/examples/README.md +++ b/examples/README.md @@ -11,7 +11,15 @@ ## How to use -These are available during `coder projects init`. Optionally modify the terraform and use `coder projects create` or `coder projects update`, if you have already imported the project. +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. + +You can still use projects that are not embedded in your version of Coder: + +```sh +git clone https://github.com/coder/coder +cd examples/aws-macos +coder projects create +``` ## Statuses From 65c9860979cea833fa0f3dd22a992fedf084d71c Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 30 Mar 2022 12:37:52 +0000 Subject: [PATCH 03/10] add aws-linux and aws-windows examples --- examples/aws-linux/README.md | 14 +++ examples/aws-linux/main.tf | 151 +++++++++++++++++++++++++++++++++ examples/aws-windows/README.md | 14 +++ examples/aws-windows/main.tf | 100 ++++++++++++++++++++++ 4 files changed, 279 insertions(+) create mode 100644 examples/aws-linux/README.md create mode 100644 examples/aws-linux/main.tf create mode 100644 examples/aws-windows/README.md create mode 100644 examples/aws-windows/main.tf diff --git a/examples/aws-linux/README.md b/examples/aws-linux/README.md new file mode 100644 index 0000000000000..454b1c0aba3ba --- /dev/null +++ b/examples/aws-linux/README.md @@ -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 diff --git a/examples/aws-linux/main.tf b/examples/aws-linux/main.tf new file mode 100644 index 0000000000000..cac871b71019b --- /dev/null +++ b/examples/aws-linux/main.tf @@ -0,0 +1,151 @@ +terraform { + required_providers { + coder = { + source = "coder/coder" + } + } +} + +variable "access_key" { + description = <= 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 { + user_data_start = < +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +${data.coder_agent_script.dev.value} + +true +EOT + + user_data_end = < +shutdown /s + +true +EOT +} + +resource "aws_instance" "dev" { + # count = data.coder_workspace.me.transition == "start" ? 1 : 0 + 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)}" + } + +} From 3edebd6de851d61ffe12507236b494687cddc4ec Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 30 Mar 2022 12:40:23 +0000 Subject: [PATCH 04/10] cleanup --- examples/aws-linux/main.tf | 6 +++++- examples/aws-windows/main.tf | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/aws-linux/main.tf b/examples/aws-linux/main.tf index cac871b71019b..03cdaf51408a5 100644 --- a/examples/aws-linux/main.tf +++ b/examples/aws-linux/main.tf @@ -85,6 +85,11 @@ resource "coder_agent" "dev" { } 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 = < [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 From e33ed8f7cce2eb35bd92757205fe2a25313e2d6f Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 30 Mar 2022 12:40:23 +0000 Subject: [PATCH 05/10] cleanup --- examples/aws-linux/main.tf | 6 +++++- examples/aws-windows/main.tf | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/examples/aws-linux/main.tf b/examples/aws-linux/main.tf index cac871b71019b..03cdaf51408a5 100644 --- a/examples/aws-linux/main.tf +++ b/examples/aws-linux/main.tf @@ -85,6 +85,11 @@ resource "coder_agent" "dev" { } 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 = < [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 From 6d8f64abdeac3338f708eb4a965b975d4ea2cc68 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 30 Mar 2022 12:45:41 +0000 Subject: [PATCH 06/10] sign From 43b5b2e2d61e73554c00c8b680fed7006e659ffe Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 30 Mar 2022 17:11:41 +0000 Subject: [PATCH 07/10] fix grammar and comments from feedback --- examples/README.md | 26 +++++--------------------- examples/aws-linux/README.md | 11 +---------- examples/aws-linux/main.tf | 3 +-- examples/aws-windows/README.md | 11 +---------- examples/aws-windows/main.tf | 4 +--- 5 files changed, 9 insertions(+), 46 deletions(-) diff --git a/examples/README.md b/examples/README.md index 81ddc90de675e..9b0526f26df08 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,19 +1,12 @@ -# Project examples +# 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 | +Examples are available in our CLI with `coder projects init` -## How to use +> Submit [an issue](https://github.com/coder/coder/issues/new) if you experience issues with an example! -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. +## Getting Sarted -You can still use projects that are not embedded in your version of Coder: +Manually clone to create a project from any example in this repo: ```sh git clone https://github.com/coder/coder @@ -21,15 +14,6 @@ cd examples/aws-macos coder projects create ``` -## Statuses - -- Planned -- WIP -- Basic (proof of concept) -- Beta -- Stable -- Broken/unsupported - ## Requests Submit [an issue](https://github.com/coder/coder/issues/new) or pull request to request features or more examples. diff --git a/examples/aws-linux/README.md b/examples/aws-linux/README.md index 454b1c0aba3ba..ee3b6adf15329 100644 --- a/examples/aws-linux/README.md +++ b/examples/aws-linux/README.md @@ -1,14 +1,5 @@ --- name: Develop in Linux on AWS -description: Get started with Linux development on AWS (EC2). +description: Get started with Linux development on AWS. tags: [cloud, aws] --- - -## Supported features - -- Persistent storage -- Start/stop - -## User preferences - -- Region diff --git a/examples/aws-linux/main.tf b/examples/aws-linux/main.tf index 03cdaf51408a5..4e67621e0a22a 100644 --- a/examples/aws-linux/main.tf +++ b/examples/aws-linux/main.tf @@ -86,8 +86,7 @@ resource "coder_agent" "dev" { locals { - # with AWS, we are using user data - # to start/stop instances with Terraform + # User data is used to stop/start AWS instances. See: # https://github.com/hashicorp/terraform-provider-aws/issues/22 user_data_start = < Date: Wed, 30 Mar 2022 17:57:08 +0000 Subject: [PATCH 08/10] use descript workspace name --- examples/aws-linux/main.tf | 8 +------- examples/aws-windows/main.tf | 8 +------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/examples/aws-linux/main.tf b/examples/aws-linux/main.tf index 4e67621e0a22a..de15565b537c8 100644 --- a/examples/aws-linux/main.tf +++ b/examples/aws-linux/main.tf @@ -60,12 +60,6 @@ data "coder_agent_script" "dev" { 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 { @@ -148,7 +142,7 @@ resource "aws_instance" "dev" { user_data = data.coder_workspace.me.transition == "start" ? local.user_data_start : local.user_data_end tags = { - Name = "coder-${lower(random_string.random.result)}" + Name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}" } } diff --git a/examples/aws-windows/main.tf b/examples/aws-windows/main.tf index 2926d11703b57..cf0db20d2cacf 100644 --- a/examples/aws-windows/main.tf +++ b/examples/aws-windows/main.tf @@ -47,12 +47,6 @@ data "coder_agent_script" "dev" { os = "windows" } -# assign a random name for the workspace -resource "random_string" "random" { - length = 8 - special = false -} - data "aws_ami" "windows" { most_recent = true owners = ["amazon"] @@ -97,7 +91,7 @@ resource "aws_instance" "dev" { user_data = data.coder_workspace.me.transition == "start" ? local.user_data_start : local.user_data_end tags = { - Name = "coder-${lower(random_string.random.result)}" + Name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}" } } From 788c2c5f1531de440dcfffb2493f0d6dc7bbc074 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 30 Mar 2022 17:58:02 +0000 Subject: [PATCH 09/10] use TF version --- examples/aws-linux/main.tf | 3 ++- examples/aws-windows/main.tf | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/aws-linux/main.tf b/examples/aws-linux/main.tf index de15565b537c8..6dfa861656ede 100644 --- a/examples/aws-linux/main.tf +++ b/examples/aws-linux/main.tf @@ -1,7 +1,8 @@ terraform { required_providers { coder = { - source = "coder/coder" + source = "coder/coder" + version = "0.2.1" } } } diff --git a/examples/aws-windows/main.tf b/examples/aws-windows/main.tf index cf0db20d2cacf..a7104e5425e08 100644 --- a/examples/aws-windows/main.tf +++ b/examples/aws-windows/main.tf @@ -1,7 +1,8 @@ terraform { required_providers { coder = { - source = "coder/coder" + source = "coder/coder" + version = "0.2.1" } } } From acedca5361e8d1d3cde4af64e8df7caffc41b927 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Thu, 31 Mar 2022 15:00:04 +0000 Subject: [PATCH 10/10] Fix requested changes on README --- examples/README.md | 12 ++++-------- examples/aws-linux/README.md | 4 ++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/examples/README.md b/examples/README.md index 9b0526f26df08..ed62ed2abb346 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,19 +1,15 @@ # Examples -Examples are available in our CLI with `coder projects init` +List examples in our CLI with `coder projects init`. -> Submit [an issue](https://github.com/coder/coder/issues/new) if you experience issues with an example! +> [Submit an issue](https://github.com/coder/coder/issues/new) if you encounter any issues! -## Getting Sarted +## Getting Started -Manually clone to create a project from any example in this repo: +Clone this repository to create a project from any example listed here: ```sh git clone https://github.com/coder/coder cd examples/aws-macos coder projects create ``` - -## Requests - -Submit [an issue](https://github.com/coder/coder/issues/new) or pull request to request features or more examples. diff --git a/examples/aws-linux/README.md b/examples/aws-linux/README.md index ee3b6adf15329..6bc248d3ba837 100644 --- a/examples/aws-linux/README.md +++ b/examples/aws-linux/README.md @@ -1,5 +1,5 @@ --- -name: Develop in Linux on AWS -description: Get started with Linux development on AWS. +name: Develop in Linux on AWS EC2 +description: Get started with Linux development on AWS EC2. tags: [cloud, aws] ---