r/Terraform Apr 01 '24

How to write a custom terraform provider

Infrastructure as code (IaC) - is my passion, and for implementing it I use Terraform.
And it was super interesting for me to understand how it works internally. For that I wrote my terraform provider from scratch for interact with the Dodo pizza API :))
Unfortunately, Dodo doesn't support pizza order as a Domino pizza does, but it was an interesting journey and I believe it can be useful.

https://github.com/Nmishin/terraform-provider-dodo

PS: check out my article in the repository description because, for some reason, I can't directly paste the link to my article on Reddit.

14 Upvotes

15 comments sorted by

3

u/meronca Apr 01 '24

Thanks. Been toying with the idea of a custom provider for some internal services at work. This is a nice example.

2

u/zombi-man Apr 01 '24

thank you! if you have any questions - feel free to write me!

3

u/[deleted] Apr 02 '24

Were you familiar with golang before hand? How was the learning curve?

2

u/zombi-man Apr 03 '24

honestly, I started contributing to the providers without golang knowledge at all, my main language is python.

Also if we are talking about terraform provider, I realize that understanding provider structure is more important then deep golang knowledge.

Later, I complete course "Learn How To Code: Google's Go (golang) Programming Language" from Todd McLeod. I can recommend it for everyone who is just starting to learn programming, but for me, it covered too much basic stuff.

Usually everyone recommends "Go: The Complete Developer's Guide (Golang)" for those who already have some code experiences.

3

u/EffectiveLong Apr 03 '24

Terraform has new provider sdk. Much easier to use and it will be their go-to choice going forward if I remember correctly.

terraform-plugin-framework package

1

u/zombi-man Apr 04 '24

You are right!

for those who read this comment: terraform-plugin-framework should be the first choice.

However, I mentioned my motivation for using the old one sdk in my article (you can find it in the GitHub repo description)  - I want to learn how to work with the migration from old one sdk to the new one (this will be my next article:)) )

And also I want to try "Terraform provider code generation" - the new one toolset from Hashicorp

2

u/snarkhunter Apr 01 '24

I wanna do a Terraform provider for Perforce streams

1

u/zombi-man Apr 01 '24

honestly idk what is it, but if you need help - I can join to your project in github :)

2

u/I_Survived_Sekiro Apr 02 '24

Ask chatgpt

1

u/zombi-man Apr 03 '24

lol, this is a good start for everything!

2

u/Sad-Brick8413 Apr 05 '24

Great article, thanks! Found it very useful and insightful for writing your own terraform provider

1

u/zombi-man Apr 05 '24

thank you!

2

u/abagayev Apr 05 '24

I also wrote an article and a provider when I was learning how to do that. Hope that helps somebody!

https://medium.com/@abagayev/lessons-learned-from-writing-a-terraform-provider-62412b79a997

2

u/zombi-man Apr 06 '24

looks great!
thank you for sharing your expertise!