<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jessica Aparecida Bueno</title>
    <description>The latest articles on DEV Community by Jessica Aparecida Bueno (@jessicaapbueno).</description>
    <link>https://dev.to/jessicaapbueno</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1455462%2Fb8a3ef16-4dc7-4587-ad85-80d889fce562.png</url>
      <title>DEV Community: Jessica Aparecida Bueno</title>
      <link>https://dev.to/jessicaapbueno</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jessicaapbueno"/>
    <language>en</language>
    <item>
      <title>Cloud Simplified: Hands-on DevSecOps Lab with Terraform and LocalStack</title>
      <dc:creator>Jessica Aparecida Bueno</dc:creator>
      <pubDate>Thu, 19 Mar 2026 01:54:52 +0000</pubDate>
      <link>https://dev.to/jessicaapbueno/cloud-simplified-hands-on-devsecops-lab-with-terraform-and-localstack-1k2e</link>
      <guid>https://dev.to/jessicaapbueno/cloud-simplified-hands-on-devsecops-lab-with-terraform-and-localstack-1k2e</guid>
      <description>&lt;h1&gt;
  
  
  Demystifying the Cloud: A Practical DevSecOps Lab with Terraform and LocalStack
&lt;/h1&gt;

&lt;p&gt;Imagine being able to test your entire AWS infrastructure with rigorous security validation and professional automation, without spending a single cent.&lt;/p&gt;

&lt;p&gt;In the real world, cloud mistakes are expensive. That's why simulation environments and well-structured CI/CD pipelines are "game changers" for a Cloud Engineer.&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 The Protagonist: LocalStack
&lt;/h2&gt;

&lt;p&gt;To make this zero-cost environment possible, I used &lt;strong&gt;LocalStack&lt;/strong&gt;. It is a cloud service emulator that runs in a single Docker container on your local machine or within CI/CD environments.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;How does it work?&lt;/strong&gt; LocalStack intercepts the API calls you would send to the real AWS and processes them locally. For your Terraform, it's as if it were talking to the true cloud, but the data and resources never leave your controlled environment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How to start locally?&lt;/strong&gt; If you want to run it manually on your machine for quick experiments, just run:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;localstack start &lt;span class="nt"&gt;-d&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;In this project, however, LocalStack is started automatically by the GitHub Actions pipeline&lt;/strong&gt; — you don't need to run it locally for the CI/CD flow to work. The local command above is optional, useful for manual testing before pushing.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Official Documentation:&lt;/strong&gt; To explore all supported services, you can access the &lt;a href="https://docs.localstack.cloud" rel="noopener noreferrer"&gt;LocalStack Documentation&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🌟 Overview
&lt;/h2&gt;

&lt;p&gt;This project was born from the need to unite theory and practice in a &lt;strong&gt;DevSecOps&lt;/strong&gt; scenario. The main goal isn't just to "create a resource," but to build a learning journey on how &lt;strong&gt;IaC (Infrastructure as Code)&lt;/strong&gt; and &lt;strong&gt;Automation&lt;/strong&gt; technologies integrate into the daily routine of a technology team.&lt;/p&gt;




&lt;h2&gt;
  
  
  🛡️ The "Sec" in DevSecOps: Why is this not just another automation project?
&lt;/h2&gt;

&lt;p&gt;We often hear the term &lt;strong&gt;DevOps&lt;/strong&gt;, but when we add &lt;strong&gt;Sec (Security)&lt;/strong&gt; in the middle, we are talking about a paradigm shift called &lt;strong&gt;Shift Left&lt;/strong&gt;. In practice, this means bringing security to the beginning of the development cycle rather than leaving it as a final task before deployment.&lt;/p&gt;

&lt;p&gt;In this lab, security is not optional; it is a &lt;strong&gt;structural part of the pipeline&lt;/strong&gt;. Here's how I transformed a delivery flow into a &lt;strong&gt;&lt;em&gt;secure&lt;/em&gt;&lt;/strong&gt; delivery flow:&lt;/p&gt;

