<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Anthony Vickers on Medium]]></title>
        <description><![CDATA[Stories by Anthony Vickers on Medium]]></description>
        <link>https://medium.com/@antvick?source=rss-2fbd7237ffac------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*T1Ptxx5FmNrKRo1oRQsXXQ.jpeg</url>
            <title>Stories by Anthony Vickers on Medium</title>
            <link>https://medium.com/@antvick?source=rss-2fbd7237ffac------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 05:08:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@antvick/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A builder approach to cloud configuration using Terraform 0.13]]></title>
            <link>https://medium.com/panaseer-labs-engineering-data-science/a-builder-approach-to-cloud-configuration-using-terraform-0-13-fcd02df05773?source=rss-2fbd7237ffac------2</link>
            <guid isPermaLink="false">https://medium.com/p/fcd02df05773</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[dont-repeat-yourself]]></category>
            <category><![CDATA[terragrunt]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Anthony Vickers]]></dc:creator>
            <pubDate>Fri, 18 Sep 2020 14:20:52 GMT</pubDate>
            <atom:updated>2020-09-18T14:20:52.819Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LhaWKPuCLbiwv5Hn0A4ogw.jpeg" /></figure><p>Hi, I’m Anthony. I work in the DevOps team at Panaseer. In this blog I’ll discuss how I’ve overcome the common challenge of maintaining lots of Terraform configuration to administer a vast multi-account public cloud estate. To solve this issue, I constructed a builder Terraform module that describes some common desired functionality across many AWS regions and accounts. Modules within this builder module can be dynamically installed depending on the business requirements of the region and account using a new Terraform 0.13 feature. This process has increased automation and reduced the operations overhead within the DevOps team and improves confidence in security operating in the cloud. Using this new approach, the number of files in our code base to maintain a single account has reduced by over ~80%. Read on to find out more.</p><h3>Keeping our code DRY</h3><p>The Panaseer product is hosted using a multi-account, multi-region AWS cloud architecture to provide high guarantees of data separation between customers. This presents the challenge of ensuring that each cloud environment has a consistent configuration of infrastructure alongside a standardised and comprehensive suite of security features. Our software configuration is expressed using a selection of well scoped Terraform modules and deployment is abstracted across each account using Terragrunt.</p><p>It has been possible to keep our codebase reasonably DRY (dont’ repeat yourself) by implementing our code structure following <a href="https://blog.gruntwork.io/terragrunt-how-to-keep-your-terraform-code-dry-and-maintainable-f61ae06959d8">Terragrunt’s suggested approach</a>. However, the declarative nature of having to create a Terragrunt configuration file for each desired module on a per region, per account basis where we want the infrastructure deployed creates the opportunity for error and an increasing maintenance overhead as the solution scales with the number of accounts under management.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tBCdzxUtNcvr7eiWJLmUSg.png" /><figcaption>A DRY (don’t repeat yourself) approach to Terraform code</figcaption></figure><p>As an example, imagine a situation in which you have 100 production accounts each needing the installation of a new Terraform module in two AWS regions. To achieve this with the standard approach would require 200 new Terragrunt configuration files. Then you require a further Terraform module in a particular region across the same 100 accounts which means another 100 files to commit. And so on. Not only do you have at least 300 files to maintain but now you also have to remember some business logic around why particular modules are installed in some regions and not others. Nightmare.</p><p>We had too many files similar to this in our infrastructure git repo:</p><pre>## terragrunt.hcl<br>terraform {<br>  source = &quot;<a href="/service/mailto:git@github.com">git@github.com</a>:Panaseer/repo.git//modules/module?ref=v0.0.1&quot;<br>}<br>include {<br>  path = find_in_parent_folders()<br>}<br>inputs = merge(<br>  {<br>    &quot;this_region&quot;: &quot;us-east-1&quot;<br>  }<br>)</pre><p>At Panaseer we decided to try things a bit differently. Terraform’s eagerly anticipated version 0.13 release contains a new feature which we found particularly exciting: the for_each attribute on a module. Instead of installing a module in a declarative way (i.e. write a Terragrunt file when we want it), the for_eachattribute can be used to setup a procedural evaluation where logic is used to express whether a given module is enabled in a region or not.</p><h3>How we implemented a feature-flag approach to manage modules dynamically</h3><p>First, we assembled all our common Terraform modules that described potential desired functionality into a new main.tf with all the required providers and variable declarations. Using Terraform 0.13 a for_each argument was added to each Terraform module which allows it to be switch on and off dynamically:</p><pre>## main.tf</pre><pre>##<br># Modules<br>##</pre><pre>module &quot;aws_config&quot; {<br>  providers = {<br>    aws = aws.aws_config<br>  }<br>  for_each = var.aws_config_enabled == tobool(true) ? { RegionEnabled = &quot;True&quot; } : {}<br>  source   = &quot;<a href="/service/mailto:git@github.com">git@github.com</a>:Panaseer/repo.git//modules/aws_config?ref=v0.0.1&quot;<br>}</pre><pre>module &quot;aws_config_aggregator&quot; {<br>  providers = {<br>    aws = aws.aws_config_aggregator<br>}<br>  for_each = var.aws_config_aggregator_enabled == tobool(true) ? { RegionEnabled = &quot;True&quot; } : {}<br>  source   = &quot;<a href="/service/mailto:git@github.com">git@github.com</a>:Panaseer/repo.git//modules/aws_config_aggregator?ref=v0.0.1&quot;<br>}</pre><pre>module &quot;guard_duty&quot; {<br>  providers = {<br>    aws = aws.guard_duty<br>  }<br>  for_each = var.guard_duty_enabled == tobool(true) ? { RegionEnabled = &quot;True&quot; } : {}<br>  source   = &quot;<a href="/service/mailto:git@github.com">git@github.com</a>:Panaseer/repo.git//modules/guard_duty?ref=v0.0.1&quot;<br>}</pre><pre>module &quot;cloudtrail&quot; {<br>  providers = {<br>    aws = aws.cloudtrail<br>  }<br>  for_each = var.cloudtrail_enabled == tobool(true) ? { RegionEnabled = &quot;True&quot; } : {}<br> source   = &quot;<a href="/service/mailto:git@github.com">git@github.com</a>:Panaseer/repo.git//modules/cloudtrail?ref=v0.0.1&quot;<br>}</pre><pre>##<br># Variables<br>##</pre><pre>variable aws_config_enabled {<br>  type    = bool<br>  default = true<br>}</pre><pre>variable aws_config_aggregator_enabled {<br>  type    = bool<br>  default = false<br>}</pre><pre>variable guard_duty_enabled {<br>  type    = bool<br>  default = true<br>}</pre><pre>variable cloudtrail_enabled {<br>  type    = bool<br>  default = false<br>}</pre><p>This new main.tf has become a region “builder” module, allowing for the declaration of complex, repeatable infrastructure for our product with minimal code. In the example above, default values for enabling a module are set for all modules which are can have overrides when necessary in each environment. In practice, the greatest benefit of this approach is realised when there are many common modules that need to be enabled by default.</p><p>Next, we created a Terragrunt configuration file for an AWS region which consumes this new builder Terraform module instead of multiple configuration files which each consume and instantiate single Terraform modules:</p><pre>## terragrunt.hcl</pre><pre>terraform {<br>  source = &quot;<a href="/service/mailto:git@github.com">git@github.com</a>:Panaseer/repo.git//modules/builder?ref=v0.0.1&quot;<br>}</pre><pre>include {<br>  path = find_in_parent_folders()<br>}</pre><pre>inputs = merge(<br>  {<br>    &quot;this_region&quot;: &quot;eu-west-1&quot;,<br>    &quot;aws_config_aggregator&quot;: &quot;true&quot;<br>  }<br>)</pre><p>Variables are merged as inputs to Terragrunt to enable and disable the desired functionality for an AWS region. In this example, the AWS Config aggregator module has been enabled for this specific region and will be installed. The AWS Config and Guard Duty modules are already enabled by default in the builder module and will be installed. The Cloudtrail module has not been enabled and will not be installed.</p><p>In this example, the number of Terragrunt configuration files is reduced from three to one per region, per account when using the builder approach versus the standard method. If the Cloudtrail module is also required, the reduction is four files to one per region, per account. The result is a Terragrunt configuration file per region rather than per app, per region which lean whilst maintaining the flexibility to choose which modules to install:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YU4S3vfcLx2SQq7MPlF7Cw.png" /><figcaption>A very DRY (don’t repeat yourself) approach to Terraform code</figcaption></figure><p>The benefits of Panaseer’s approach are significant if you have adopted the recommended standard practice of keeping your infrastructure packaged up into small units and have many common modules to deploy across many accounts. At Panaseer, we accepted <a href="https://blog.gruntwork.io/terragrunt-how-to-keep-your-terraform-code-dry-and-maintainable-f61ae06959d8">the well-documented trade-offs</a> of this approach versus the standard practice. Panaseer’s approach is similar to adding a dependencies configuration block in a terragrunt.hcl file however it’s more versatile for standardising configuration across multiple regions and accounts as you don’t have to maintain a dependencies block in each file and the modules may not necessarily be dependent which is misleading.</p><p>In Panaseer’s implementation of this code architecture, default values for enabling modules across all customers are set in a common properties default_modules.json file which is loaded into Terragrunt across multiple regions and multiple accounts:</p><pre>inputs = merge(<br>  jsondecode(file(find_in_parent_folders(&quot;default_modules.json&quot;))),<br>  {<br>      &quot;this_region&quot;: &quot;eu-west-1&quot;,<br>      &quot;aws_config_aggregator&quot;: &quot;true&quot;<br>  }<br>)</pre><p>The result of this is that we never have to remember to install a security module in a region for a customer, it’s done automatically. The values can also be overridden on an account or region basis if we wish. All core security modules required in an account, such as Guard duty and Inspector, are installed by default which improves confidence in our cloud security, removes scope for errors, increases automation and reduces operational costs.</p><h3>Thanks for reading!</h3><p>I hope that you find this useful, please get in touch with any queries in the comments below or you can reach out to us on Twitter <a href="http://twitter.com/panaseer_team">@panaseer_team</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fcd02df05773" width="1" height="1" alt=""><hr><p><a href="https://medium.com/panaseer-labs-engineering-data-science/a-builder-approach-to-cloud-configuration-using-terraform-0-13-fcd02df05773">A builder approach to cloud configuration using Terraform 0.13</a> was originally published in <a href="https://medium.com/panaseer-labs-engineering-data-science">Panaseer Labs Engineering &amp; Data Science</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>