0
0
Terraformcloud~30 mins

Terraform plan for preview - Mini Project: Build & Apply

Choose your learning style9 modes available
Terraform plan for preview
📖 Scenario: You are working on a cloud infrastructure project using Terraform. Before applying any changes, you want to preview what Terraform will do to your infrastructure. This helps you avoid mistakes and understand the impact of your changes.
🎯 Goal: Create a Terraform configuration for a simple AWS S3 bucket and run a Terraform plan to preview the changes before applying them.
📋 What You'll Learn
Create a Terraform configuration file with an AWS provider and an S3 bucket resource
Add a variable to configure the bucket name
Write the Terraform plan command to preview the infrastructure changes
Include the output block to show the bucket name after apply
💡 Why This Matters
🌍 Real World
Terraform plan is used daily by cloud engineers to preview infrastructure changes before applying them, preventing mistakes and downtime.
💼 Career
Knowing how to write Terraform configurations and use terraform plan is essential for roles like Cloud Engineer, DevOps Engineer, and Infrastructure Engineer.
Progress0 / 4 steps
1
Create Terraform configuration with AWS provider and S3 bucket
Create a Terraform configuration file with the AWS provider block specifying region = "us-east-1". Then create an aws_s3_bucket resource named my_bucket with the bucket name "my-terraform-bucket-12345".
Terraform
Need a hint?

Start by defining the AWS provider with the region. Then add the S3 bucket resource with the exact bucket name.

2
Add a variable for the bucket name
Add a Terraform variable named bucket_name of type string with the default value "my-terraform-bucket-12345". Then update the aws_s3_bucket.my_bucket resource to use this variable for the bucket name.
Terraform
Need a hint?

Define the variable block with the exact name and default value. Use var.bucket_name in the bucket resource.

3
Write the Terraform plan command
Write the Terraform command to preview the infrastructure changes without applying them. Use the command terraform plan.
Terraform
Need a hint?

Use the exact command terraform plan to preview changes.

4
Add output to show the bucket name
Add an output block named bucket_name_output that outputs the value of aws_s3_bucket.my_bucket.bucket.
Terraform
Need a hint?

Use an output block with the exact name and value to show the bucket name after apply.