&lt;h3&gt;
  
  
  Shift Left with Static Analysis (tfsec)
&lt;/h3&gt;

&lt;p&gt;Unlike a traditional flow where you would create the resource and then run a scanner, here I used &lt;strong&gt;tfsec&lt;/strong&gt; directly in GitHub Actions — running it before LocalStack even starts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The code is analyzed even before any resource is simulated or created.&lt;/li&gt;
&lt;li&gt;In this lab, &lt;code&gt;soft_fail: true&lt;/code&gt; is configured so that security warnings appear in the logs without blocking the pipeline — allowing you to observe and learn from each finding. In a real production environment, this flag would be removed, making &lt;code&gt;tfsec&lt;/code&gt; a hard gate: any critical vulnerability would immediately stop the pipeline.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Secure Infrastructure by Design (Hardening)
&lt;/h3&gt;

&lt;p&gt;The developed S3 module doesn't just focus on creating the bucket, but on its &lt;strong&gt;Hardening&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Public Access Block&lt;/strong&gt;: I implemented features that prevent the bucket from being accidentally exposed to the internet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AES256 Encryption&lt;/strong&gt;: Ensures that data at rest is always protected.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Versioning&lt;/strong&gt;: Added a recovery layer against accidental deletions or malicious attacks.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Security as a Troubleshooting Culture
&lt;/h3&gt;

&lt;p&gt;During development, the pipeline "broke" several times due to &lt;code&gt;tfsec&lt;/code&gt; alerts. In a common scenario, a developer might simply disable the scanner. Here, the approach was &lt;strong&gt;remediation&lt;/strong&gt;: understanding the pointed risk (like the lack of &lt;code&gt;public_access_block&lt;/code&gt;) and updating the code to meet market security standards.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"DevSecOps is not about tools; it's about not allowing delivery speed to compromise data integrity."&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🎯 Why this Lab?
&lt;/h2&gt;

&lt;p&gt;Often, when studying cloud, we hit the fear of costs or the complexity of setting up a pipeline from scratch. This lab was designed to be a &lt;strong&gt;safe learning environment&lt;/strong&gt;, where I applied concepts of:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Modularization&lt;/strong&gt;: How to organize files so that the code is reusable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Preventive Security (Shift Left)&lt;/strong&gt;: How to use scanning tools (tfsec) to block security errors before the resource even exists.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Local Simulation&lt;/strong&gt;: How to bypass physical and financial limitations using LocalStack to emulate complex AWS services.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  🛠️ The Tech Stack: The Automation "Engine"
&lt;/h2&gt;

&lt;p&gt;For this ecosystem to work in harmony, I selected industry-standard tools that complement each other perfectly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Terraform&lt;/strong&gt;: The choice for IaC. It allows defining infrastructure through declarative code, ensuring the environment is replicable and free from error-prone manual configurations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LocalStack&lt;/strong&gt;: Emulates a complete AWS cloud inside a Docker container on the GitHub runner, allowing testing of resources like S3 without generating real costs on the AWS account.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Actions&lt;/strong&gt;: The CI/CD engine. It orchestrates the execution of validation, security, and simulation jobs on every &lt;code&gt;git push&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;tfsec&lt;/strong&gt;: The static analysis tool that ensures the "Sec" of DevSecOps, scanning the code for insecure configurations before deployment.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  📂 Organization and Structure: Thinking at Scale
&lt;/h2&gt;

&lt;p&gt;A professional infrastructure project cannot be a "single file." The folder organization reflects the maturity of the code and facilitates maintenance by other engineers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;localstack-terraform-lab/
├── .github/workflows/
│   └── terraform.yml       # Where the automation magic happens
├── modules/
│   └── s3-bucket/          # Our reusable and secure component
│       ├── main.tf         # Security logic and S3 resources
│       └── variables.tf    # Module parameterization
├── main.tf                 # Entry point (calling modules)
├── provider.tf             # LocalStack and AWS Provider configuration
└── variables.tf            # Global project variables
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this structure, the highlight goes to the &lt;code&gt;modules/&lt;/code&gt; folder. Instead of creating the bucket directly in the root, the logic was isolated within a &lt;strong&gt;reusable module&lt;/strong&gt;. This means that if 10 more buckets are needed tomorrow, they will all strictly follow the same security standard we defined once.&lt;/p&gt;




