Terraform Part 2

In the previous post 'Intro to Terraform', I provided an introduction to Terraform. In this post, I will be digging a little bit deeper into how Terraform could be used in real world usecases.

How to use organize Terraform files?

We can organize Terraform files so that, each component which we would provision would go into its own .tf file. That way, we can have a modularized approach.


This file would have the provider configuration details, so that any change to provider related config could be done in one place.


This file would have the variables used by every different file. We can variabilize different parts of our infrastructure configuration, like for eg, the CIDR ranges which will be used in VPC and subnet. This way, we can parameterize our provisioning code.

One tf file per Component:

We can have one .tf file per component, for instance, a vpc.tf file, a subnet.tf file etc. This way we can isolate changes.

Data Selector:

Another important feature which we can use is the Datasource configuration. Let us say we create a component in one file (say vpc) and in another file we would like to retrieve the Id of this component. One good way to do this is to configure a datasource and use it to filter and retrieve the component.


Data Configuration for Policy:

If we are going to create a IAM policy (let us say for SQS), using terraform, one of the challenges is how to do we create provide all the inputs required for this policy. Generally, AWS policies are in JSON format. Terraform provides a data configuration option for this.

Below is an example for creating a policy for SQS. We can provide all the required config data in data node and then use the .json option while creating resource.


Popular posts from this blog

Pivotal Cloud Foundry (PCF) Integration with Elastic Cloud Storage (ECS)

Restful code example using Spring MVC

Spring Integration - Bulk processing Example