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

feat: Add examples/templates/do-linux for Digital Ocean Droplets #1749

Merged
merged 13 commits into from
May 27, 2022

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented May 25, 2022

This PR adds an example that provisions workspaces as Digital Ocean Droplets and mounts a persistent volume for the users (coder) home directory.

I wanted to provision the workspaces in a specified Digital Ocean Project, but due to terraform detecting this as two workspace volumes, there's a side-effect of not being able to SSH into the workspace.

For now, the project specification is commented out:

# resource "digitalocean_project_resources" "project" {
#   project = var.step2_do_project_id
#   # Workaround for terraform plan when using count.
#   resources = length(digitalocean_droplet.workspace) > 0 ? [
#     digitalocean_volume.home_volume.urn,
#     digitalocean_droplet.workspace[0].urn
#     ] : [
#     digitalocean_volume.home_volume.urn
#   ]
# }

See #1750 for details on the issue.

@@ -0,0 +1,46 @@
#cloud-config
users:
- name: coder
Copy link
Member

Choose a reason for hiding this comment

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

We could even make the username their Coder username 👀

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I love that!

@mafredri mafredri force-pushed the mafredri/example-digital-ocean-droplet branch from aa51940 to 8d73582 Compare May 25, 2022 17:30
@coadler
Copy link
Member

coadler commented May 25, 2022

Super small nit, but do-droplet seems slightly redundant. For the other clouds we have gcp-linux, aws-linux, etc instead of gcp-gce-linux and aws-ec2-linux.

@mafredri
Copy link
Member Author

@coadler My motivation for using droplet was that DO offers managed k8s as well, and if we'd want to have one for that as well, what would we call it? I'm OK with making the change though.

@coadler
Copy link
Member

coadler commented May 25, 2022

This is true for the other clouds too though. Maybe we should have subfolders for each cloud? Don't mean to derail this at all, just thinking out loud!

@mafredri
Copy link
Member Author

Good point. How about I make the change here to standard naming scheme, then we can consolidate later? At the risk of bike-shedding, I do kind of like that the name explains exactly what it is since the name is often inherited from the folder name. So we'd have gcp-gce-linux instead of gce-linux (via gcp/gce-linux).

@coadler
Copy link
Member

coadler commented May 25, 2022

Works for me!

examples/do-droplet-linux/main.tf Outdated Show resolved Hide resolved
examples/do-droplet-linux/main.tf Outdated Show resolved Hide resolved
examples/do-droplet-linux/cloud-config.yaml.tftpl Outdated Show resolved Hide resolved
description = "Which Droplet image would you like to use for your workspace?"
default = "ubuntu-22-04-x64"
validation {
condition = contains(["ubuntu-22-04-x64", "ubuntu-20-04-x64", "fedora-36-x64", "fedora-35-x64", "debian-11-x64", "debian-10-x64", "centos-stream-9-x64", "centos-stream-8-x64", "rockylinux-8-x64", "rockylinux-8-4-x64"], var.droplet_image)
Copy link
Member Author

Choose a reason for hiding this comment

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

I wanted to conditionally include Fedora images based on if SSH key is set, but it's not possible, unfortunately :/ hashicorp/terraform#25609

Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

Looking great!

examples/do-linux/main.tf Outdated Show resolved Hide resolved
Co-authored-by: Cian Johnston <cian@coder.com>
@mafredri
Copy link
Member Author

Right now we leave the SSH server running on the Droplet. I think this is OK, if someone doesn't want that, they can edit the cloud-config to disable it. Or should it be an option?

With the last commit (08483d8) we could in theory use remote-exec instead of cloud-config (when SSH key is provided). But perhaps that could be left for an alternative implementation of this template.

@mafredri mafredri marked this pull request as ready for review May 27, 2022 12:01
@mafredri mafredri changed the title feat: Add examples/do-droplet-linux for Digital Ocean Droplets feat: Add examples/templates/do-linux for Digital Ocean Droplets May 27, 2022
@mafredri mafredri merged commit 1a70298 into main May 27, 2022
@mafredri mafredri deleted the mafredri/example-digital-ocean-droplet branch May 27, 2022 17:04
kylecarbs pushed a commit that referenced this pull request Jun 10, 2022
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.

None yet

4 participants