<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Lab: Installing Terraform and OpenTofu on Example Academy</title><link>https://layer5io.github.io/layer5-academy/pr-preview/pr-202/learning-paths/d011fd20-a3f5-4480-883b-dfb34321d168/cloud-container-and-infrastructure/iac/lab/</link><description>Recent content in Lab: Installing Terraform and OpenTofu on Example Academy</description><generator>Hugo</generator><language>en</language><atom:link href="https://layer5io.github.io/layer5-academy/pr-preview/pr-202/learning-paths/d011fd20-a3f5-4480-883b-dfb34321d168/cloud-container-and-infrastructure/iac/lab/index.xml" rel="self" type="application/rss+xml"/><item><title>Overview</title><link>https://layer5io.github.io/layer5-academy/pr-preview/pr-202/learning-paths/d011fd20-a3f5-4480-883b-dfb34321d168/cloud-container-and-infrastructure/iac/lab/overview/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://layer5io.github.io/layer5-academy/pr-preview/pr-202/learning-paths/d011fd20-a3f5-4480-883b-dfb34321d168/cloud-container-and-infrastructure/iac/lab/overview/</guid><description>&lt;p>In this lab, you will gain hands-on experience installing Terraform - an infrastructure as code tool that enables you to safely and predictably provision and manage infrastructure in any cloud. We will provision a Google Compute Engine using Terraform and then move on to implementing OpenTofu, which is a fork of Terraform that is open source, community-driven, and managed by the Linux Foundation.&lt;/p>

&lt;h3 id="pre-requisites" class="heading-link">
 Pre-Requisites
 &lt;a href="#pre-requisites" class="heading-anchor" aria-label="Permalink to this heading">🔗&lt;/a>
