0% found this document useful (0 votes)
6 views6 pages

3.2. Creating Infrastructure With Terraform

The document outlines the process of creating and managing AWS infrastructure using Terraform, including setting up configurations, defining resources, and executing commands like terraform init, plan, apply, and destroy. It emphasizes the importance of clarity in resource management to prevent accidental loss. The activity section provides step-by-step instructions for setting up a VPC, subnets, and other resources in Terraform.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views6 pages

3.2. Creating Infrastructure With Terraform

The document outlines the process of creating and managing AWS infrastructure using Terraform, including setting up configurations, defining resources, and executing commands like terraform init, plan, apply, and destroy. It emphasizes the importance of clarity in resource management to prevent accidental loss. The activity section provides step-by-step instructions for setting up a VPC, subnets, and other resources in Terraform.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Creating Infrastructure with Terraform

The process begins with setting up a Terraform configuration in a folder, defining


resources such as VPCs, subnets, an Internet Gateway, and a route table using .tf files.
The AWS provider and required dependencies are initialized with terraform init.
Authentication is established, and the infrastructure plan is reviewed using terraform
plan. Resources are then created with terraform apply and verified in the AWS
Management Console. Optionally, resources can be destroyed with terraform destroy.
The end goal is to automate the creation, management, and teardown of AWS
infrastructure efficiently using Terraform while maintaining clarity and preventing
accidental resource loss.

Activity
1. Open Visual Studio Code and Create a folder and name it appropriately, such as 01-
benefits. Inside the folder, create a file with the .tf extension (e.g., vpc.tf).
2. Write a provider block to define the AWS provider and specify the region.
3. Define a resource block for the VPC with its CIDR block (e.g., 10.0.0.0/16).
4. Create resource blocks for a public and a private subnet, linking them to the VPC and
specifying non-overlapping CIDR blocks.
5. Define a resource block for the Internet Gateway and attach it to the VPC.
6. Create a resource block for the route table and link it to the VPC.
7. Add a route in the route table for internet access (0.0.0.0/0) via the Internet Gateway.
8. Define a route table association resource to link the public subnet to the route table.
9. Review the configuration to ensure all resources are connected correctly and
dependencies are clear.
10. Optionally, apply the configuration using Terraform commands to deploy the
infrastructure to AWS.
11. Run a terraform plan to preview the changes Terraform will apply.
12. If everything looks correct, execute terraform apply to deploy the infrastructure to
AWS.
13. Verify the created resources in the AWS Management Console.
14. The code is shown below:-
Now, we are going to continue this in the next lab.
Exploring Terraform Stages
1. Navigate to the project directory where Terraform configurations are stored.
2. Open VS Code where you have the code and open new terminal.
3. Run terraform init to initialize the directory and download required providers.

4. Authenticate by sourcing the environment file with AWS credentials.

5. Use terraform plan to review resources Terraform will create or change.

6. Add or modify tags in the configuration file if needed, to distinguish resources.


7. Execute terraform apply, review the plan, and confirm with "yes" to create the
resources.

8. Verify the resources in the AWS Management Console for the selected region.
9. Run terraform destroy to remove all resources managed by Terraform, confirming
with "yes".

10. Refresh the AWS console to ensure resources were successfully deleted.

Note: Use Terraform carefully to manage updates or deletions to avoid accidental


infrastructure loss.

You might also like