<?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: Jobs</title>
    <description>The latest articles on DEV Community by Jobs (@johnrobertferrer).</description>
    <link>https://dev.to/johnrobertferrer</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%2F1175061%2F23c951de-a2f5-4b3a-be4b-57749f4a8747.png</url>
      <title>DEV Community: Jobs</title>
      <link>https://dev.to/johnrobertferrer</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/johnrobertferrer"/>
    <language>en</language>
    <item>
      <title>Setting Up MongoDB Atlas Cluster and Creating VPC Peering in AWS</title>
      <dc:creator>Jobs</dc:creator>
      <pubDate>Mon, 02 Oct 2023 15:42:35 +0000</pubDate>
      <link>https://dev.to/johnrobertferrer/setting-up-mongodb-atlas-cluster-and-creating-vpc-peering-in-aws-11ba</link>
      <guid>https://dev.to/johnrobertferrer/setting-up-mongodb-atlas-cluster-and-creating-vpc-peering-in-aws-11ba</guid>
      <description>&lt;p&gt;&lt;strong&gt;MongoDB Atlas&lt;/strong&gt; is a fully managed cloud service for MongoDB. It provides a simple and cost-effective way to deploy, manage, and scale MongoDB databases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AWS Virtual Private Cloud (VPC) peering&lt;/strong&gt; allows you to connect your Atlas cluster to your VPC. This provides a private and secure connection between your Atlas cluster and your other AWS resources.&lt;/p&gt;

&lt;p&gt;In this blog post, we will show you how to set up a MongoDB Atlas cluster and create VPC peering in AWS.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Prerequisites&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Before getting started, you will need to have the following prerequisites:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An AWS account&lt;/li&gt;
&lt;li&gt;A MongoDB Atlas account&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Setting up a MongoDB Atlas cluster&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To set up a MongoDB Atlas cluster, follow these steps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Create a MongoDB Atlas Cluster&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Log in to your MongoDB Atlas account.&lt;/li&gt;
&lt;li&gt;Click on "Clusters" in the left sidebar.&lt;/li&gt;
&lt;li&gt;Click the "Build a Cluster" button to create a new cluster.&lt;/li&gt;
&lt;li&gt;Choose the M10 cluster tier, which is a recommended starting point for most use cases.&lt;/li&gt;
&lt;li&gt;Configure your cluster settings, including:

&lt;ul&gt;
&lt;li&gt;Cluster name&lt;/li&gt;
&lt;li&gt;Cloud provider (AWS)&lt;/li&gt;
&lt;li&gt;Region&lt;/li&gt;
&lt;li&gt;Cluster tier&lt;/li&gt;
&lt;li&gt;Additional settings (authentication, backup, etc.)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Click the "Create Cluster" button to initiate the cluster creation process.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZCxx9sjz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wy5bb5cjq0k3yum4fs08.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZCxx9sjz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wy5bb5cjq0k3yum4fs08.png" alt="setup-atlas-database-01" width="800" height="641"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O-CySvMH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/viu0eyquxrcre1p18ywv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O-CySvMH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/viu0eyquxrcre1p18ywv.png" alt="setup-atlas-database-02" width="800" height="734"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nuRdKdNI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c5p63o5e8vf4jjp4gr7v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nuRdKdNI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c5p63o5e8vf4jjp4gr7v.png" alt="setup-atlas-database-03" width="800" height="661"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9jeZEUHG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pp88084xfno02zl1khtx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9jeZEUHG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pp88084xfno02zl1khtx.png" alt="setup-atlas-database-04" width="800" height="599"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CYyhNkjn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/txv9c5ewaosbbsfcosmh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CYyhNkjn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/txv9c5ewaosbbsfcosmh.png" alt="setup-atlas-database-05" width="800" height="472"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z91hTEul--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gasstfqudiud8ddhks6j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z91hTEul--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gasstfqudiud8ddhks6j.png" alt="setup-atlas-database-06" width="800" height="647"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Configure Network Access&lt;/strong&gt;&lt;br&gt;
To secure your MongoDB Atlas cluster, you need to configure network access:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In the MongoDB Atlas dashboard, navigate to "Network Access" under the "Security" section.&lt;/li&gt;
&lt;li&gt;Click the "Add IP Address" button to whitelist the VPC CIDR block for secure access.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cI7zIxF2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/th75sc56p44lm6ongs43.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cI7zIxF2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/th75sc56p44lm6ongs43.png" alt="network-access-01" width="800" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Create a Peering Connection in AWS&lt;/strong&gt;&lt;br&gt;
This VPC peering allows private network communication between your resources in AWS and MongoDB Atlas cluster.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Log in to your AWS Management Console.&lt;/li&gt;
&lt;li&gt;Navigate to the Amazon VPC dashboard.&lt;/li&gt;
&lt;li&gt;In the left sidebar, click on "Peering Connections" under the "Peering" section.&lt;/li&gt;
&lt;li&gt;Click the "Create Peering Connection" button.&lt;/li&gt;
&lt;li&gt;Configure the peering connection as follows:

