A Brief Practical Demonstration of Building AWS Infrastructure Using Terraform

<p>Today, let&rsquo;s get into a brief Terraform illustration. It&rsquo;s beneficial to understand Terraform&rsquo;s workings, even if you&rsquo;re not directly responsible for its execution. Here&rsquo;s a straightforward demonstration of Infrastructure as Code (IaC) employing Terraform to establish a fundamental Amazon Web Services (AWS) infrastructure. In this instance, we&rsquo;ll generate an AWS EC2 instance and configure a corresponding security group.</p> <pre> # Define the provider (AWS) provider &quot;aws&quot; { region = &quot;us-east-1&quot; } # Create a security group resource &quot;aws_security_group&quot; &quot;example_sg&quot; { name = &quot;example-sg&quot; description = &quot;Example Security Group&quot; // Define inbound rules to allow SSH and HTTP traffic ingress { from_port = 22 to_port = 22 protocol = &quot;tcp&quot; cidr_blocks = [&quot;0.0.0.0/0&quot;] } ingress { from_port = 80 to_port = 80 protocol = &quot;tcp&quot; cidr_blocks = [&quot;0.0.0.0/0&quot;] } } # Create an EC2 instance resource &quot;aws_instance&quot; &quot;example_instance&quot; { ami = &quot;ami-0c55b159cbfafe1f0&quot; # Amazon Linux 2 AMI ID instance_type = &quot;t2.micro&quot; key_name = &quot;your-key-pair-name&quot; # Replace with your SSH key name security_groups = [aws_security_group.example_sg.name] tags = { Name = &quot;ExampleInstance&quot; } }</pre> <p>In this example:</p> <ol> <li>We define the AWS provider with the desired region.</li> <li>We create a security group (&lsquo;<strong>aws_security_group&rsquo;</strong>) named &ldquo;<strong>example-sg</strong>&rdquo; and specify inbound rules to allow SSH and HTTP traffic.</li> <li>We create an EC2 instance (&lsquo;<strong>aws_instance&rsquo;</strong>) named &ldquo;<strong>example_instance</strong>&rdquo; using the specified Amazon Machine Image (AMI) and instance type. Make sure to replace &ldquo;your-key-pair-name&rdquo; with your actual SSH key name.</li> </ol> <p><a href="https://medium.com/@emer.kurbegovic/a-brief-practical-demonstration-of-building-aws-infrastructure-using-terraform-344cb5c1b867"><strong>Learn More</strong></a></p>
Tags: Building AWS