<?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: Saurabh Kumar Singh</title>
    <description>The latest articles on DEV Community by Saurabh Kumar Singh (@cloudcuddler).</description>
    <link>https://dev.to/cloudcuddler</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%2F2596143%2F92beaf0c-d5f6-4ede-8e42-62168291ae7c.jpg</url>
      <title>DEV Community: Saurabh Kumar Singh</title>
      <link>https://dev.to/cloudcuddler</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cloudcuddler"/>
    <language>en</language>
    <item>
      <title>Difference between AWS Security Groups and NACL</title>
      <dc:creator>Saurabh Kumar Singh</dc:creator>
      <pubDate>Wed, 25 Dec 2024 22:38:51 +0000</pubDate>
      <link>https://dev.to/cloudcuddler/difference-between-aws-security-groups-and-nacl-32f0</link>
      <guid>https://dev.to/cloudcuddler/difference-between-aws-security-groups-and-nacl-32f0</guid>
      <description>&lt;p&gt;Hi Techie,&lt;/p&gt;

&lt;p&gt;Today, we will discuss the most common topics in AWS: security groups and NACL. A common interview question is, &lt;strong&gt;“What is the difference between Security Groups and NACL?”&lt;/strong&gt; So, let’s discuss both topics in detail.&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic Architecture of Security Group and NACL in AWS
&lt;/h2&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%2F08ghdcgvobo09fjmapkq.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%2F08ghdcgvobo09fjmapkq.png" alt="Image description" width="800" height="760"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Security Group
&lt;/h2&gt;

&lt;p&gt;Security Group is a stateful firewall for the EC2 instances to control inbound and outbound traffic. It acts like a virtual firewall that can be attached to the instance or instances.&lt;/p&gt;

&lt;p&gt;Below are the basic attributes of security groups:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;For inbound and outbound traffic we can put separate rules.&lt;/li&gt;
&lt;li&gt;There are no inbound rules for the newly created security group. To allow communication from another host to your EC2 instance, you need to add them to the inbound rules of a security group.&lt;/li&gt;
&lt;li&gt;By default, all the outbound traffic is allowed in a newly created security group. However, you can remove this and set outbound rules as per your requirement.&lt;/li&gt;
&lt;li&gt;security group rules are always permissive i.e You can not specify deny rules, you need to always define allow rules.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;How newly added security group looks like in AWS:&lt;/strong&gt;&lt;/p&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%2Fgk8atiwswzyxo3sfgf5q.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%2Fgk8atiwswzyxo3sfgf5q.png" alt="Image description" width="800" height="382"&gt;&lt;/a&gt;&lt;/p&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%2Fuw5z3kwavamsw2s7gurw.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%2Fuw5z3kwavamsw2s7gurw.png" alt="Image description" width="800" height="359"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Security Group Inbound and Outbound Rule Fields:
&lt;/h2&gt;

&lt;p&gt;Both the Inbound and Outbound rules have almost the same rule fields.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;**Type: **Type of traffic which can be SSH, SMTP, ICMP, etc. It also has a Custom Protocol option, which allows you to select other port range.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Protocol:&lt;/strong&gt; Same like type it could be autofill based on Type selection or can be specific custom.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Port Range:&lt;/strong&gt; You can specify a single port or a range of port e.g. 5001 – 6000&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Source (Inbound rule):&lt;/strong&gt; It could be single IP, anywhere (0.0.0.0/0) or CIDR range.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Destination (Outbound rule):&lt;/strong&gt; It could be single IP, anywhere (0.0.0.0/0) or CIDR range.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Description:&lt;/strong&gt; This is an optional field but recommends adding a description that helps the team to understand the purpose of the rule.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Network Access Control List
&lt;/h2&gt;

&lt;p&gt;NACL is a stateless virtual firewall that works at the subnet level. Everything both Inbound and Outbound traffic is allowed in default NACL. In NACL you need to specify explicitly what to block in Inbound and Outbound Rules.&lt;/p&gt;

