docs: improve structure for example templates (#9842)

Co-authored-by: Kyle Carberry <kyle@carberry.com>
Co-authored-by: Muhammad Atif Ali <atif@coder.com>
Co-authored-by: Muhammad Atif Ali <me@matifali.dev>
This commit is contained in:
Ben Potter
2023-12-17 17:05:13 +03:00
committed by GitHub
co-authored by Kyle Carberry Muhammad Atif Ali Muhammad Atif Ali
parent 3f6096b0d7
commit 2e86b76fb8
38 changed files with 473 additions and 1343 deletions
+29 -12
View File
@@ -1,21 +1,27 @@
---
name: Develop in Linux on AWS EC2
description: Get started with Linux development on AWS EC2.
tags: [cloud, aws]
icon: /icon/aws.png
display_name: AWS EC2 (Linux)
description: Provision AWS EC2 VMs as Coder workspaces
icon: ../../../site/static/icon/aws.png
maintainer_github: coder
verified: true
tags: [vm, linux, aws, persistent-vm]
---
# aws-linux
# Remote Development on AWS EC2 VMs (Linux)
To get started, run `coder templates init`. When prompted, select this template.
Follow the on-screen instructions to proceed.
Provision AWS EC2 VMs as [Coder workspaces](https://coder.com/docs/coder-v2/latest) with this example template.
## Authentication
<!-- TODO: Add screenshot -->
This template assumes that coderd is run in an environment that is authenticated
with AWS. For example, run `aws configure import` to import credentials on the
system and user running coderd. For other ways to authenticate [consult the
Terraform docs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#authentication-and-configuration).
## Prerequisites
### Authentication
By default, this template authenticates to AWS using the provider's default [authentication methods](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#authentication-and-configuration).
The simplest way (without making changes to the template) is via environment variables (e.g. `AWS_ACCESS_KEY_ID`) or a [credentials file](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html#cli-configure-files-format). If you are running Coder on a VM, this file must be in `/home/coder/aws/credentials`.
To use another [authentication method](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#authentication), edit the template.
## Required permissions / policy
@@ -71,6 +77,17 @@ instances provisioned by Coder:
}
```
## Architecture
This template provisions the following resources:
- AWS Instance
Coder uses `aws_ec2_instance_state` to start and stop the VM. This example template is fully persistent, meaning the full filesystem is preserved when the workspace restarts. See this [community example](https://github.com/bpmct/coder-templates/tree/main/aws-linux-ephemeral) of an ephemeral AWS instance.
> **Note**
> This template is designed to be a starting point! Edit the Terraform to extend the template to support your use case.
## code-server
`code-server` is installed via the `startup_script` argument in the `coder_agent`
+25 -26
View File
@@ -212,36 +212,35 @@ resource "coder_app" "code-server" {
locals {
linux_user = "coder"
user_data = data.coder_workspace.me.start_count > 0 ? trimspace(<<EOT
Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0
user_data = <<-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"
--//
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]
hostname: ${lower(data.coder_workspace.me.name)}
users:
- name: ${local.linux_user}
sudo: ALL=(ALL) NOPASSWD:ALL
shell: /bin/bash
#cloud-config
cloud_final_modules:
- [scripts-user, always]
hostname: ${lower(data.coder_workspace.me.name)}
users:
- name: ${local.linux_user}
sudo: ALL=(ALL) NOPASSWD:ALL
shell: /bin/bash
--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"
--//
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 -u ${local.linux_user} sh -c '${coder_agent.dev[0].init_script}'
--//--
EOT
) : ""
#!/bin/bash
sudo -u ${local.linux_user} sh -c '${try(coder_agent.dev[0].init_script, "")}'
--//--
EOT
}
resource "aws_instance" "dev" {