&lt;h2&gt;
  
  
  🏗️ Dissecting the Pipeline: The &lt;code&gt;terraform.yml&lt;/code&gt; Workflow
&lt;/h2&gt;

&lt;p&gt;The heart of this automation resides in the &lt;code&gt;.github/workflows/terraform.yml&lt;/code&gt; file. It is divided into three major pillars (Jobs) that ensure project integrity.&lt;/p&gt;

&lt;h3&gt;
  
  
  Header and Trigger
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Terraform Professional CI&lt;/span&gt;
&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;push&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;name&lt;/strong&gt;: The name that will appear in the GitHub "Actions" tab. Choosing a professional name helps quickly identify the purpose of the automation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;on: [push]&lt;/strong&gt;: Defines the trigger. Every time new code is sent to the repository, the pipeline comes to life automatically.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Job 1: Check Code Quality (Validation)
&lt;/h3&gt;

&lt;p&gt;This is the first quality filter. It ensures the code is well-written before anything else happens.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;validate&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Check&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Code&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Quality"&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v4&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;hashicorp/setup-terraform@v3&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;terraform init -backend=false&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;terraform validate&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;runs-on: ubuntu-latest&lt;/strong&gt;: Tells GitHub to provision a clean Linux virtual machine to run these commands.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;actions/checkout@v4&lt;/strong&gt;: Makes the virtual machine download your code from the repository.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;terraform init -backend=false&lt;/strong&gt;: A crucial learning. Since we use local modules, Terraform needs to "install" them before validating. We use &lt;code&gt;-backend=false&lt;/code&gt; because we don't need a real cloud connection at this stage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;terraform validate&lt;/strong&gt;: The command that checks for missing brackets, typos, or incorrectly declared variables.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Job 2: Security Scan
&lt;/h3&gt;

&lt;p&gt;This is where DevOps becomes &lt;strong&gt;DevSecOps&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;  &lt;span class="na"&gt;security&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Security&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Scan"&lt;/span&gt;
    &lt;span class="na"&gt;needs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;validate&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v4&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Run tfsec&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;aquasecurity/tfsec-action@v1.0.0&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;soft_fail&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;needs: validate&lt;/strong&gt;: Creates the dependency between jobs. The Security Scan only starts if the Quality Validation passes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;aquasecurity/tfsec-action&lt;/strong&gt;: The "security inspector." It scans the code for vulnerabilities, such as S3 buckets without encryption or with public access enabled.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;soft_fail: true&lt;/strong&gt;: A deliberate choice for this lab context. It allows security warnings to appear in the logs without blocking the pipeline, so you can observe all findings and plan your remediations. &lt;strong&gt;Important&lt;/strong&gt;: in a real production pipeline, this flag should be removed — making tfsec a hard blocker that stops the pipeline on any critical finding.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Job 3: LocalStack Plan (Simulation)
&lt;/h3&gt;

&lt;p&gt;The final stage, where the infrastructure is simulated in the zero-cost cloud.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;  &lt;span class="na"&gt;terraform-plan&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;LocalStack&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;Plan"&lt;/span&gt;
    &lt;span class="na"&gt;needs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;security&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v4&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Start LocalStack&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;localstack/setup-localstack@main&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;hashicorp/setup-terraform@v3&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Terraform Init &amp;amp; Plan&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
          &lt;span class="s"&gt;terraform init&lt;/span&gt;
          &lt;span class="s"&gt;terraform plan&lt;/span&gt;
        &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;AWS_ACCESS_KEY_ID&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.AWS_ACCESS_KEY_ID }}&lt;/span&gt;
          &lt;span class="na"&gt;AWS_SECRET_ACCESS_KEY&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.AWS_SECRET_ACCESS_KEY }}&lt;/span&gt;
          &lt;span class="na"&gt;AWS_DEFAULT_REGION&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;us-east-1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;localstack/setup-localstack&lt;/strong&gt;: Starts a Docker container with LocalStack, creating an AWS simulator inside the GitHub runner.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;terraform plan&lt;/strong&gt;: Generates the execution plan, showing exactly what would be created in real AWS.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;env &amp;amp; secrets&lt;/strong&gt;: Uses GitHub &lt;strong&gt;Repository Secrets&lt;/strong&gt; to inject credentials safely, simulating exactly how you would protect access keys in a real production project.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  📦 Hands-on: Building a Secure S3 Module