&lt;p&gt;A default NACL will be created when we create a new VPC and it allows ALL Inbound Traffic and Outbound Traffic. If we don’t associate a Subnet to a user-defined NACL then default NACL will be attached to that Subnet. A default NACL looks like this :&lt;/p&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%2Fgsgk6iqr6hufg44986ua.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%2Fgsgk6iqr6hufg44986ua.png" alt="Image description" width="800" height="428"&gt;&lt;/a&gt;&lt;/p&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%2F9ncicz3xw74427tczojl.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%2F9ncicz3xw74427tczojl.png" alt="Image description" width="800" height="414"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  NACL Inbound and Outbound Rule Fields
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Rule Number:&lt;/strong&gt; Rules are evaluated starting with the lowest numbered rule. If a rule matches, it gets executed without checking for any other higher-numbered rules.&lt;/li&gt;
&lt;li&gt;**Type: **Type of traffic which can be SSH, SMTP, ICMP, etc. It also has a Custom Protocol option, which allows you to select other port range.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Protocol:&lt;/strong&gt; Same like type it could be autofill based on Type selection or can be specific custom.
Port Range: You can specify a single port or a range of port e.g. 5001 – 6000&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Source (Inbound rule):&lt;/strong&gt; It could be single IP, anywhere (0.0.0.0/0) or CIDR range.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Destination (Outbound rule):&lt;/strong&gt; It could be single IP, anywhere (0.0.0.0/0) or CIDR range.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Description:&lt;/strong&gt; This is an optional field but recommends adding a description that helps the team to understand the purpose of the rule.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Allow/Deny:&lt;/strong&gt; Specifies whether to allow or deny traffic.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Now the question is “What is the difference between Security Group and NACL?”
&lt;/h2&gt;

&lt;p&gt;Firewall behavior is the major feature that will make security groups different from NACL. A security group is stateful while NACL is Stateless.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stateful:&lt;/strong&gt; Security Group is called a Stateful Firewall because SG maintains the state of a connection that means if an instance sends a request, the response traffic from outside is allowed back irrespective of the inbound rules and vice versa.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example:- Let suppose In the security group you have blocked all the inbound traffic and allows all the outbound traffic. Now I visit a website on my ec2 instance, the response from the WebServer back to my ec2 instance will be allowed even you have set no traffic for an inbound rule.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Security group achieves this by Connection Tracking. Security Groups use Connection Tracking to keep track of connection details that flows in and out of an ec2 instance, this information includes – IP address, Port number, and some other metadata.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stateless:&lt;/strong&gt; NACL does not maintain connections detail, which means it is stateless. if some traffic is allowed in NACL Inbound Rule, the response Outbound traffic is not allowed by default unless specified in the Outbound Rules.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Differences between Security Group and NACL :
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Security Group&lt;/th&gt;
&lt;th&gt;NACL&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;It works at instance level.&lt;/td&gt;
&lt;td&gt;It works at subnet level.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;All inbound traffic blocked by default.&lt;/td&gt;
&lt;td&gt;All inbound and outbound traffic allows by default.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Only allow rule can be add&lt;/td&gt;
&lt;td&gt;Allow and deny both the rules can be added&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Stateful&lt;/td&gt;
&lt;td&gt;Stateless&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multiple SGs can be associated with an ec2 instance&lt;/td&gt;
&lt;td&gt;Only one NACL can be associated with a single subnet&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Evaluates all Rules and finds the most permissive rule&lt;/td&gt;
&lt;td&gt;Evaluates starting with the lowest numbered rule till a rule matches.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>aws</category>
      <category>devops</category>
      <category>security</category>
      <category>networking</category>
    </item>
    <item>
      <title>How to Estimate Cloud Costs with Terraform using Infracost</title>
      <dc:creator>Saurabh Kumar Singh</dc:creator>
      <pubDate>Fri, 20 Dec 2024 16:47:43 +0000</pubDate>
      <link>https://dev.to/cloudcuddler/how-to-estimate-cloud-costs-with-terraform-using-infracost-55a3</link>
      <guid>https://dev.to/cloudcuddler/how-to-estimate-cloud-costs-with-terraform-using-infracost-55a3</guid>
      <description>&lt;p&gt;Managing, optimizing and estimating cloud costs has become critical to running efficient and cost-effective operations in today’s cloud-centric world. As organizations increasingly rely on Infrastructure as Code (IaC) tools like Terraform to manage their cloud infrastructure, the need for integrated cost estimation and financial operations (FinOps) practices is more important than ever. This article explores leveraging Infracost for accurate cloud cost estimates and adopting FinOps best practices to streamline your Terraform-managed infrastructure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Importance of Cloud Cost Estimates&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Understanding the cost implications of your infrastructure decisions is fundamental to effective cloud management. Accurate cloud cost estimates enable teams to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Budget Accurately:&lt;/strong&gt; Ensure that cloud expenses align with financial forecasts and budgets.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optimize Resources:&lt;/strong&gt; Identify cost-saving opportunities by analyzing spending patterns and optimizing resource utilization.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Promote Cost-Aware Culture:&lt;/strong&gt; Embed a cost-conscious culture within development teams, ensuring cost considerations are part of the decision-making process.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;How to use Infracost with Terraform?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Terraform is a widely used IaC tool that allows developers to define and provision cloud resources using declarative configuration files. By integrating Infracost, a tool designed for real-time cost estimation, into your Terraform workflows, you can gain valuable insights into the cost implications of your infrastructure changes before deployment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A machine (for this guide, I am using Amazon Linux )&lt;/li&gt;
