<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Terraform on Mike Bell - Blog &amp; Stuff</title><link>https://mikebell.io/tags/terraform/</link><description>Recent content in Terraform on Mike Bell - Blog &amp; Stuff</description><generator>Hugo -- gohugo.io</generator><language>en</language><managingEditor>hello@mikebell.io (Mike Bell)</managingEditor><webMaster>hello@mikebell.io (Mike Bell)</webMaster><copyright>© 2026 Mike Bell</copyright><lastBuildDate>Tue, 16 Jan 2024 20:00:00 +0000</lastBuildDate><atom:link href="https://mikebell.io/tags/terraform/index.xml" rel="self" type="application/rss+xml"/><item><title>Terraforming AWS</title><link>https://mikebell.io/posts/2024-01-16-terraforming-aws/</link><pubDate>Tue, 16 Jan 2024 20:00:00 +0000</pubDate><author>hello@mikebell.io (Mike Bell)</author><guid>https://mikebell.io/posts/2024-01-16-terraforming-aws/</guid><description>
&lt;p>I&amp;rsquo;ve had my personal AWS setup for 10 years now and it&amp;rsquo;s time that it got organised. I&amp;rsquo;ve made previous attempts at this using Terraformer but it&amp;rsquo;s output wasn&amp;rsquo;t structure enough for my liking.&lt;/p>
&lt;p>TLDR; template code can be found &lt;a
href="https://github.com/mikebell-dev/tf-template"
target="_blank"
>here&lt;/a>.&lt;/p>
&lt;p>This time round I&amp;rsquo;ve decided to split it up into two components:&lt;/p>
&lt;ul>
&lt;li>Base&lt;/li>
&lt;li>Applications&lt;/li>
&lt;/ul>
&lt;h2 class="relative group">Terraform style guide
&lt;div id="terraform-style-guide" class="anchor">&lt;/div>
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100">
&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700 !no-underline" href="#terraform-style-guide" aria-label="Anchor">#&lt;/a>
&lt;/span>
&lt;/h2>
&lt;p>I have a few rules that my TF repos need to follow:&lt;/p>
&lt;ol>
&lt;li>Must have a &lt;code>readme.md&lt;/code>&lt;/li>
&lt;li>Terraform files must be stored in a &lt;code>terraform&lt;/code> directory (application code can live outside)&lt;/li>
&lt;li>&lt;code>main.tf&lt;/code> must be lean and not contain any resources&lt;/li>
&lt;li>Terraform files must be named after the AWS resource&lt;/li>
&lt;li>Must pin terraform version&lt;/li>
&lt;li>Must include github workflows for gitops&lt;/li>
&lt;/ol>
&lt;h2 class="relative group">Base Terraform
&lt;div id="base-terraform" class="anchor">&lt;/div>
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100">
&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700 !no-underline" href="#base-terraform" aria-label="Anchor">#&lt;/a>
&lt;/span>
&lt;/h2>
&lt;p>This contains all the base terraform code that doesn&amp;rsquo;t belong in an application, things like s3/dynamodb for terraform (applications use this) and IAM roles for Github OIDC.&lt;/p>
&lt;pre tabindex="0">&lt;code>-&amp;gt; % tree -a
.
├── .github
│   └── workflows
│   ├── pr-apply.yml
│   └── pr-plan.yml
├── .gitignore
├── readme.md
└── terraform
├── dynamodb.tf
├── iam.tf
├── main.tf
├── s3.tf
├── .terraform.lock.hcl
└── .terraform-version
&lt;/code>&lt;/pre>
&lt;h1 class="relative group">Application Terraform
&lt;div id="application-terraform" class="anchor">&lt;/div>
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100">
&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700 !no-underline" href="#application-terraform" aria-label="Anchor">#&lt;/a>
&lt;/span>
&lt;/h1>
&lt;p>Applications are usually a group of resources that do a related set of &lt;em>things&lt;/em>. In my case it&amp;rsquo;s domains which I use to group these resources into an &amp;ldquo;application&amp;rdquo;&lt;/p>
&lt;pre tabindex="0">&lt;code>-&amp;gt; % tree -a
.
├── .github
│   └── workflows
│   ├── pr-apply.yml
│   └── pr-plan.yml
├── .gitignore
├── readme.md
└── terraform
├── acm.tf
├── cloudfront.tf
├── main.tf
├── providers.tf
├── route53.tf
├── s3.tf
├── .terraform.lock.hcl
└── .terraform-version
&lt;/code>&lt;/pre>
&lt;h2 class="relative group">Github Actions
&lt;div id="github-actions" class="anchor">&lt;/div>
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100">
&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700 !no-underline" href="#github-actions" aria-label="Anchor">#&lt;/a>
&lt;/span>
&lt;/h2>
&lt;p>Each application repo has two Github Actions repos by default, the first runs &lt;code>terraform plan&lt;/code> when a pull request is raised. The second is a &lt;code>terraform apply&lt;/code> when a PR is merged into &lt;code>main&lt;/code>. General rule of thumb is to never run terraform locally and every change has to be done through a PR. Depending on the size and urgency of the change sometimes it&amp;rsquo;s just easier to run it locally, majority of the time it&amp;rsquo;s through PRs.&lt;/p>
&lt;h2 class="relative group">Readme.md
&lt;div id="readmemd" class="anchor">&lt;/div>
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100">
&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700 !no-underline" href="#readmemd" aria-label="Anchor">#&lt;/a>
&lt;/span>
&lt;/h2>
&lt;p>@TODO I want to automate this, some sort of tool that runs through each tf file and outputs each resource into a table. This sounds like a great time to learn Go.&lt;/p>
&lt;h2 class="relative group">.terraform-version
&lt;div id="terraform-version" class="anchor">&lt;/div>
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100">
&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700 !no-underline" href="#terraform-version" aria-label="Anchor">#&lt;/a>
&lt;/span>
&lt;/h2>
&lt;p>This is used by &lt;code>tfenv&lt;/code> making sure that I&amp;rsquo;m always running the same version regardless of the environment. I want to look into this further and potentially remove it. ASDF looks interesting for sure.&lt;/p>
&lt;h1 class="relative group">Conclusion
&lt;div id="conclusion" class="anchor">&lt;/div>
&lt;span
class="absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100">
&lt;a class="group-hover:text-primary-300 dark:group-hover:text-neutral-700 !no-underline" href="#conclusion" aria-label="Anchor">#&lt;/a>
&lt;/span>
&lt;/h1>
&lt;p>That&amp;rsquo;s about it for my own personal setup, I&amp;rsquo;ve borrowed a lot from various setups I&amp;rsquo;ve work on over the past couple of years so can&amp;rsquo;t take all the credit for it. Overall I&amp;rsquo;ve migrated around 30% of my applications to this setup, more to come. A basic template of this can be found &lt;a
href="https://github.com/mikebell-dev/tf-template"
target="_blank"
>here&lt;/a>.&lt;/p>
&lt;p>Thanks for reading via RSS!&lt;/p>
&lt;p>Send me a message on &lt;a href="https://remotelab.uk/mikebell">Mastodon&lt;/a> or &lt;a href="mailto:hello@mikebell.io">email me&lt;/a>&lt;/p></description></item></channel></rss>