Over recent years, infrastructure as code has made creating and managing a complex cloud environment —plus making necessary ongoing changes to that environment—significantly more streamlined. Rather than having to handle infrastructure management separately, developers can push infrastructure changes and updates alongside updates to application code.
Terraform from HashiCorp has been a leading tool in the charge of making infrastructure as code more accessible. While early versions, admittedly, involved a steep learning curve, as upgrades have been made the tool becomes more and more workable. The latest version of Terraform v0.12, introduced a number of changes that make using the programming language inside the tool much simpler.
Command Improvements
Terraform v0.12 variations have seen major updates indeed since a lot of commands and features have been changed over the last three months. HCL, the underlying language used by Terraform, has been updated too; we will get to this in a bit.
The use of first-class expressions is perhaps the most notable update of them all in the new version. Rather than wrapping expressions in interpolation sequences using double quotes, expressions can now be used natively. This makes more sense as many developers may be more used to the latter. Developers can now use variables like var.conf[1]
rather than calling it using the old format of “${var.conf}”
.
Expressions are also strengthened by the introduction of for
expressions to filter lists and map values. The use of for
as a filter is also a great improvement; it makes advanced infrastructure manipulation based on conditions easier to achieve.
There is also a more general operator. You can use resource.*.field
syntax in any application rather than for components with their count
specifically set. The same general operator is also compatible with any list of value you add to your code.
At Caylent, we love the use of 1:1 JSON mapping. Conversion of HCL configuration to and from JSON happens seamlessly and with no possibility of errors and problems. This may look like a small update at first, but it is a simple change that will make life significantly smoother for developers who manage their own infrastructure using Terraform.
More Updates in Terraform v0.12
Other changes are just as interesting. As mentioned before, HashiCorp updated the HCL programming language extensively in this version. There are limitations to using HCL and we —developers —have been relying on workarounds to make things work. Terraform v0.12, as the previous points demonstrate, really eliminates a number of bottlenecks we’ve been facing all along.
There is also the fact that you can now use conditional operators to configure infrastructure. First of all, I’m glad to inform you that null
is now a recognized value. When you assign null
to parameters or fields, the default value set by the infrastructure will be used instead.
Conditional operators like ?
and :
are also handy to use, plus you can now rely on lazy evaluation of results when using Terraform to code your infrastructure. Using the previous example, fields that contain null actually get omitted from the upstream API calls.
Complex lists and maps are also now supported. This is perhaps the biggest change in this version. While Terraform supported only simple values in the past, you can now use complex lists and maps in both inputs and outputs. You can even code lines to control modules and other components.
Another version upgrade worth mentioning is the new access to resources details using remote state outputs. The v0.12 release sees terraform_remote_state data source
changing slightly so that all the remote state outputs are now available as a single map value, in contrast to how previously they were top-level attributes.
It’s also worth commenting on the new, improved ‘Context-Rich Error Messages’ which make debugging much easier than in previous versions. Not all messages will include the following elements but most will conform to this structure:
- A short problem description
- A specific configuration construct reference
- Any reference values necessary
- A longer, more thorough problem and possible solutions
Last but certainly not least, Terraform now recognizes references as first-class values. Yes, no more multiple quotes and having to nest references when coding updates for your infrastructure. Resource identifiers can also be outputted or used as parameters, depending on how your infrastructure is set up.
Real-World Challenges
The new version of Terraform has seen many big updates since the start of v0.12.0 in May 2019, and the engineers behind this framework worked really hard in making sure that no configuration changes are needed. In fact, the average Terraform user will not have to make any changes when updating to Terraform v0.12.
However, breaking changes are to be expected and if you do have to mitigate changes that need to be made due to the upgrade to Terraform v0.12, HashiCorp is working on an automated tool that makes the process possible. You can use the tool to calculate compatibility and anticipate potential issues that may stem from the upgrade.
One last thing to note about this latest update: it’s only the beginning. Terraform v0.12 is a signal from the engineers behind this tool that they are serious about pushing Terraform (and HCL) further. Upcoming releases and iterations are already in the pipeline, with refinements like better versioning and seamless upgrade being among the major changes.
It is inspiring to see engineers work so hard to ensure that there are little to no breaking changes with every version they push. Terraform may well be the IAC language of the future if it continues to bring positive updates and useful tools to its framework at the current pace.
Caylent provides a critical DevOps-as-a-Service function to high growth companies looking for expert support with Kubernetes, cloud security, cloud infrastructure, and CI/CD pipelines. Our managed and consulting services are a more cost-effective option than hiring in-house, and we scale as your team and company grow. Check out some of the use cases, learn how we work with clients, and read more about our DevOps-as-a-Service offering.