Reconciler pattern and how terraform uses it.

Reconciler Pattern is used by many cloud-specific tools to perform thier functionalities. In this article we are going to talk about the reconciler pattern. And this is the pattern on which terraform is build. So lets start our article on what is reconciler pattern and how terraform uses reconciler pattern.

So reconciler pattern is a software design pattern which is very useful if you are working with project in which you have a state that you want your software to be in. And then you compare you software state and fix the changes that are present. If this is confusing next few point will fix it for you.

Following are the methods of the reconciler pattern.

GetExpected:

This method will give you what your expected state you want to for your software or any remote resource. Generates a graph how the resources are connected to each other thus resulting in order in which they will be created.

GetActual:

This method will give you the current state of your software or any remote resource.

Reconcile:

This method actually calculates the difference between the actual state and expected state and apply that to make the state what is expected. This apply works in the order which is decided while GetExpected is executed.

Destory:

This method deletes everything but in the reverse order of what is generated by GetExpected.

So this are simple methods that implements the reconciler pattern. In short, You software checks for remote state, what state you want, gets the difference and apply that difference.

How terraform works on this?

So terraform has following steps that it performs.

Terraform Plan:
In this step it makes a remote call to get current state, then creates a map from the configs you define in tf file, compares both of them and then creates a plan on what it will do.

Suggested Books for terraform:

Terraform Apply:
In this step the difference is applied on the remote resource.

Terraform destory:

Same as destroy method, it deletes the resources in reverse order in which they were created.

If you like the article please share and subscribe.


Gaurav Yadav

Gaurav is cloud infrastructure engineer and a full stack web developer and blogger. Sportsperson by heart and loves football. Scale is something he loves to work for and always keen to learn new tech. Experienced with CI/CD, distributed cloud infrastructure, build systems and lot of SRE Stuff.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.