&lt;/h3>
&lt;p>Ensure you have an Ubuntu 20.04 host. If not, then provision a virtual machine from Google Cloud Platform as per the lab in chapter 3.&lt;/p></description></item><item><title>Install Terraform</title><link>https://layer5io.github.io/layer5-academy/pr-preview/pr-202/learning-paths/d011fd20-a3f5-4480-883b-dfb34321d168/cloud-container-and-infrastructure/iac/lab/e1/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://layer5io.github.io/layer5-academy/pr-preview/pr-202/learning-paths/d011fd20-a3f5-4480-883b-dfb34321d168/cloud-container-and-infrastructure/iac/lab/e1/</guid><description>&lt;p>In this exercise, we will install Terraform on our Ubuntu host.&lt;/p>
&lt;ol>
&lt;li>Download the public signing key for the package repositories. To get started, execute the following commands:&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>/usr/share/keyrings/hashicorp-archive-keyring.gpg
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ol>
&lt;li>Add the appropriate apt repository:&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>echo &lt;span style="color:#e6db74">&amp;#34;deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg]
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74">https://apt.releases.hashicorp.com &lt;/span>&lt;span style="color:#66d9ef">$(&lt;/span>lsb_release -cs&lt;span style="color:#66d9ef">)&lt;/span>&lt;span style="color:#e6db74"> main&amp;#34;&lt;/span> | sudo tee
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>/etc/apt/sources.list.d/hashicorp.list
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ol>
&lt;li>Update the apt package index and install Terraform:&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>sudo apt update &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> sudo apt install terraform
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ol>
&lt;li>Verify the Terraform installation.&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>terraform --version
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Terraform v1.7.4
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>on linux_amd64
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>Set up the GCP Service Account and Configure Google Cloud SDK</title><link>https://layer5io.github.io/layer5-academy/pr-preview/pr-202/learning-paths/d011fd20-a3f5-4480-883b-dfb34321d168/cloud-container-and-infrastructure/iac/lab/e2/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://layer5io.github.io/layer5-academy/pr-preview/pr-202/learning-paths/d011fd20-a3f5-4480-883b-dfb34321d168/cloud-container-and-infrastructure/iac/lab/e2/</guid><description>&lt;p>In this exercise, we will install Google Cloud SDK, configure Google Cloud account to create a service account and use the credentials to create infrastructure using Terraform.&lt;/p>
&lt;ol>
&lt;li>Before you install the gcloud CLI, update the packages:&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>sudo apt-get update
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ol>
&lt;li>Install the curl and apt-transport-https packages:&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>sudo apt-get install apt-transport-https ca-certificates gnupg curl
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ol>
&lt;li>Import the Google Cloud public key:&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>-o /usr/share/keyrings/cloud.google.gpg
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ol>
&lt;li>Add the gcloud CLI distribution URI as a package source:&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>echo &lt;span style="color:#e6db74">&amp;#34;deb [signed-by=/usr/share/keyrings/cloud.google.gpg]
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74">https://packages.cloud.google.com/apt cloud-sdk main&amp;#34;&lt;/span> | sudo tee -a
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>/etc/apt/sources.list.d/google-cloud-sdk.list
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ol>
&lt;li>Update and install the gcloud CLI:&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>sudo apt-get update &lt;span style="color:#f92672">&amp;amp;&amp;amp;&lt;/span> sudo apt-get install google-cloud-cli
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ol>
&lt;li>After installing the SDK, initialize it by running the following command and follow the prompts:&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>gcloud init
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Welcome! This command will take you through the configuration of gcloud.
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Your current configuration has been set to: &lt;span style="color:#f92672">[&lt;/span>default&lt;span style="color:#f92672">]&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>You can skip diagnostics next time by using the following flag:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>gcloud init --skip-diagnostics
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Network diagnostic detects and fixes local network connection issues.
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Checking network connection...done.
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Reachability Check passed.
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Network diagnostic passed &lt;span style="color:#f92672">(&lt;/span>1/1 checks passed&lt;span style="color:#f92672">)&lt;/span>.
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Choose the account you would like to use to perform operations &lt;span style="color:#66d9ef">for&lt;/span> this
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>configuration:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Follow the prompts and enter your project details accordingly.
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ol>
&lt;li>Create a Service Account:&lt;/li>
&lt;/ol>
&lt;p>You&amp;rsquo;ll need to create a service account in your Google Cloud project. This service account will be used by
applications and scripts to authenticate with Google Cloud APIs.&lt;/p></description></item><item><title>Create a Google Cloud Compute Engine Instance Using Terraform</title><link>https://layer5io.github.io/layer5-academy/pr-preview/pr-202/learning-paths/d011fd20-a3f5-4480-883b-dfb34321d168/cloud-container-and-infrastructure/iac/lab/e3/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://layer5io.github.io/layer5-academy/pr-preview/pr-202/learning-paths/d011fd20-a3f5-4480-883b-dfb34321d168/cloud-container-and-infrastructure/iac/lab/e3/</guid><description>&lt;ol>
&lt;li>Create a directory to store our Terraform code:&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>mkdir -p ~/code
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ol>
&lt;li>Create a Terraform configuration file and save the file as main.tf with the following configuration:&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-hcl" data-lang="hcl">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">provider&lt;/span> &lt;span style="color:#e6db74">&amp;#34;google&amp;#34;&lt;/span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> project &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;&amp;lt;ADD YOUR PROJECT ID HERE&amp;gt;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> region &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;us-central1&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> zone &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;us-central1-a&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">resource&lt;/span> &lt;span style="color:#e6db74">&amp;#34;google_compute_instance&amp;#34; &amp;#34;my_instance&amp;#34;&lt;/span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> name &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;my-instance&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> machine_type &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;n1-standard-1&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> zone &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;us-central1-a&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">boot_disk&lt;/span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">initialize_params&lt;/span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> image &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;debian-cloud/debian-10&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">network_interface&lt;/span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> network &lt;span style="color:#f92672">=&lt;/span> &lt;span style="color:#e6db74">&amp;#34;default&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">access_config&lt;/span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#960050;background-color:#1e0010">//&lt;/span> &lt;span style="color:#66d9ef">Ephemeral&lt;/span> &lt;span style="color:#66d9ef">IP&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>Note: Replace &amp;quot; ADD YOUR PROJECT ID HERE &amp;quot; with your Google Cloud project ID. You can also customize other parameters like the instance name, machine type, zone, and image.&lt;/strong>&lt;/p></description></item><item><title>Setting up OpenTofu</title><link>https://layer5io.github.io/layer5-academy/pr-preview/pr-202/learning-paths/d011fd20-a3f5-4480-883b-dfb34321d168/cloud-container-and-infrastructure/iac/lab/e4/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://layer5io.github.io/layer5-academy/pr-preview/pr-202/learning-paths/d011fd20-a3f5-4480-883b-dfb34321d168/cloud-container-and-infrastructure/iac/lab/e4/</guid><description>&lt;p>OpenTofu is a fork of Terraform that is open source, community-driven, and managed by the Linux Foundation.
OpenTofu is an infrastructure as code tool that lets you define both cloud and on-prem resources in
human-readable configuration files that you can version, reuse, and share. You can then use a consistent workflow to provision and manage all of your infrastructure throughout its lifecycle. OpenTofu can manage low-level components like compute, storage, and networking resources, as well as high-level components like DNS entries and SaaS features.&lt;/p></description></item></channel></rss>