Introducing a Terraform provider for Forem

I am glad to announce that I have just released a Terraform provider for Forem! This provider is my small contibution to this amazing open-source project. You can find its source code on Github and the provider’s page on Terraform registry.

T…


This content originally appeared on DEV Community and was authored by karvounis

I am glad to announce that I have just released a Terraform provider for Forem! This provider is my small contibution to this amazing open-source project. You can find its source code on Github and the provider's page on Terraform registry.

TL;DR

Manage your Forem resources using code! Forem as Code (FaC) following the Infrastructure as Code (IaC) concept.

Need

Forem is a great software project and the platform that powers dev.to. When I published my first article in dev.to, I found it very easy to navigate through the browser interface of Forem, create, write, and edit the article.

However, while I was writing the second article, I realised that there are a lot of similarities between them and that certain things can be automated. I also realised that the more articles you publish, the harder their maintenance is going to get. Using just the browser does not scale well and there is certainly room for automation.

I decided to use Terraform to automate the management of Forem resources. Quoted from their website:

Terraform is an open-source infrastructure as code software tool that provides a consistent CLI workflow to manage hundreds of cloud services. Terraform codifies cloud APIs into declarative configuration files.

If there is an API, you can create a Terraform provider for it!

API

Forem has an API that you can use in order to create and update articles, listings and a few other resources. Instead of using the browser, you can send HTTP requests to the api endpoint of the Forem installation and read, create or update the resources you need.

Example

You can either visit the linkg https://dev.to/karvounis/basic-traefik-configuration-tutorial-593m from your browser or send the following curl request:

curl https://dev.to/api/articles/karvounis/basic-traefik-configuration-tutorial-593m

How to use it

The provider requires two arguments:

  • api_key (String) API key to be able to communicate with the FOREM API. Can be specified with the FOREM_API_KEY environment variable.
  • host (String) Host of the FOREM API. You can specify the dev.to or any other Forem installation. Can be specified with the FOREM_HOST environment variable. Default: https://dev.to/api.

In order to generate an API key, go to Settings -> Account -> DEV Community API Keys, give it a proper description and press the Generate API Key button.

Forem Articles through Terraform

You can create a new Forem article using the examples shown here. In this example, both example_file and example_full articles use the same tags that are defined in the locals block.

Imagine having way more articles maintained by Terraform and you need to remove a specific tag from all of them. With this provider, you can just remove that tag from the list, re-run the plan and Terraform will be smart enough to understand the difference and remove this tag from all the articles. By doing that, we saved ourselves a lot of clicks!

Currently supported

Currently, the lastest Terraform provider version is 1.0.1 and supports the following Forem resources and actions:

Resources Actions
Articles Create, Update, Read, Import
Listings Create, Update, Read, Import
Data Sources Actions
Articles Get By ID, Get By username and slug
Listings Get By ID
Users Get By ID, Get By username

Conclusion

I really hope that this provider is going to help all people using Forem. In fact, this very article has been generated using this provider! Don’t take my word for it, check the Terraform article resource and the actual Markdown file! 😉

Any contributions to the provider are welcome and I would appreciate any feedback in the comments section! Cheers!

Useful links


This content originally appeared on DEV Community and was authored by karvounis


Print Share Comment Cite Upload Translate Updates
APA

karvounis | Sciencx (2022-04-14T06:44:36+00:00) Introducing a Terraform provider for Forem. Retrieved from https://www.scien.cx/2022/04/14/introducing-a-terraform-provider-for-forem/

MLA
" » Introducing a Terraform provider for Forem." karvounis | Sciencx - Thursday April 14, 2022, https://www.scien.cx/2022/04/14/introducing-a-terraform-provider-for-forem/
HARVARD
karvounis | Sciencx Thursday April 14, 2022 » Introducing a Terraform provider for Forem., viewed ,<https://www.scien.cx/2022/04/14/introducing-a-terraform-provider-for-forem/>
VANCOUVER
karvounis | Sciencx - » Introducing a Terraform provider for Forem. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/04/14/introducing-a-terraform-provider-for-forem/
CHICAGO
" » Introducing a Terraform provider for Forem." karvounis | Sciencx - Accessed . https://www.scien.cx/2022/04/14/introducing-a-terraform-provider-for-forem/
IEEE
" » Introducing a Terraform provider for Forem." karvounis | Sciencx [Online]. Available: https://www.scien.cx/2022/04/14/introducing-a-terraform-provider-for-forem/. [Accessed: ]
rf:citation
» Introducing a Terraform provider for Forem | karvounis | Sciencx | https://www.scien.cx/2022/04/14/introducing-a-terraform-provider-for-forem/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.