&lt;/h2&gt;

&lt;p&gt;To keep the project organized and scalable, I developed an &lt;strong&gt;isolated module&lt;/strong&gt; for S3. My intention was to create a security standard I could replicate in any other project. Here is the &lt;code&gt;main.tf&lt;/code&gt; of the module, block by block:&lt;/p&gt;

&lt;h3&gt;
  
  
  The Base Resource
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_s3_bucket"&lt;/span&gt; &lt;span class="s2"&gt;"this"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;bucket&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bucket_name&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is where the bucket itself is defined. I used a variable (&lt;code&gt;var.bucket_name&lt;/code&gt;) to make the module flexible, allowing different names to be set without changing the module's internal security logic.&lt;/p&gt;

&lt;h3&gt;
  
  
  Public Access Block (The "Vault Lock")
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_s3_bucket_public_access_block"&lt;/span&gt; &lt;span class="s2"&gt;"this"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;bucket&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;aws_s3_bucket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;

  &lt;span class="nx"&gt;block_public_acls&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="nx"&gt;block_public_policy&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="nx"&gt;ignore_public_acls&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="nx"&gt;restrict_public_buckets&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Four security locks that ensure that even if someone tries to change permissions manually, the bucket will remain private — preventing sensitive data from being accidentally exposed on the internet.&lt;/p&gt;

&lt;h3&gt;
  
  
  Versioning
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_s3_bucket_versioning"&lt;/span&gt; &lt;span class="s2"&gt;"this"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;bucket&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;aws_s3_bucket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
  &lt;span class="nx"&gt;versioning_configuration&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;status&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Enabled"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With versioning enabled, it's possible to recover previous versions of deleted or accidentally modified files. It's an essential protection layer against human error or ransomware attacks.&lt;/p&gt;

&lt;h3&gt;
  
  
  Encryption at Rest
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"aws_s3_bucket_server_side_encryption_configuration"&lt;/span&gt; &lt;span class="s2"&gt;"this"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;bucket&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;aws_s3_bucket&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;

  &lt;span class="nx"&gt;rule&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;apply_server_side_encryption_by_default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;sse_algorithm&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"AES256"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This block was added to address the security findings identified by &lt;strong&gt;tfsec&lt;/strong&gt; during the CI/CD pipeline execution. AES256 encryption ensures that all files stored on disk (or simulated in LocalStack) are protected by default.&lt;/p&gt;




&lt;h2&gt;
  
  
  📥 Flexibility with &lt;code&gt;variables.tf&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;To avoid a "hardcoded" project, I followed one of Terraform's golden rules: &lt;strong&gt;never leave fixed values in the middle of the code&lt;/strong&gt;. Think of variables as function parameters — they allow you to use the same module to create different buckets just by changing the name at the "entry point," without touching the security logic you already validated.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"bucket_name"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Unique name of the S3 bucket"&lt;/span&gt;
  &lt;span class="nx"&gt;type&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Description (Living Documentation)&lt;/strong&gt;: In a real team scenario, this avoids any doubt about what that field expects to receive — for other engineers and for your future self.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Type Constraint (Type Safety)&lt;/strong&gt;: By defining the type as &lt;code&gt;string&lt;/code&gt;, Terraform validates the input. If a list or number is accidentally passed, Terraform warns you immediately, preventing strange errors during deployment.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"Working with variables is what separates a simple script from professional, scalable infrastructure."&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🏗️ The Command Center: Root Files
&lt;/h2&gt;

&lt;p&gt;With the security modules properly built and "locked," it was time to organize the &lt;strong&gt;Command Center&lt;/strong&gt; of the project: the root folder. This is where the pieces connect to LocalStack. Separating the files into &lt;code&gt;provider.tf&lt;/code&gt;, &lt;code&gt;main.tf&lt;/code&gt;, and &lt;code&gt;variables.tf&lt;/code&gt; ensures that each one has a single responsibility, avoiding the hard-to-maintain "monolith."&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;provider.tf&lt;/code&gt;: The Bridge and the Security Lock
&lt;/h3&gt;

&lt;h4&gt;
  
  
  The Terraform Block: Ensuring the Correct Version
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;terraform&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;required_providers&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;aws&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;source&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"hashicorp/aws"&lt;/span&gt;
      &lt;span class="nx"&gt;version&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"~&amp;gt; 5.0"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why this?&lt;/strong&gt; During testing, I noticed that the more recent versions (v6.x) of the AWS Provider had protocol XML errors when talking to LocalStack v4. By pinning the version to &lt;code&gt;~&amp;gt; 5.0&lt;/code&gt;, I ensured stability and avoided the &lt;strong&gt;MalformedXML&lt;/strong&gt; error.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Provider Block: Pointing to LocalStack
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;provider&lt;/span&gt; &lt;span class="s2"&gt;"aws"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;region&lt;/span&gt;                      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"us-east-1"&lt;/span&gt;
  &lt;span class="nx"&gt;access_key&lt;/span&gt;                  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"test"&lt;/span&gt;
  &lt;span class="nx"&gt;secret_key&lt;/span&gt;                  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"test"&lt;/span&gt;
  &lt;span class="nx"&gt;s3_use_path_style&lt;/span&gt;           &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="nx"&gt;skip_credentials_validation&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="nx"&gt;skip_metadata_api_check&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="nx"&gt;skip_requesting_account_id&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;

  &lt;span class="nx"&gt;endpoints&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;s3&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"http://localhost:4566"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Skip configurations&lt;/strong&gt;: These flags (&lt;code&gt;skip_credentials_validation&lt;/code&gt;, &lt;code&gt;skip_metadata_api_check&lt;/code&gt;, &lt;code&gt;skip_requesting_account_id&lt;/code&gt;) are &lt;strong&gt;specific to the LocalStack test environment&lt;/strong&gt;. They tell Terraform not to try validating the &lt;code&gt;"test"&lt;/code&gt; keys against real AWS servers. &lt;strong&gt;Never use these settings in a real production provider configuration.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Path Style&lt;/strong&gt;: &lt;code&gt;s3_use_path_style = true&lt;/code&gt; because LocalStack handles this URL format for buckets better than the subdomain format used in real cloud.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Endpoints&lt;/strong&gt;: The most important line — it redirects all S3 traffic to &lt;code&gt;localhost:4566&lt;/code&gt;, where LocalStack is listening.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  🔐 What About Secrets?
&lt;/h3&gt;

&lt;p&gt;Although the code uses &lt;code&gt;"test"&lt;/code&gt; keys (which LocalStack accepts by default), I took care to configure &lt;strong&gt;GitHub Secrets&lt;/strong&gt; in my CI/CD pipeline. This means the real access values are never exposed in the code — they are injected via environment variables, simulating exactly how you would protect access keys for a real AWS account.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;main.tf&lt;/code&gt;: The Conductor
&lt;/h3&gt;

&lt;p&gt;If the modules are the musicians, the root &lt;code&gt;main.tf&lt;/code&gt; is the conductor. It doesn't create the bucket by itself; it &lt;strong&gt;calls&lt;/strong&gt; the module I developed and passes the necessary instructions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;module&lt;/span&gt; &lt;span class="s2"&gt;"my_bucket"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;source&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"./modules/s3-bucket"&lt;/span&gt;
  &lt;span class="nx"&gt;bucket_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bucket_name&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;source&lt;/strong&gt;: Points to the path of the module folder.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Variable passing&lt;/strong&gt;: The global variable &lt;code&gt;bucket_name&lt;/code&gt; is passed directly into the module's &lt;code&gt;bucket_name&lt;/code&gt; input, creating a clean and consistent hierarchy.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;variables.tf&lt;/code&gt;: The Global Control Panel
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight terraform"&gt;&lt;code&gt;&lt;span class="k"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"bucket_name"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Bucket name defined at the root level"&lt;/span&gt;
  &lt;span class="nx"&gt;default&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"my-devsecops-study-bucket"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This file at the root concentrates all definitions that might change from one environment to another, acting as the project's central control panel.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔗 How Does It All Connect?
