<?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"><channel><title><![CDATA[Orim Dominic]]></title><description><![CDATA[Orim Dominic]]></description><link>https://orimdominic.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 25 Sep 2026 12:17:32 GMT</lastBuildDate><atom:link href="https://orimdominic.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Ibadan Hashicorp User Group - Challenge I]]></title><description><![CDATA[This article is part of the fulfillment of Challenge I of the Ibadan Hashicorp User Group’s 6 Weeks Terraform Challenge (Cohort 3). The cohort teaches us about Infrastructure as Code (IaC) and how to use Terraform through hands-on projects.
A Descrip...]]></description><link>https://orimdominic.hashnode.dev/ibadan-hashicorp-user-group-challenge-i</link><guid isPermaLink="true">https://orimdominic.hashnode.dev/ibadan-hashicorp-user-group-challenge-i</guid><category><![CDATA[Terraform]]></category><category><![CDATA[Netlify]]></category><category><![CDATA[#IaC]]></category><category><![CDATA[Devops]]></category><dc:creator><![CDATA[Orim Dominic Adah]]></dc:creator><pubDate>Thu, 21 Aug 2025 18:33:35 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1755793867708/67e9d2fa-1c59-4400-9506-62fad14d9081.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This article is part of the fulfillment of Challenge I of the <a target="_blank" href="https://www.linkedin.com/company/hashicorp-user-group-ibadan">Ibadan Hashicorp User Group</a>’s 6 Weeks Terraform Challenge (Cohort 3). The cohort teaches us about Infrastructure as Code (IaC) and how to use Terraform through hands-on projects.</p>
<h2 id="heading-a-description-of-the-challenge">A Description of the Challenge</h2>
<p>Build and deploy a simple static website on Netlify using Terraform while managing your Terraform state securely in Terraform Cloud. The project should be small, creative, reproducible and well-documented.</p>
<h2 id="heading-integrating-netlify-with-hashicorp-cloud-platform-terraform">Integrating Netlify with Hashicorp Cloud Platform Terraform</h2>
<p>I <a target="_blank" href="https://developer.hashicorp.com/sign-up">created an account on HCP</a> and created an organisation on my account to create projects and workspaces. I installed the <a target="_blank" href="https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli">Terraform CLI</a> and <a target="_blank" href="https://developer.hashicorp.com/terraform/tutorials/cloud-get-started/cloud-login">logged into my HCP account</a> through it to enable me to run Terraform commands to make changes in my HCP account.</p>
<p>I already have a Netlify account and a GitHub account which are necessary for this exercise. I generated a <a target="_blank" href="https://docs.netlify.com/api-and-cli-guides/cli-guides/get-started-with-cli/#obtain-a-token-in-the-netlify-ui">Netlify personal access token</a> and a <a target="_blank" href="https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic">GitHub developer token</a> for the repository on GitHub for the configuration of the Terraform providers I used in this exercise. These tokens were stored in my workspace environment on HCP.</p>
<h2 id="heading-setting-up-the-project">Setting Up the Project</h2>
<h3 id="heading-the-static-website">The Static Website</h3>
<p>I created a folder for the project and in a subfolder called <code>app</code>, I created the website locally using <a target="_blank" href="https://vite.dev/">Vite</a>. I created two environment variables in a git-ignored <code>.env</code> file in <code>app</code> - <code>VITE_CONTENT</code> and <code>VITE_TITLE</code>; both are strings. Both variables are to be configured via the Terraform setup when deployed and they will be used to display randomised content on the deployed website.</p>
<h3 id="heading-terraformtf">terraform.tf</h3>
<p>In the root folder of the project, I created a <code>terraform.tf</code> file in which I set up the Terraform cloud block with my HCP account details (organisation, workspace and project names). I also set up the required providers for the project in it. I used a combination of four Terraform providers:</p>
<ul>
<li><p><a target="_blank" href="https://registry.terraform.io/providers/hashicorp/random/">hashicorp/random v3.5</a></p>
</li>
<li><p><a target="_blank" href="https://registry.terraform.io/providers/AegirHealth/netlify/">AegirHealth/netlify v0.6.12</a></p>
</li>
<li><p><a target="_blank" href="https://registry.terraform.io/providers/integrations/githubhttps://registry.terraform.io/providers/integrations/github">integrations/github v6.0</a></p>
</li>
<li><p><a target="_blank" href="https://registry.terraform.io/providers/netlify/netlify/">netlify/netlify v0.2.3</a></p>
</li>
</ul>
<p>I used the <code>hashicorp/random</code> provider to generate random strings for the Netlify project name’s suffix and the values of the environment variables.</p>
<p>The official Terraform Netlify provider - <code>netlify/netlify</code>, does not support creating projects on Netlify accounts from GitHub repositories using Terraform. To overcome the hurdle, I used <code>AegirHealth/netlify</code> and <code>integrations/github</code> together to create the project on my Netlify account via HCP Terraform, hence it is essential that the project must be hosted on GitHub first before the <code>terraform apply</code> command is used. <code>AegirHealth/netlify</code> requires the hosted repository details in one of its resource configurations.</p>
<p>I used <code>netlify/netlify</code> to set the <code>VITE_CONTENT</code> and <code>VITE_TITLE</code> environment variables on Netlify for the website.</p>
<h3 id="heading-outputstf">outputs.tf</h3>
<p>I wanted to make sure that the deployed name of the site on Netlify is what is displayed on the terminal, not the one generated from the infrastructure configuration. To achieve that, I used <code>netlify/netlify</code>’s <code>data "netlify_site"</code> block to fetch the name of the deployed site to be used in <code>outputs.tf</code>.</p>
<h3 id="heading-providerstf-and-variablestf">providers.tf and variables.tf</h3>
<p>In <code>providers.tf</code>, I provided the necessary configuration tokens via variables from <code>variables.tf</code> to configure the providers. The values of these variables are stored in my HCP account workspace environment variables (remotely) and the <code>terraform.tfvars</code> locally.</p>
<h3 id="heading-maintf">main.tf</h3>
<p><code>main.tf</code> contains configurations for</p>
<ul>
<li><p>Generating random strings using the <code>hashicorp/random</code> provider</p>
</li>
<li><p>Setting the environment variables on Netlify using <code>netlify/netlify</code></p>
</li>
<li><p>Defining or creating the site using <code>AegirHealth/netlify</code> and <code>integrations/github</code></p>
</li>
</ul>
<h2 id="heading-deployment">Deployment</h2>
<p>Before running the Terraform CLI commands, I pushed the repository to GitHub for access by <code>AegirHealth/netlify</code>.</p>
<p>I ran the following commands in order:</p>
<ul>
<li><p><code>terraform init</code> - to initialise the project and install provider dependencies</p>
</li>
<li><p><code>terraform validate</code> - to validate the configuration. I corrected errors wherever they were found</p>
</li>
<li><p><code>terraform plan</code> - to preview the changes that will be made when the infrastructure is deployed</p>
</li>
<li><p><code>terraform apply</code> - to deploy the infrastructure configuration</p>
</li>
</ul>
<h2 id="heading-the-result">The Result</h2>
<p>The screenshot below is an image of the terminal on a successful run of the <code>terraform apply</code> command.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1755798259550/41e7e83a-3cf4-4ddd-b9bc-0502b8b29904.png" alt="Screenshot of successful Terraform Netlify deployment" class="image--center mx-auto" /></p>
<p>You can find the GitHub repository for my solution at <a target="_blank" href="https://github.com/orimdominic/terraform-netlify-iac">orimdominic/terraform-netlify-iac</a> and the deployed website at <a target="_blank" href="https://ibadan-hug-nlfy-tf-vezhpa.netlify.app/">https://ibadan-hug-nlfy-tf-vezhpa.netlify.app/</a></p>
<h2 id="heading-what-makes-my-approach-unique">What Makes my Approach Unique?</h2>
<p>My approach ensures that with the Terraform infrastructure configuration, you only need to</p>
<ul>
<li><p>Set your environment variables</p>
</li>
<li><p>Push the repository to GitHub.</p>
</li>
<li><p>Run the Terraform commands</p>
</li>
</ul>
<p>to have your project deployed.You don’t need to create a project on Netlify first.</p>
<p>My approach also provides a way to configure environment variables for the project on Netlify from the Terraform infrastructure configuration. These environment variables are different and randomised for each deployment. I also display the values of the environment variables on the website.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>You can deploy static websites to Netlify using HUG Terraform without the need of use UIs. The infrastructure is also configurable.</p>
<p>Give <a target="_blank" href="https://www.linkedin.com/company/hashicorp-user-group-ibadan">Ibadan Hashicorp User Group</a> a follow on LinkedIn if you can, the organisers have been supportive. Also give <a target="_blank" href="https://github.com/orimdominic/terraform-netlify-iac">orimdominic/terraform-netlify-iac</a> a star if you find it useful.</p>
<p>You can reach out to me on <a target="_blank" href="https://linkedin.com/in/orimdominicadah">LinkedIn</a> if you have any questions or found this article useful. I’m delighted to chat with you.</p>
]]></content:encoded></item></channel></rss>