&lt;li&gt;Terraform CLI &lt;/li&gt;
&lt;li&gt;An AWS account&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;STEP 1 – Install Infracost&lt;/strong&gt;&lt;br&gt;
Get the latest Infracost release. The simplest method is to use the installation script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Downloads the CLI based on your OS/arch and puts it in /usr/local/bin
curl -fsSL https://raw.githubusercontent.com/infracost/infracost/master/scripts/install.sh | sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;infracost --version # Should show 0.10.37&lt;/code&gt;&lt;/p&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%2F3n1423qa3wprn6yq02y2.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%2F3n1423qa3wprn6yq02y2.png" alt="Image description" width="800" height="203"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEP 2 – Get the API key&lt;/strong&gt;&lt;br&gt;
Please register for a free API key, which the CLI uses to fetch prices from our Cloud Pricing API, such as retrieving prices for different instance types.&lt;br&gt;
&lt;code&gt;infracost auth login&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You will be redirected to the Infracost login page, where you must complete the login process. Once done, the key will be stored on your server. You can retrieve the key by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;infracost configure get api_key 
# output should be ico-X8i4bg0xD6SBV9GT1QqtseF51S4V8Z0P
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;STEP 3 – Create a Terraform Configuration&lt;/strong&gt;&lt;br&gt;
Created a simple Terraform configuration file, which you can download from git [&lt;a href="https://github.com/cloudcuddlers/infracost-terraform" rel="noopener noreferrer"&gt;https://github.com/cloudcuddlers/infracost-terraform&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEP 4 – Initialize Terraform and generate a plan&lt;/strong&gt;&lt;br&gt;
Run the command init and plan to generate a terraform plan for your infrastructure as code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform init
terraform plan -out=tfplan.binary
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;STEP 5 – Generate Infracost Cost Estimates&lt;/strong&gt;&lt;br&gt;
Run Infracost to generate a cost estimate for your Terraform configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;infracost breakdown --path=tfplan.binary --project-name=cloudcuddler
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fjkpcx049qoagolbcriom.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%2Fjkpcx049qoagolbcriom.png" alt="Image description" width="800" height="599"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now if you want to compare the cost with the previous version and the current version then you need to save the output in JSON format with the mentioned command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;infracost breakdown --path=tfplan.binary --project-name=cloudcuddler --out-file previous_version.json --format json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you have added one more EC2 instance in your Terraform configuration file and again run the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;infracost diff --path=tfplan.binary --compare-to previous_version.json --project-name=cloudcuddler
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2F44izsrxo5sdarixzdffq.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%2F44izsrxo5sdarixzdffq.png" alt="Image description" width="800" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, by adding another EC2 instance, Infracost captures this change from Terraform, reflecting the resulting increase in monthly costs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By integrating Infracost into your Terraform workflows, you can gain valuable insights into the cost implications of your infrastructure changes before deployment. This ensures that cost efficiency is considered at every development lifecycle stage. Implementing FinOps best practices with Infracost helps promote a culture of cost awareness and drives financial and operational excellence in your cloud journey.&lt;/p&gt;

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