Skip to content
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

chore: refactor folder structure #142

Merged
merged 5 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/kubectl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

-
id: get-aws-info
working-directory: ./.github/aws
working-directory: ./coder-deployment/terraform_info
shell: bash
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-build-dev-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
push:
paths:
- '.github/.devcontainer/**'
- '.github/.devcontainer/pre-build/**'
- '.github/workflows/pre-build-dev-container.yml'
branches:
- "main"
Expand Down
23 changes: 8 additions & 15 deletions .github/workflows/test_user_data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request:
paths:
- '.github/workflows/test_user_data.yml'
- './k8s/user_data.sh'
- './k8s/coder-deployment/terraform/scripts/user_data.sh'
branches:
- "main"

Expand All @@ -22,19 +22,12 @@ jobs:
id: checkout
uses: actions/checkout@v1

- run: apt update
- run: apt install curl -y

- run: sed -i "2a\\alias sudo=''" ./user_data.sh
name: Add alias to mock sudo
working-directory: ./k8s

- run: chmod +x ./user_data.sh
name: Add execute permissions
working-directory: ./k8s


- run: ./user_data.sh
working-directory: ./k8s
- working-directory: ./coder-deployment/terraform/scripts
run: |
apt update
apt install curl -y
sed -i "2a\\alias sudo=''" ./user_data.sh
chmod +x ./user_data.sh
./user_data.sh


File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 1 addition & 6 deletions k8s/ec2.tf → coder-deployment/terraform/ec2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module "ec2_temp_instance_v2" {

ami = data.aws_ami.ubuntu.id
source = "terraform-aws-modules/ec2-instance/aws"
user_data = file("${path.module}/user_data.sh")
user_data = file("${path.module}/scripts/user_data.sh")

name = "eks-cluster-tmp-manager-instance-v2"

Expand Down Expand Up @@ -119,11 +119,6 @@ resource "aws_eip_association" "eip_assoc" {

# ----------------- OUTPUT --------------------

output "user_data" {
value = file("${path.module}/user_data.sh")

}

output "ssh_command" {
value = try("ssh -i id_ed ubuntu@${aws_eip.ip_of_manager_instance.public_ip}", null)
}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh -x
set -x

# INSTALL DOCKER
sudo apt update -y
Expand Down
File renamed without changes.
File renamed without changes.
95 changes: 95 additions & 0 deletions coder-deployment/terraform_coder_templates/aws-linux/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
display_name: AWS EC2 (Linux)
description: Provision AWS EC2 VMs as Coder workspaces
icon: ../../../site/static/icon/aws.svg
maintainer_github: coder
verified: true
tags: [vm, linux, aws, persistent-vm]
---

# Remote Development on AWS EC2 VMs (Linux)

Provision AWS EC2 VMs as [Coder workspaces](https://coder.com/docs/v2/latest/workspaces) with this example template.

<!-- TODO: Add screenshot -->

## 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

The following sample policy allows Coder to create EC2 instances and modify
instances provisioned by Coder:

```json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"ec2:GetDefaultCreditSpecification",
"ec2:DescribeIamInstanceProfileAssociations",
"ec2:DescribeTags",
"ec2:DescribeInstances",
"ec2:DescribeInstanceTypes",
"ec2:CreateTags",
"ec2:RunInstances",
"ec2:DescribeInstanceCreditSpecifications",
"ec2:DescribeImages",
"ec2:ModifyDefaultCreditSpecification",
"ec2:DescribeVolumes"
],
"Resource": "*"
},
{
"Sid": "CoderResources",
"Effect": "Allow",
"Action": [
"ec2:DescribeInstanceAttribute",
"ec2:UnmonitorInstances",
"ec2:TerminateInstances",
"ec2:StartInstances",
"ec2:StopInstances",
"ec2:DeleteTags",
"ec2:MonitorInstances",
"ec2:CreateTags",
"ec2:RunInstances",
"ec2:ModifyInstanceAttribute",
"ec2:ModifyInstanceCreditSpecification"
],
"Resource": "arn:aws:ec2:*:*:instance/*",
"Condition": {
"StringEquals": {
"aws:ResourceTag/Coder_Provisioned": "true"
}
}
}
]
}
```

## 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`
resource block. The `coder_app` resource is defined to access `code-server` through
the dashboard UI over `localhost:13337`.
Loading