&lt;ul&gt;
&lt;li&gt;Peering connection options: Select "Requester" (Your AWS VPC) and "Accepter" (MongoDB Atlas).&lt;/li&gt;
&lt;li&gt;Requester VPC: Choose your AWS VPC.&lt;/li&gt;
&lt;li&gt;Accepter VPC: Choose "Another AWS account" and provide the Atlas VPC details provided in the MongoDB Atlas dashboard.&lt;/li&gt;
&lt;li&gt;Provide a unique name for the peering connection.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Click the "Create Peering Connection" button.&lt;/li&gt;
&lt;li&gt;In the peering connection details, click the "Actions" button and select "Accept Request" to approve the peering request in the MongoDB Atlas account.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WpLk3zxv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3kpnk4cmv3iojcmyhtno.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WpLk3zxv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3kpnk4cmv3iojcmyhtno.png" alt="vpc-peering-01" width="800" height="825"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WkNZVqUI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ljwmj3fqmp9em61dkwf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WkNZVqUI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ljwmj3fqmp9em61dkwf.png" alt="vpc-peering-02" width="800" height="394"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--14C3mW5n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/10kie8ybi2wkdbchbt2p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--14C3mW5n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/10kie8ybi2wkdbchbt2p.png" alt="vpc-peering-03" width="800" height="170"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7hMTBtNJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oouh22c6iqp927y476x6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7hMTBtNJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oouh22c6iqp927y476x6.png" alt="vpc-peering-04" width="800" height="179"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Configure Route Tables&lt;/strong&gt;&lt;br&gt;
To allow traffic to flow between your AWS VPC and MongoDB Atlas VPC, you need to update the route tables:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In the AWS VPC dashboard, navigate to "Route Tables."&lt;/li&gt;
&lt;li&gt;Edit the route table associated with your AWS VPC.&lt;/li&gt;
&lt;li&gt;Add a new route with the destination CIDR block of the MongoDB Atlas VPC, pointing to the peering connection as the target.&lt;/li&gt;
&lt;li&gt;Save the changes.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--p-Xal-Ms--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wctssww7tli2aj3dzisv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p-Xal-Ms--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wctssww7tli2aj3dzisv.png" alt="route-table" width="800" height="278"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Test Connectivity&lt;/strong&gt;&lt;br&gt;
To ensure that the VPC peering connection is working correctly, test the connectivity between resources in your AWS VPC and your MongoDB Atlas cluster. Created a simple Python script on AWS Lambda that uses a VPC and private subnets to test whether the resources within the VPC can reach the MongoDB Atlas production environment through VPC peering.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BKhUQf0K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aympebwlm78yjx81t0jq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BKhUQf0K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aympebwlm78yjx81t0jq.png" alt="lambda-mongodb-atlas-01" width="800" height="131"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Yp5AkBoM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/27pq49898y9bbulqwgi3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Yp5AkBoM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/27pq49898y9bbulqwgi3.png" alt="lambda-mongodb-atlas-02" width="800" height="131"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In this blog post, we have shown you how to set up a MongoDB Atlas cluster and create VPC peering in AWS. This allows you to connect your Atlas cluster to your VPC and provide a private and secure connection between your Atlas cluster and your other AWS resources.&lt;/p&gt;

