Skip to content

add: ECS example template #3915

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 5 commits into from
Sep 8, 2022
Merged

add: ECS example template #3915

merged 5 commits into from
Sep 8, 2022

Conversation

ericpaulsen
Copy link
Member

this PR adds an example template for creating a workspace as an Elastic Container Service (ECS) hosted container.

I'm submitting this as a draft because of a current issue with stop/start. the workspace builds fine initially, but does not shut down the resources once stopped. I tinkered with adding the count = data.coder_workspace.me.start_count argument to the Task Definition resource, but am receiving an odd error when building the template:

Error: Invalid index
The given key does not identify an element in this collection value: the collection has no elements.

I haven't been able to debug this error, and would like some extra eyes to assist.

@ericpaulsen ericpaulsen requested a review from bpmct September 6, 2022 21:16
@ericpaulsen ericpaulsen self-assigned this Sep 6, 2022
@ericpaulsen ericpaulsen marked this pull request as draft September 6, 2022 21:21
@ericpaulsen ericpaulsen requested review from bpmct and removed request for bpmct September 6, 2022 21:21
Copy link
Member

@bpmct bpmct left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this! Tested it out and left some comments which seem to scale up/down the service based on stop and add support for 2 workspaces.

I don't know too much about ECS, but my basic understanding is:

  • You create a cluster, typically with AWS instances (VMs)
  • You deploy "services" which are containers that run across the VMs

Does this use case aim to provision 1 cluster per workspace, or provision workspaces on an existing cluster, similar to Kubernetes? After the proposed changes are added, this template somehow:

  1. provisions a cluster when workspace 1 is created + a service + autoscaling group
  2. provisions services, autoscaling groups on the existing cluster created by workspace 1

It's kinda nice, but doesn't seem like the expected behavior given the Terraform code. I expected it would provision 1 cluster per developer, which seems overkill.

ecs

If we don't want this template to create a cluster (at least 1 VM) per developer, we might want to recommend that the Coder admin provisions the cluster (and perhaps the autoscaling group, capacity provider) outside of Coder and then just uses 1 aws_ecs_service per workspace, similar to our K8s examples.

The cluster can still be provisioned with Terraform, just via a single terraform apply, outside of Coder not as a part of each workspace.

@ericpaulsen ericpaulsen requested a review from bpmct September 7, 2022 15:50
@ericpaulsen ericpaulsen marked this pull request as ready for review September 8, 2022 13:42
Copy link
Member

@bpmct bpmct left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worked great for me!


variable "ecs-cluster" {
description = "Input the ECS cluster ARN to host the workspace"
default = ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
default = ""
sensitive = true

We're currently using this to indicate whether this is a developer-level variable or template-wide variable. I assume the intended behavior is that the admin picks which cluster workspaces are deploying to?

I also suggest not setting a default value since it will skip it on coder templates create

Some docs: https://coder.com/docs/coder-oss/latest/templates#parameters

Co-authored-by: Ben Potter <ben@coder.com>
@ericpaulsen ericpaulsen enabled auto-merge (squash) September 8, 2022 15:21
@ericpaulsen ericpaulsen merged commit 9c5b879 into main Sep 8, 2022
@ericpaulsen ericpaulsen deleted the ecs-example branch September 8, 2022 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants