Terraform Tutorial For Beginners on AWS | Run A Static Website
Tags: terraform, aws, devops, tutorial
Published: 2020-12-23 01:57:00

<p>In this article, you will learn how to use Terraform to create an EC2 instance and deploy a simple web application. </p>
<p>Check out this video for a demo</p>
{% youtube 7NR7soSwYKk %}
<p>Before we look at the definition of Terraform, let's first understand another key concept.</p>
<h2>Infrastructure as Code</h2>
<p>Infrastructure as Code (IAC) is the process of provisioning and managing infrastructure (VM/Storage/Network etc.) by means of using code / configuration files.</p>
<h2>Terraform</h2>
<p>Terraform is an open-source Infrastructure as code tool that can work with multiple cloud providers such as AWS, GCP, Azure etc.</p>
<p>As always the best way to learn is by getting your hands dirty. Let's jump into a practical example.</p>
<h2>Terraform Example</h2>
<p>The goal is to be able to invoke a terraform call to provision an EC2 instance, install and configure a web server, and deploy a simple website on the instance.</p>
<h3>Pre-requisites:</h3>
<ul>
<li><a href="https://aws.amazon.com/free/?trk=ps_a134p000003yBfvAAE&amp;trkCampaign=acq_paid_search_brand&amp;sc_channel=ps&amp;sc_campaign=acquisition_US&amp;sc_publisher=google&amp;sc_category=core&amp;sc_country=US&amp;sc_geo=NAMER&amp;sc_outcome=acq&amp;sc_detail=%2Baws%20%2Bfree&amp;sc_content=Cost_bmm&amp;sc_segment=438195701024&amp;sc_medium=ACQ-P|PS-GO|Brand|Desktop|SU|AWS|Core|US|EN|Text&amp;s_kwcid=AL!4422!3!438195701024!b!!g!!%2Baws%20%2Bfree&amp;ef_id=CjwKCAiA_eb-BRB2EiwAGBnXXqD5UXITnHn0swwY14Hl_IdAqSRbJZRD1f4ei39AjS87LjJI2Cy-XRoCyK4QAvD_BwE:G:s&amp;s_kwcid=AL!4422!3!438195701024!b!!g!!%2Baws%20%2Bfree&amp;all-free-tier.sort-by=item.additionalFields.SortRank&amp;all-free-tier.sort-order=asc">Sign up for an AWS account</a> (If you're new to AWS, you will be able to use free-tier services)</li>
<li>Default Virtual Private Cloud (VPC)</li>
<li>Default subnet in the above VPC</li>
</ul>
<p>I believe by default you will get the above AWS components when you create an AWS account for the first time. Please refer to this <a href="https://www.youtube.com/watch?v=fpxDGU2KdkA">video</a> if you need to understand VPC more.</p>
<h3>High-level steps:</h3>
<ol>
<li>Create an EC2 instance on AWS console where you will run terraform.</li>
<li>Ensure you can ssh to the above EC2 instance by adding appropriate rules to security group.</li>
<li>Install wget and unzip packages in the above EC2 instance. Download &amp; Extract the latest terraform version from their website.</li>
<li>Create an EC2 Admin Role</li>
<li>Modify IAM Role of your EC2 instance</li>
<li>Initialize terraform</li>
<li>Code and Execute Terraform Module</li>
</ol>
<h3>Create an EC2 instance on AWS console where you will run terraform</h3>
<ol>
<li>Login to your AWS console</li>
<li>Navigate to EC2 service</li>
<li>Click "Launch Instance"</li>
</ol>
<p><img class="alignnone wp-image-1195 size-large" src="https://executeoncommand.com/wp-content/uploads/2020/12/ec2_step0-1024x544.png" alt="" width="1024" height="544" /></p>
<ul>
<li>Select Amazon Linux 2 AMI</li>
</ul>
<p><img class="alignnone wp-image-1197 size-large" src="https://executeoncommand.com/wp-content/uploads/2020/12/ec2_step1-1024x378.png" alt="" width="1024" height="378" /></p>
<ul>
<li>Choose "t2.micro" instance type</li>
</ul>
<p><img class="alignnone wp-image-1198 size-large" src="https://executeoncommand.com/wp-content/uploads/2020/12/ec2_step2-1024x314.png" alt="" width="1024" height="314" /></p>
<ul>
<li>Configure Instance details</li>
</ul>
<p><img class="alignnone wp-image-1200 size-large" src="https://executeoncommand.com/wp-content/uploads/2020/12/ec2_step3-1024x409.png" alt="" width="1024" height="409" /></p>
<ul>
<li>You may click "Next" button for "Add Storage" (Step 4) and "Add Tags" (Step 5). No need to change anything on these steps.</li>
<li>Create a new security group. You can change its name if you need to. Please note the ssh/http port rules added to the security group.</li>
</ul>
<p><img class="alignnone wp-image-1201 size-large" src="https://executeoncommand.com/wp-content/uploads/2020/12/ec2_step6-1024x299.png" alt="" width="1024" height="299" /></p>
<ul>
<li>Review your choices</li>
</ul>
<p><img class="alignnone wp-image-1202 size-large" src="https://executeoncommand.com/wp-content/uploads/2020/12/ec2_step7-1024x476.png" alt="" width="1024" height="476" /></p>
<ul>
<li>Create a key pair to use for ssh-ing into your instance. Make sure to download key pair on your laptop.</li>
</ul>
<p><img class="alignnone size-large wp-image-1196" src="https://executeoncommand.com/wp-content/uploads/2020/12/ec2_step8-1024x528.png" alt="" width="1024" height="528" /></p>
<ul>
<li>Launch Instance.</li>
<li>Your instance will be created and start running in a few minutes.</li>
</ul>
<h3>Ensure you can ssh to the above EC2 instance by adding appropriate rules to security group.</h3>
<ol>
<li>Open a terminal or putty session on your laptop.</li>
<li>change your directory to your key pair location, ssh into your instance (ec2-user) and sudo to root.</li>
</ol>
<p><img class="alignnone size-large wp-image-1210" src="https://executeoncommand.com/wp-content/uploads/2020/12/login-1024x469.png" alt="" width="1024" height="469" /></p>
<h3>Install wget and unzip packages in the above EC2 instance. Download &amp; Extract the latest terraform version from their website.</h3>
<pre><code class="language-jsx">[root@ip-172-31-0-191 ~]# yum install wget unzip 

Loaded plugins: extras_suggestions, langpacks, priorities, update-motd 

amzn2-core                                                                                              | 3.7 kB  00:00:00 

Package wget-1.14-18.amzn2.1.x86_64 already installed and latest version 

Package unzip-6.0-21.amzn2.x86_64 already installed and latest version 

Nothing to do 

[root@ip-172-31-0-191 ~]# 

[root@ip-172-31-0-191 ~]# wget https://releases.hashicorp.com/terraform/0.14.2/terraform_0.14.2_linux_amd64.zip 

--2020-12-14 02:39:25--  https://releases.hashicorp.com/terraform/0.14.2/terraform_0.14.2_linux_amd64.zip 

Resolving releases.hashicorp.com (releases.hashicorp.com)... 151.101.201.183, 2a04:4e42:3b::439 

Connecting to releases.hashicorp.com (releases.hashicorp.com)|151.101.201.183|:443... connected. 

HTTP request sent, awaiting response... 200 OK 

Length: 33609981 (32M) [application/zip] 

Saving to: ‘terraform_0.14.2_linux_amd64.zip’ 

100%[=====================================================================================&gt;] 33,609,981  46.8MB/s   in 0.7s 

2020-12-14 02:39:25 (46.8 MB/s) - ‘terraform_0.14.2_linux_amd64.zip’ saved [33609981/33609981] 

[root@ip-172-31-0-191 ~]# 

[root@ip-172-31-0-191 ~]# unzip terraform_0.14.2_linux_amd64.zip 

Archive:  terraform_0.14.2_linux_amd64.zip 

  inflating: terraform 

[root@ip-172-31-0-191 ~]# mv terraform /usr/local/bin/ 

[root@ip-172-31-0-191 ~]# 

[root@ip-172-31-0-191 ~]# 

[root@ip-172-31-0-191 ~]# terraform -v 

Terraform v0.14.2</code></pre>
<h3>Create an EC2 Admin Role</h3>
<ul>
<li>Navigate to Identity and Access Management. Click on "Create Role"</li>
</ul>
<p><img class="alignnone size-large wp-image-1203" src="https://executeoncommand.com/wp-content/uploads/2020/12/role1-1024x418.png" alt="" width="1024" height="418" /></p>
<ul>
<li>Select EC2 instance since the role will be assigned to EC2 instance</li>
</ul>
<p><img class="alignnone size-large wp-image-1204" src="https://executeoncommand.com/wp-content/uploads/2020/12/role2-1024x366.png" alt="" width="1024" height="366" /></p>
<ul>
<li>Select "AdministratorAccess" and Click Next.</li>
</ul>
<p><img class="alignnone size-large wp-image-1205" src="https://executeoncommand.com/wp-content/uploads/2020/12/role3-1024x471.png" alt="" width="1024" height="471" /></p>
<ul>
<li>Creating tag is optional. Click Next</li>
</ul>
<p><img class="alignnone size-large wp-image-1206" src="https://executeoncommand.com/wp-content/uploads/2020/12/role4-1024x316.png" alt="" width="1024" height="316" /></p>
<ul>
<li>Click "Create Role"</li>
</ul>
<p><img class="alignnone size-large wp-image-1207" src="https://executeoncommand.com/wp-content/uploads/2020/12/role5-1024x537.png" alt="" width="1024" height="537" /></p>
<h3><img class="alignnone size-large wp-image-1208" src="https://executeoncommand.com/wp-content/uploads/2020/12/role6-1024x304.png" alt="" width="1024" height="304" /></h3>
<h3>Modify IAM Role of your EC2 instance</h3>
<ul>
<li>Navigate back to EC2 service and Instance page. And Modify IAM role.</li>
<li>Choose the role created in the prior step</li>
</ul>
<h3>Initialize Terraform</h3>
<p>Switch back to your terminal session and run "terraform init" command. Terraform init command downloads necessary plugins based on the providers specified in the configuration file.</p>
<p><img class="alignnone size-large wp-image-1211" src="https://executeoncommand.com/wp-content/uploads/2020/12/init-1024x640.png" alt="" width="1024" height="640" /></p>
<h3>Code and Execute Terraform Module</h3>
<p>Create a file called "webapp.tf" using vi editor and save the below code in it.</p>
<pre><code class="language-jsx">
// this section declares which cloud provider we are going to use.
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~&gt; 3.0"
    }
  }
}

