06/01/2019

What I learned from refactoring Terraform provider - Golang

Beginning of 2018 was my real expose to Golang. It's almost a year now! (before that was just playing around where I can just read the syntax).

Working with a new programing language is a bit different from person to another. It depends on many factors like your background, experience, the language itself, and many others.

For me, it was interesting to follow up how I did learn a new language from a different paradigm (my whole experience before that was with interpreted languages like Python, Ruby, Perl, and Bash).

First step was writing something simple that I wrote before in a language I know (Python). So I already know the logic, the goal, and I just need to implement it in the new language (Golang). It's a bit easy and straightforward, you mainly focus on the code syntax.

Second step was writing a plugin from scratch for bigger application or ecosystem that you already know (I used to use InfluxData Telegraf for almost 2 years before that).

As a DevOps part of Data Science team, I wrote Apache Flume plugin for Telegraf. But writing a plugin from scratch in a new language has two faces, one easy and another hard!

  • The easy, you just need to focus on one thing and don't really have to take care of whole application. Also you have good examples to learn from.
  • The hard, you need also to understand the application internals and how it's actually works. And of course the language itself.

Third step was refactoring someone else code. That was Terraform provider for Proxmox. It was a great experience for me because I rewrote big part of the plugin logic! And not just the plugin, but also the API library that's used by the plugin too!

So here you need to:

  • Get the logic, specially if you are not into it that much (Proxmox was sort of legacy in my work stack but we wanted to get maximum use of it).
  • Understand the connections internally and between the components.
  • Deal with someone else code and style for a language you just started with recently.
  • Rewrite a "working prototype" (as plugin creators state) was also another nice part you need to deal with. Where you will shape the structure of the project.

Fourth step was writing a full app from scratch! (which was 6 months later after my first real code). Where you do everything related to the app in that language. Which simply exposes you not just to the core of the language, but also to its whole ecosystem!

So here you will know more about:

  • Syntax, logic, and so on.
  • More internals and idioms.
  • How project/code is structured.
  • Helper tools.
  • Release style in terms of CI/CD.
  • Testing style (unit and/or integration)

That was my first API (with CLI) that I wrote to fix one of my problems (working in a hybrid dynamic environment e.g. on-premise and public cloud) ... but this is another story I will write about it another time :-)

And now I not just have a better understanding of Golang, but also I understand my way of learning and how I deal with new stuff ... so it's kind of "meta understanding" :-)

Powered by Blogger.

Hello, my name is Ahmed AbouZaid and this is my "lite" technical blog!

I'm a passionate DevOps, Linux system engineer, RHCE, AWS SysOps/Solutions Architect, Free/Open source geek, author, interested in environment, calligraphy, and I believe that “Details Matter”!

Automation, data, and metrics are my preferred areas. I have a built-in monitoring chip, and too lazy to do anything manually :D

Popular Posts