</description>
      <category>mongodb</category>
      <category>aws</category>
      <category>networking</category>
      <category>devops</category>
    </item>
    <item>
      <title>Creating an EventBridge Scheduler to Trigger a Lambda Function using Terraform</title>
      <dc:creator>Jobs</dc:creator>
      <pubDate>Mon, 02 Oct 2023 15:12:13 +0000</pubDate>
      <link>https://dev.to/johnrobertferrer/creating-an-eventbridge-scheduler-to-trigger-a-lambda-function-using-terraform-59ed</link>
      <guid>https://dev.to/johnrobertferrer/creating-an-eventbridge-scheduler-to-trigger-a-lambda-function-using-terraform-59ed</guid>
      <description>&lt;p&gt;&lt;strong&gt;EventBridge&lt;/strong&gt; is a fully managed, serverless event bus service that makes it easy to connect applications together using events. It supports a broad set of event sources and targets, including AWS services, SaaS applications, and custom applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;EventBridge Scheduler&lt;/strong&gt; is a feature of EventBridge that allows you to schedule events to be delivered to targets at specific times or intervals. This makes it easy to automate tasks that need to be run on a regular basis.&lt;/p&gt;

&lt;p&gt;In this blog post, we will show you how to create an EventBridge scheduler to trigger a Lambda function using Terraform.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Prerequisites&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Before getting started, you will need to have the following prerequisites:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A Terraform installation&lt;/li&gt;
&lt;li&gt;An AWS account with the necessary permissions to create and manage AWS resources&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Creating a Terraform configuration&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The first step is to create a Terraform configuration file. This file will define the resources that you want to create, such as the EventBridge scheduler and the Lambda function.&lt;/p&gt;

&lt;p&gt;Here is a simple example of a Terraform configuration for an EventBridge scheduler to trigger a Lambda function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Lambda Function
module "lambda_function" {
  source                 = "terraform-aws-modules/lambda/aws"
  function_name          = var.function_name
  description            = var.description
  handler                = var.handler
  runtime                = var.runtime
  local_existing_package = var.local_path
  vpc_subnet_ids         = var.subnet_ids
  vpc_security_group_ids = var.security_group_ids
  attach_network_policy  = var.attach_network_policy
}