# Configure the AWS Provider
provider "aws" {
  region = "us-east-1"
}

// this section declares the query to get ami info out of AWS
data "aws_ami" "amazon_linux2_ami" {
    most_recent = true
    owners = ["amazon"]

    filter {
        name = "image-id"
        values = ["ami-04d29b6f966df1537"]
    }
}

// this section declares that we need a security group resource with its rules
resource "aws_security_group" "allow_webapp_traffic" {
  name        = "allow_webapp_traffic"
  description = "Allow inbound traffic"

  ingress {
    from_port   = 80
    to_port     = 80
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  ingress {
    from_port   = 22
    to_port     = 22
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  egress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }

  tags = {
    Name = "allow_my_laptop"
  }
}

// this section declares that we need an aws instance along with its configuration
resource "aws_instance" "webapp" {
  ami           = data.aws_ami.amazon_linux2_ami.id
  instance_type = "t2.micro"
  vpc_security_group_ids = [aws_security_group.allow_webapp_traffic.id]
  key_name = "temp_key"

  user_data = &lt;&lt;-EOF
            #!/bin/bash
            sudo yum update -y
            sudo yum install httpd -y
            sudo service httpd start
            sudo chkconfig httpd on
            echo "&lt;html&gt;&lt;h1&gt;Your terraform deployment worked !!!&lt;/h1&gt;&lt;/html&gt;" | sudo tee /var/www/html/index.html
            hostname -f &gt;&gt; /var/www/html/index.html
            EOF

  tags = {
    Name = "myfirsttfinstance"
  }
}

output "instance_ip" {
    value = aws_instance.webapp.public_ip
}</code></pre>
<h3>Run "terraform plan" command</h3>
<p>This command will make it explicit the change to be made. It's analogous to "git diff" or even sql execution plan. Before commiting your terraform configuration changes, you can run this and confirm that you're making the changes correctly.</p>
<pre><code class="language-jsx">[root@ip-172-31-0-191 ~]# terraform plan

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # aws_instance.webapp will be created
  + resource "aws_instance" "webapp" {
      + ami                          = "ami-04d29b6f966df1537"
      + arn                          = (known after apply)
      + associate_public_ip_address  = (known after apply)
      + availability_zone            = (known after apply)
      + cpu_core_count               = (known after apply)
      + cpu_threads_per_core         = (known after apply)
      + get_password_data            = false
      + host_id                      = (known after apply)
      + id                           = (known after apply)
      + instance_state               = (known after apply)
      + instance_type                = "t2.micro"
      + ipv6_address_count           = (known after apply)
      + ipv6_addresses               = (known after apply)
      + key_name                     = "temp_key"
      + outpost_arn                  = (known after apply)
      + password_data                = (known after apply)
      + placement_group              = (known after apply)
      + primary_network_interface_id = (known after apply)
      + private_dns                  = (known after apply)
      + private_ip                   = (known after apply)
      + public_dns                   = (known after apply)
      + public_ip                    = (known after apply)
      + secondary_private_ips        = (known after apply)
      + security_groups              = (known after apply)
      + source_dest_check            = true
      + subnet_id                    = (known after apply)
      + tags                         = {
          + "Name" = "myfirsttfinstance"
        }
      + tenancy                      = (known after apply)
      + user_data                    = "9c208e6d7a2edb2d4ec410b992a5cde5d69d59a5"
      + volume_tags                  = (known after apply)
      + vpc_security_group_ids       = (known after apply)

      + ebs_block_device {
          + delete_on_termination = (known after apply)
          + device_name           = (known after apply)
          + encrypted             = (known after apply)
          + iops                  = (known after apply)
          + kms_key_id            = (known after apply)
          + snapshot_id           = (known after apply)
          + volume_id             = (known after apply)
          + volume_size           = (known after apply)
          + volume_type           = (known after apply)
        }

      + ephemeral_block_device {
          + device_name  = (known after apply)
          + no_device    = (known after apply)
          + virtual_name = (known after apply)
        }

      + metadata_options {
          + http_endpoint               = (known after apply)
          + http_put_response_hop_limit = (known after apply)
          + http_tokens                 = (known after apply)
        }

      + network_interface {
          + delete_on_termination = (known after apply)
          + device_index          = (known after apply)
          + network_interface_id  = (known after apply)
        }

      + root_block_device {
          + delete_on_termination = (known after apply)
          + device_name           = (known after apply)
          + encrypted             = (known after apply)
          + iops                  = (known after apply)
          + kms_key_id            = (known after apply)
          + volume_id             = (known after apply)
          + volume_size           = (known after apply)
          + volume_type           = (known after apply)
        }
    }

  # aws_security_group.allow_webapp_traffic will be created
  + resource "aws_security_group" "allow_webapp_traffic" {
      + arn                    = (known after apply)
      + description            = "Allow inbound traffic"
      + egress                 = [
          + {
              + cidr_blocks      = [
                  + "0.0.0.0/0",
                ]
              + description      = ""
              + from_port        = 0
              + ipv6_cidr_blocks = []
              + prefix_list_ids  = []
              + protocol         = "-1"
              + security_groups  = []
              + self             = false
              + to_port          = 0
            },
        ]
      + id                     = (known after apply)
      + ingress                = [
          + {
              + cidr_blocks      = [
                  + "0.0.0.0/0",
                ]
              + description      = ""
              + from_port        = 22
              + ipv6_cidr_blocks = []
              + prefix_list_ids  = []
              + protocol         = "tcp"
              + security_groups  = []
              + self             = false
              + to_port          = 22
            },
          + {
              + cidr_blocks      = [
                  + "0.0.0.0/0",
                ]
              + description      = ""
              + from_port        = 80
              + ipv6_cidr_blocks = []
              + prefix_list_ids  = []
              + protocol         = "tcp"
              + security_groups  = []
              + self             = false
              + to_port          = 80
            },
        ]
      + name                   = "allow_webapp_traffic"
      + owner_id               = (known after apply)
      + revoke_rules_on_delete = false
      + tags                   = {
          + "Name" = "allow_my_laptop"
        }
      + vpc_id                 = (known after apply)
    }

Plan: 2 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + instance_ip = (known after apply)

------------------------------------------------------------------------

Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.</code></pre>
<h3>Run "terraform apply" command</h3>
<p>This command will apply the changes in your configuration files to reach the desired state.</p>
<pre><code class="language-jsx">[root@ip-172-31-0-191 ~]# terraform apply

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # aws_instance.webapp will be created
  + resource "aws_instance" "webapp" {
      + ami                          = "ami-04d29b6f966df1537"
      + arn                          = (known after apply)
      + associate_public_ip_address  = (known after apply)
      + availability_zone            = (known after apply)
      + cpu_core_count               = (known after apply)
      + cpu_threads_per_core         = (known after apply)
      + get_password_data            = false
      + host_id                      = (known after apply)
      + id                           = (known after apply)
      + instance_state               = (known after apply)
      + instance_type                = "t2.micro"
      + ipv6_address_count           = (known after apply)
      + ipv6_addresses               = (known after apply)
      + key_name                     = "temp_key"
      + outpost_arn                  = (known after apply)
      + password_data                = (known after apply)
      + placement_group              = (known after apply)
      + primary_network_interface_id = (known after apply)
      + private_dns                  = (known after apply)
      + private_ip                   = (known after apply)
      + public_dns                   = (known after apply)
      + public_ip                    = (known after apply)
      + secondary_private_ips        = (known after apply)
      + security_groups              = (known after apply)
      + source_dest_check            = true
      + subnet_id                    = (known after apply)
      + tags                         = {
          + "Name" = "myfirsttfinstance"
        }
      + tenancy                      = (known after apply)
      + user_data                    = "9c208e6d7a2edb2d4ec410b992a5cde5d69d59a5"
      + volume_tags                  = (known after apply)
      + vpc_security_group_ids       = (known after apply)

      + ebs_block_device {
          + delete_on_termination = (known after apply)
          + device_name           = (known after apply)
          + encrypted             = (known after apply)
          + iops                  = (known after apply)
          + kms_key_id            = (known after apply)
          + snapshot_id           = (known after apply)
          + volume_id             = (known after apply)
          + volume_size           = (known after apply)
          + volume_type           = (known after apply)
        }

      + ephemeral_block_device {
          + device_name  = (known after apply)
          + no_device    = (known after apply)
          + virtual_name = (known after apply)
        }

      + metadata_options {
          + http_endpoint               = (known after apply)
          + http_put_response_hop_limit = (known after apply)
          + http_tokens                 = (known after apply)
        }

      + network_interface {
          + delete_on_termination = (known after apply)
          + device_index          = (known after apply)
          + network_interface_id  = (known after apply)
        }

      + root_block_device {
          + delete_on_termination = (known after apply)
          + device_name           = (known after apply)
          + encrypted             = (known after apply)
          + iops                  = (known after apply)
          + kms_key_id            = (known after apply)
          + volume_id             = (known after apply)
          + volume_size           = (known after apply)
          + volume_type           = (known after apply)
        }
    }

  # aws_security_group.allow_webapp_traffic will be created
  + resource "aws_security_group" "allow_webapp_traffic" {
      + arn                    = (known after apply)
      + description            = "Allow inbound traffic"
      + egress                 = [
          + {
              + cidr_blocks      = [
                  + "0.0.0.0/0",
                ]
              + description      = ""
              + from_port        = 0
              + ipv6_cidr_blocks = []
              + prefix_list_ids  = []
              + protocol         = "-1"
              + security_groups  = []
              + self             = false
              + to_port          = 0
            },
        ]
      + id                     = (known after apply)
      + ingress                = [
          + {
              + cidr_blocks      = [
                  + "0.0.0.0/0",
                ]
              + description      = ""
              + from_port        = 22
              + ipv6_cidr_blocks = []
              + prefix_list_ids  = []
              + protocol         = "tcp"
              + security_groups  = []
              + self             = false
              + to_port          = 22
            },
          + {
              + cidr_blocks      = [
                  + "0.0.0.0/0",
                ]
              + description      = ""
              + from_port        = 80
              + ipv6_cidr_blocks = []
              + prefix_list_ids  = []
              + protocol         = "tcp"
              + security_groups  = []
              + self             = false
              + to_port          = 80
            },
        ]
      + name                   = "allow_webapp_traffic"
      + owner_id               = (known after apply)
      + revoke_rules_on_delete = false
      + tags                   = {
          + "Name" = "allow_my_laptop"
        }
      + vpc_id                 = (known after apply)
    }

Plan: 2 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + instance_ip = [
      + (known after apply),
    ]

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_security_group.allow_webapp_traffic: Creating...
aws_security_group.allow_webapp_traffic: Creation complete after 1s [id=sg-0120ec8b63972d7b5]
aws_instance.webapp: Creating...
aws_instance.webapp: Still creating... [10s elapsed]
aws_instance.webapp: Still creating... [20s elapsed]
aws_instance.webapp: Still creating... [30s elapsed]
aws_instance.webapp: Creation complete after 33s [id=i-01d2d7c58df4decc0]

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.

Outputs:

instance_ip = "3.219.233.31"</code></pre>
<h3>Run "terraform output" command</h3>
<p>This command prints the output variables defined in the configuration file.</p>
<pre><code class="language-jsx">[root@ip-172-31-0-191 ~]# terraform output
instance_ip = "3.219.233.31"</code></pre>
<h3>Run "terraform destroy" command</h3>
<pre><code class="language-jsx">[root@ip-172-31-18-39 learn_terraform]# terraform destroy

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  - destroy

Terraform will perform the following actions:

  # aws_instance.webapp will be destroyed
  - resource "aws_instance" "webapp" {
      - ami                          = "ami-04d29b6f966df1537" -&gt; null
      - arn                          = "arn:aws:ec2:us-east-1:651299717062:instance/i-024f4d2ac530440a6" -&gt; null
      - associate_public_ip_address  = true -&gt; null
      - availability_zone            = "us-east-1b" -&gt; null
      - cpu_core_count               = 1 -&gt; null
      - cpu_threads_per_core         = 1 -&gt; null
      - disable_api_termination      = false -&gt; null
      - ebs_optimized                = false -&gt; null
      - get_password_data            = false -&gt; null
      - hibernation                  = false -&gt; null
      - id                           = "i-024f4d2ac530440a6" -&gt; null
      - instance_state               = "running" -&gt; null
      - instance_type                = "t2.micro" -&gt; null
      - ipv6_address_count           = 0 -&gt; null
      - ipv6_addresses               = [] -&gt; null
      - key_name                     = "temp_key" -&gt; null
      - monitoring                   = false -&gt; null
      - primary_network_interface_id = "eni-0552525e63b5114ac" -&gt; null
      - private_dns                  = "ip-172-31-22-53.ec2.internal" -&gt; null
      - private_ip                   = "172.31.22.53" -&gt; null
      - public_dns                   = "ec2-100-27-33-82.compute-1.amazonaws.com" -&gt; null
      - public_ip                    = "100.27.33.82" -&gt; null
      - secondary_private_ips        = [] -&gt; null
      - security_groups              = [
          - "allow_webapp_traffic",
        ] -&gt; null
      - source_dest_check            = true -&gt; null
      - subnet_id                    = "subnet-0edbcce323dcc729d" -&gt; null
      - tags                         = {
          - "Name" = "myfirsttfinstance"
        } -&gt; null
      - tenancy                      = "default" -&gt; null
      - user_data                    = "9c208e6d7a2edb2d4ec410b992a5cde5d69d59a5" -&gt; null
      - volume_tags                  = {} -&gt; null
      - vpc_security_group_ids       = [
          - "sg-09cc1d86b1f7bf752",
        ] -&gt; null

      - credit_specification {
          - cpu_credits = "standard" -&gt; null
        }

      - enclave_options {
          - enabled = false -&gt; null
        }

      - metadata_options {
          - http_endpoint               = "enabled" -&gt; null
          - http_put_response_hop_limit = 1 -&gt; null
          - http_tokens                 = "optional" -&gt; null
        }

      - root_block_device {
          - delete_on_termination = true -&gt; null
          - device_name           = "/dev/xvda" -&gt; null
          - encrypted             = false -&gt; null
          - iops                  = 100 -&gt; null
          - throughput            = 0 -&gt; null
          - volume_id             = "vol-0bcea9b9d281eb9d5" -&gt; null
          - volume_size           = 8 -&gt; null
          - volume_type           = "gp2" -&gt; null
        }
    }

  # aws_security_group.allow_webapp_traffic will be destroyed
  - resource "aws_security_group" "allow_webapp_traffic" {
      - arn                    = "arn:aws:ec2:us-east-1:651299717062:security-group/sg-09cc1d86b1f7bf752" -&gt; null
      - description            = "Allow inbound traffic" -&gt; null
      - egress                 = [
          - {
              - cidr_blocks      = [
                  - "0.0.0.0/0",
                ]
              - description      = ""
              - from_port        = 0
              - ipv6_cidr_blocks = []
              - prefix_list_ids  = []
              - protocol         = "-1"
              - security_groups  = []
              - self             = false
              - to_port          = 0
            },
        ] -&gt; null
      - id                     = "sg-09cc1d86b1f7bf752" -&gt; null
      - ingress                = [
          - {
              - cidr_blocks      = [
                  - "0.0.0.0/0",
                ]
              - description      = ""
              - from_port        = 22
              - ipv6_cidr_blocks = []
              - prefix_list_ids  = []
              - protocol         = "tcp"
              - security_groups  = []
              - self             = false
              - to_port          = 22
            },
          - {
              - cidr_blocks      = [
                  - "0.0.0.0/0",
                ]
              - description      = ""
              - from_port        = 80
              - ipv6_cidr_blocks = []
              - prefix_list_ids  = []
              - protocol         = "tcp"
              - security_groups  = []
              - self             = false
              - to_port          = 80
            },
        ] -&gt; null
      - name                   = "allow_webapp_traffic" -&gt; null
      - owner_id               = "651299717062" -&gt; null
      - revoke_rules_on_delete = false -&gt; null
      - tags                   = {
          - "Name" = "allow_my_laptop"
        } -&gt; null
      - vpc_id                 = "vpc-f2cbd488" -&gt; null
    }

Plan: 0 to add, 0 to change, 2 to destroy.

Changes to Outputs:
  - instance_ip = "100.27.33.82" -&gt; null

Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes

aws_instance.webapp: Destroying... [id=i-024f4d2ac530440a6]
aws_instance.webapp: Still destroying... [id=i-024f4d2ac530440a6, 10s elapsed]
aws_instance.webapp: Still destroying... [id=i-024f4d2ac530440a6, 20s elapsed]
aws_instance.webapp: Still destroying... [id=i-024f4d2ac530440a6, 30s elapsed]
aws_instance.webapp: Destruction complete after 40s
aws_security_group.allow_webapp_traffic: Destroying... [id=sg-09cc1d86b1f7bf752]
aws_security_group.allow_webapp_traffic: Destruction complete after 0s</code></pre>

<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->