Coder workspaces with XCP-ng and XOA

Table of Contents

Introduction

It’s been a long time since I ditched powerful, bulky, and pricey laptops for “cloud”-based dev environments.
I started by using VSCode devcontainers and JetBrains Gateway, I ended up sharing my servers with friends. This created the need for a more industrial, dedicated dev-env manager. After extensive research, I adopted Coder, which provides all the features I need in their community edition (though more open core than open source, but at least the SSO part is included in the open version).

Initially, I focused on using devcontainers, but hosting them on ARM machines quickly revealed their limitations. Now, I’ve shifted to hosting a few x86 machines running XCP-ng, all managed through XOA. This setup would theoretically allow me to fully make use of my infrastructure and create high-performance, scalable development environments tailored to our needs.

However, there was no official or community-supported template for creating environments with Coder. Although I had never worked with Terraform before, which initially held me back, I finally decided to take the leap.

Understanding XOA and Terraform

I started by creating a VM from an XOA template, along with its disk and network, and initializing it using cloud-init. Thanks to the Terraform documentation and XOA’s Provider, the process was pretty straightforward, and I was able to get a VM up and running within minutes. After a few iterations, I successfully set everything “cleanly” up using variables, checks, and automatic fills.

Next, it was time to integrate Coder as a template.

Getting My Hands on Coder Templates

I started with the “Scratch” template and the Write a template from scratch tutorial to get familiar with the Coder Terraform provider. I initially tried to use my previous Terraform file almost as-is, adding the Coder agent and VSCode server with what’s provided. The native integration with variables made it quite easy to set up.

From POC to Complete Integration

I wasn’t satisfied with the “template-provided” variables because I wanted my users as well as myself to have the flexibility to set their vCPU number, XOA template, etc., as they wish. This is when I discovered the coder_parameter data source, which allows exactly that! A few iterations later, I made it automatically search for available hosts, vCPUs, memory, etc., to ensure users couldn’t input incorrect values. I also added coder_workspace labels to provide info and links about the VM (host, SR, network, etc.).

At the time of writing, there are still some hacky parts, like the SR and Network listing, which the XOA Provider doesn’t seem provide (I might submit a PR soon to add these features if they are indeed not present). There are also some wording changes and Quality of Life (QoL) improvements that may require feedback from usage.

The template is hosted on GitHub—feel free to contribute with feedback and improvements! The template is provided under the MIT license.

Current Features

At the time of writing, the template:


Go to Top