# EventBridge Scheduler
module "eventbridge" {
  source               = "terraform-aws-modules/eventbridge/aws"
  bus_name             = var.bus_name
  attach_lambda_policy = true
  lambda_target_arns   = [module.lambda_function.lambda_function_arn]
  schedules = {
    lambda-cron = {
      description         = "Run Lambda function based on given scheduled"
      schedule_expression = var.schedule_expression
      timezone            = var.timezone
      arn                 = module.lambda_function.lambda_function_arn
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This configuration will create a new EventBridge rule that is scheduled to run based on given scheduled. The rule will target the &lt;code&gt;var.lambda_function&lt;/code&gt; Lambda function.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Deploying the EventBridge scheduler&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Once you have created the Terraform configuration file, you can deploy the EventBridge scheduler by running the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;terraform apply&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will create the EventBridge rule and the Lambda function in AWS.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Testing the EventBridge scheduler&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Once the EventBridge scheduler has been deployed, you can test it to make sure that it is working properly. You can do this by waiting until the next time that the scheduler is scheduled to run and then checking to see if the Lambda function has been invoked.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CJouSKfH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1nm7jfldo6t0hqkmmy99.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CJouSKfH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1nm7jfldo6t0hqkmmy99.png" alt="eventbridge-lambda-function" width="800" height="815"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In this blog post, we have shown you how to create an EventBridge scheduler to trigger a Lambda function using Terraform. This is a powerful way to automate tasks that need to be run on a regular basis.&lt;/p&gt;

&lt;p&gt;You can also use EventBridge Scheduler to trigger other types of targets, such as Amazon Simple Notification Service (SNS) topics, Amazon Simple Queue Service (SQS) queues, and other EventBridge rules.&lt;/p&gt;

</description>
      <category>lambda</category>
      <category>aws</category>
      <category>terraform</category>
      <category>infrastructureascode</category>
    </item>
    <item>
      <title>Setting up a Web Application Firewall (WAF) using Terraform</title>
      <dc:creator>Jobs</dc:creator>
      <pubDate>Mon, 02 Oct 2023 14:51:36 +0000</pubDate>
      <link>https://dev.to/johnrobertferrer/setting-up-a-web-application-firewall-waf-using-terraform-52de</link>
      <guid>https://dev.to/johnrobertferrer/setting-up-a-web-application-firewall-waf-using-terraform-52de</guid>
      <description>&lt;p&gt;&lt;strong&gt;Web application firewalls (WAFs)&lt;/strong&gt; are an essential security layer for any web application. They protect your applications from common attacks, such as SQL injection, cross-site scripting, and denial-of-service attacks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Terraform&lt;/strong&gt; is an infrastructure as code (IaC) tool that can be used to automate the deployment and management of WAFs. This makes it easy to deploy consistent and secure WAFs across all of your environments.&lt;/p&gt;

&lt;p&gt;In this blog post, we will show you how to set up a WAF using Terraform. We will use the AWS WAF v2 service as an example, but the same principles can be applied to other WAFs.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Prerequisites&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Before getting started, you will need to have the following prerequisites:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A Terraform installation&lt;/li&gt;
&lt;li&gt;An AWS account with the necessary permissions to create and manage WAF resources&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Creating a Terraform configuration&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The first step is to create a Terraform configuration file. This file will define the resources that you want to create, such as the WAF and its associated rules.&lt;/p&gt;

&lt;p&gt;Here is a simple example of a Terraform configuration for an AWS WAF v2:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#######################################
# --- Resources ----
#######################################
resource "aws_wafv2_web_acl" "waf" {
  count = var.create ? 1 : 0
  name  = "${var.prefix}-${var.name}"
  scope = var.scope

  // default action
  default_action {
    allow {}
  }

  // AWSManagedRulesCommonRuleSet
  rule {
    name     = "AWSManagedRulesCommonRuleSet"
    priority = 10

    override_action {
      none {
      }
    }

    statement {
      managed_rule_group_statement {
        name        = "AWSManagedRulesCommonRuleSet"
        vendor_name = "AWS"
      }
    }

    visibility_config {
      cloudwatch_metrics_enabled = true
      metric_name                = "AWSManagedRulesCommonRuleSetMetric"
      sampled_requests_enabled   = true
    }
  }

  // AWSManagedRulesKnownBadInputsRuleSet
  rule {
    name     = "AWSManagedRulesKnownBadInputsRuleSet"
    priority = 20

    override_action {
      none {
      }
    }

    statement {
      managed_rule_group_statement {
        name        = "AWSManagedRulesKnownBadInputsRuleSet"
        vendor_name = "AWS"
      }
    }

    visibility_config {
      cloudwatch_metrics_enabled = true
      metric_name                = "AWSManagedRulesKnownBadInputsRuleSetMetric"
      sampled_requests_enabled   = true
    }
  }

  // AWSManagedRulesAmazonIpReputationList
  rule {
    name     = "AWSManagedRulesAmazonIpReputationList"
    priority = 30

    override_action {
      none {
      }
    }

    statement {
      managed_rule_group_statement {
        name        = "AWSManagedRulesAmazonIpReputationList"
        vendor_name = "AWS"
      }
    }

    visibility_config {
      cloudwatch_metrics_enabled = true
      metric_name                = "AWSManagedRulesAmazonIpReputationListMetric"
      sampled_requests_enabled   = true
    }
  }

  // AWSManagedRulesAnonymousIpList
  rule {
    name     = "AWSManagedRulesAnonymousIpList"
    priority = 40

    override_action {
      none {
      }
    }

    statement {
      managed_rule_group_statement {
        name        = "AWSManagedRulesAnonymousIpList"
        vendor_name = "AWS"
      }
    }

    visibility_config {
      cloudwatch_metrics_enabled = true
      metric_name                = "AWSManagedRulesAnonymousIpListMetric"
      sampled_requests_enabled   = true
    }
  }

  // AWSManagedRulesSQLiRuleSet
  rule {
    name     = "AWSManagedRulesSQLiRuleSet"
    priority = 50

    override_action {
      none {
      }
    }

    statement {
      managed_rule_group_statement {
        name        = "AWSManagedRulesSQLiRuleSet"
        vendor_name = "AWS"
      }
    }

    visibility_config {
      cloudwatch_metrics_enabled = true
      metric_name                = "AWSManagedRulesSQLiRuleSetMetric"
      sampled_requests_enabled   = true
    }
  }

  // AWSManagedRulesLinuxRuleSet
  rule {
    name     = "AWSManagedRulesLinuxRuleSet"
    priority = 60

    override_action {
      none {
      }
    }

    statement {
      managed_rule_group_statement {
        name        = "AWSManagedRulesLinuxRuleSet"
        vendor_name = "AWS"
      }
    }

    visibility_config {
      cloudwatch_metrics_enabled = true
      metric_name                = "AWSManagedRulesLinuxRuleSetMetric"
      sampled_requests_enabled   = true
    }
  }

  // AWSManagedRulesUnixRuleSet
  rule {
    name     = "AWSManagedRulesUnixRuleSet"
    priority = 70

    override_action {
      none {
      }
    }

    statement {
      managed_rule_group_statement {
        name        = "AWSManagedRulesUnixRuleSet"
        vendor_name = "AWS"
      }
    }

    visibility_config {
      cloudwatch_metrics_enabled = true
      metric_name                = "AWSManagedRulesUnixRuleSetMetric"
      sampled_requests_enabled   = true
    }
  }

  tags = {
    Name = "${var.prefix}-${var.name}"
  }

  visibility_config {
    cloudwatch_metrics_enabled = true
    metric_name                = var.metric_name
    sampled_requests_enabled   = true
  }

  lifecycle {
    create_before_destroy = true
  }
}

resource "aws_wafv2_web_acl_logging_configuration" "api_server_waf_log" {
  count                   = var.create ? 1 : 0
  log_destination_configs = [aws_s3_bucket.logs.arn]
  resource_arn            = aws_wafv2_web_acl.waf[count.index].arn
}

resource "aws_s3_bucket" "logs" {
  bucket = "aws-waf-logs-${var.prefix}-${var.name}"

  force_destroy = true

  tags = {
    Name = "aws-waf-logs-${var.prefix}-${var.name}"
  }
}

resource "aws_s3_bucket_acl" "acl" {
  bucket     = aws_s3_bucket.logs.id
  acl        = "private"
  depends_on = [aws_s3_bucket_ownership_controls.acl_ownership]
}

resource "aws_s3_bucket_ownership_controls" "acl_ownership" {
  bucket = aws_s3_bucket.logs.id
  rule {
    object_ownership = "ObjectWriter"
  }
}

resource "aws_s3_bucket_server_side_encryption_configuration" "sse_configuration" {
  bucket = aws_s3_bucket.logs.id
  rule {
    apply_server_side_encryption_by_default {
      sse_algorithm = "AES256"
    }
  }
}

resource "aws_s3_bucket_public_access_block" "public_access_block" {
  bucket                  = aws_s3_bucket.logs.id
  block_public_acls       = true
  block_public_policy     = true
  ignore_public_acls      = true
  restrict_public_buckets = true
}

#######################################
# --- Variables ----
#######################################
variable "create" {
  description = "Controls if waf should be created"
  type        = bool
}

variable "prefix" {
  description = "The prefix of the resource name"
  type        = string
}

variable "name" {
  description = "The name of the waf resource"
  type        = string
}

variable "scope" {
  description = "The scope of the waf"
  type        = string
}

variable "metric_name" {
  description = "The name of the metric"
  type        = string
}

#######################################
# --- Outputs ----
#######################################
output "waf_arn" {
  value       = length(aws_wafv2_web_acl.waf) &amp;gt; 0 ? aws_wafv2_web_acl.waf[0].arn : ""
  description = "The arn of waf"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Deploying the WAF&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Once you have created the Terraform configuration file, you can deploy the WAF by running the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;terraform apply&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will create the WAF and its associated resources in AWS.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Testing the WAF&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Once the WAF has been deployed, you should test it to make sure that it is working properly. You can do this by sending a test request to your web application and verifying that the WAF blocks the request.&lt;/p&gt;

&lt;p&gt;You can also use the AWS WAF console to test the WAF. To do this, go to the Web ACLs page and click on the name of your web ACL. Then, click on the Test tab and enter a test request.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In this blog post, we have shown you how to set up a WAF using Terraform. Terraform is a powerful tool that can be used to automate the deployment and management of WAFs. This makes it easy to deploy consistent and secure WAFs across all of your environments.&lt;/p&gt;

</description>
      <category>terraform</category>
      <category>aws</category>
      <category>devops</category>
      <category>security</category>
    </item>
  </channel>
</rss>
