DEV Community

Cover image for I accidentally contributed to Terraform
Iduoad
Iduoad

Posted on • Originally published at iduoad.com

I accidentally contributed to Terraform

Before I start telling you how I contributed to Terraform, I should admit that the title is a little clickbait 😅! Not totally, but just a little.

The goal of this blog post is not to tell you that I contributed to Terraform or to brag. The goal is to share my take on Open Source contribution, which I came to after countless conversations with various people in the community and some small and humble contributions.

This blog post is divided into four lessons I learned about contributing to open source throughout my humble career, while telling the story of how I contributed to Terraform.

I. OSS contribution always starts with involvement

My story begins with LXC and Incus. If you know me, you know that I am a huge fan of containers in all their types and forms. One of the forms I like and use heavily is system containers, and in particular LXC containers.

Since I use them so much, I started using Terraform to create reusable setups on LXC with Incus (a more open LXD alternative).

After a while, I found myself redoing the same work, especially when it came to spinning up machine container clusters for experimentation. So I started looking for ready-to-use Terraform modules for Incus to make my life, and my setups easier.

Not to my surprise, I found none, and this is normal since Incus is a fairly new fork of LXD and the awesome people behind it are still working on the ecosystem.

✍️ ✍The first lesson here is that in order to contribute to open source, you should get involved first. Your first contribution to an OSS project is installing it on your machine and starting to use it.

Building your own OSS project counts as an Open Source contribution

Now, I knew that something was missing, and I knew that at least someone needed it (I was the first user 😁). I started working on the first Terraform module to create instances. My end goal was to replicate my manual Kubernetes setup using the Terraform module and be able to create multiple clusters of all sizes and shapes with as few lines of code as possible, and with a single terraform apply.

While implementing a few features in my Terraform module, I discovered a bug. This links back to the first lesson: you need to get involved in order to find something you can contribute. After a lot of troubleshooting and debugging, I figured out that the bug was not on my side but on the Terraform provider's side.

So I headed to the Incus provider GitHub page and created an issue with a detailed description of the bug.

Getting "Only image or source_instance can be set" even if source_instance defaults to null · Issue #180 · lxc/terraform-provider-incus

Writing a detailed and, at the same time, on-point issue is very important. It helps the maintainers and developers of the project identify the problem faster and either point you to a solution or acknowledge the bug. It also avoids unnecessary back-and-forth.

✍️ The second lesson is not to underestimate starting an OSS project of your own. It counts as and OSS contribution.

Take the initiative

After some back-and-forth in the issue and some encouragement from the Incus maintainers, I decided to take the initiative and start working on the fix. Although I didn't have experience with Terraform providers, I took it as a learning opportunity and created a PR.

Add plugin framework conflicts_with and at_least_one_of to instance by Iduoad · Pull Request #181 · lxc/terraform-provider-incus

At first, it was really hard. I didn't know where to start, and the LLMs were not very knowledgeable about the topic back then (or maybe I wasn't good at prompting). So I decided to start learning about Terraform providers, especially the validation part—where the bug was.

I spent days learning a lot of new things, and reading a lot of code. Once I felt a bit confident, I started implementing the fix.

My fix worked, and I was happy for a while... Until the Terraform provider started behaving in weird ways again.

Go through the rabbit hole if needed

After more back-and-forth on the PR, countless trials and errors, and doubting my Terraform provider understanding (then learning again) I decided to take it to the Terraform Plugin Framework itself and consider it a bug on their side.

At first, I was still unsure whether the bug was actually in the Terraform Plugin Framework, so I started by creating an issue in their forum.

Conflicts_with fails the plan when some of the attributes is set from a variable - Terraform Providers / Plugin Development - HashiCorp Discuss

As I expected from the answer on the forum, this was most likely a bug on their side. So I created an issue in their GitHub repository and, BAM! It was a bug in terraform-plugin-framework-validators.

Conflicts_with fails during Validate even if one of the values is Unknown · Issue #251 · hashicorp/terraform-plugin-framework-validators

This time, I didn't fix it myself since the issue was already picked up by the Terraform team and was pending release.

I waited for it to be released and then went back one layer up the recursion.

The fix

When the version with the fix was released, I picked it up and continued working on my original fix. I even refactored a small part of the argument validation to make it a bit simpler.

Fortunately, this time my Terraform test code was working. My PR was merged, and I moved back one layer of recursion to continue working on my Terraform module.

Conclusion

Although I still haven't released the first Terraform module (it was delayed due to the provider release, and I got a bit busy with other work), starting work on it led me to discover a bug, engage with the community, and even contribute to fixing it.

The most important message I have for people who want to start contributing to OSS is to get involved. Pick something you like and start using it. Read its code, read the issues, discuss in the forums, and you will slowly discover bugs and features you want to add, and maybe work on them yourself.

Finally, I want to thank the awesome Incus community (and Terraform team) for their kindness and for building this amazing project and its entire ecosystem.

Top comments (0)