&lt;/h2&gt;

&lt;p&gt;Unlike a manual process where you would run commands one by one in your terminal, the intelligence here lies in the &lt;strong&gt;automation&lt;/strong&gt;. The flow works like a synchronized gear every time I perform a &lt;code&gt;git push&lt;/code&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The Trigger&lt;/strong&gt;: The moment I send my code to GitHub, the CI/CD pipeline identifies the change and starts the jobs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Inspection&lt;/strong&gt;: Before even thinking about creating the bucket, GitHub Actions runs the validation and security scan. If there's an error in the S3 module or an exposed bucket, the pipeline stops here, protecting the environment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scenario Building&lt;/strong&gt;: Once security gives the green light, GitHub starts a &lt;strong&gt;LocalStack&lt;/strong&gt; container within the execution environment itself.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Silent Connection&lt;/strong&gt;: The &lt;code&gt;provider.tf&lt;/code&gt; file acts as a GPS, guiding Terraform to the local container using the credentials configured in the repository &lt;strong&gt;Secrets&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Plan Delivery&lt;/strong&gt;: The global &lt;code&gt;main.tf&lt;/code&gt; calls the S3 module, injects the name defined in &lt;code&gt;variables.tf&lt;/code&gt;, and Terraform generates the final &lt;strong&gt;Plan&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyqnfbo55l2owt6op1wli.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyqnfbo55l2owt6op1wli.png" alt="Pipeline flow diagram" width="784" height="253"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This structure allows me to test different configurations simply by changing the code and pushing to the repository — with agility and the confidence that the infrastructure is &lt;strong&gt;secure by design&lt;/strong&gt; and automatically validated.&lt;/p&gt;




&lt;h2&gt;
  
  
  🏁 Conclusion: What Do I Take from This Lab?
&lt;/h2&gt;

&lt;p&gt;Finishing this project brought me much greater clarity on the role of automation for a Cloud Engineer. More than just writing &lt;code&gt;.tf&lt;/code&gt; files, I understood that true excellence lies in creating processes that are &lt;strong&gt;secure, repeatable, and cost-efficient&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My biggest lessons:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Security is not the end, it's the beginning&lt;/strong&gt;: Implementing &lt;code&gt;tfsec&lt;/code&gt; taught me that "Shift Left" isn't just a buzzword; it saved me time and prevented vulnerable infrastructure from ever being deployed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Troubleshooting is part of learning&lt;/strong&gt;: Solving the &lt;strong&gt;MalformedXML&lt;/strong&gt; error by adjusting the AWS Provider v5.x versions and LocalStack v4 configurations gave me the confidence to handle the real-world "traps" that arise when integrating different tools.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zero Cost, Maximum Value&lt;/strong&gt;: LocalStack proved to be an indispensable ally. The freedom to fail, destroy, and rebuild a simulated environment accelerated my learning without the worry of an AWS bill at the end of the month.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The journey to the cloud is continuous, and tools like Terraform and GitHub Actions are the engines that allow me to navigate with safety and agility.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Did you like this project?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can check out the full code in my repository: &lt;a href="https://github.com/JessicaApBueno/localstack-terraform-lab" rel="noopener noreferrer"&gt;JessicaApBueno/localstack-terraform-lab&lt;/a&gt;&lt;/p&gt;

</description>
      <category>terraform</category>
      <category>devsecops</category>
      <category>localstack</category>
      <category>tfsec</category>
    </item>
  </channel>
</rss>
