0
0
Terraformcloud~30 mins

Writing configuration for imported resources in Terraform - Mini Project: Build & Apply

Choose your learning style9 modes available
Writing configuration for imported resources
📖 Scenario: You have an existing AWS S3 bucket created outside Terraform. You want to manage it using Terraform by importing it and writing the configuration.
🎯 Goal: Create a Terraform configuration that matches the imported AWS S3 bucket resource.
📋 What You'll Learn
Create a Terraform resource block for the S3 bucket named exactly aws_s3_bucket.example.
Add a variable bucket_name with the exact value my-imported-bucket.
Use the variable bucket_name in the resource configuration.
Add a lifecycle block to ignore changes to the acl attribute.
💡 Why This Matters
🌍 Real World
Managing existing cloud resources with Terraform is common when adopting infrastructure as code in teams.
💼 Career
Cloud engineers and DevOps professionals often import resources and write configurations to maintain infrastructure consistency.
Progress0 / 4 steps
1
Define the bucket_name variable
Create a Terraform variable called bucket_name with the default value "my-imported-bucket".
Terraform
Need a hint?

Use the variable block with a default attribute.

2
Create the aws_s3_bucket.example resource block
Create a Terraform resource block named aws_s3_bucket.example that uses the variable bucket_name for the bucket attribute.
Terraform
Need a hint?

Use resource "aws_s3_bucket" "example" and set bucket = var.bucket_name.

3
Add a lifecycle block to ignore changes to acl
Inside the aws_s3_bucket.example resource block, add a lifecycle block that ignores changes to the acl attribute.
Terraform
Need a hint?

Use lifecycle { ignore_changes = ["acl"] } inside the resource block.

4
Complete the Terraform configuration for the imported S3 bucket
Ensure the Terraform configuration includes the variable "bucket_name" block and the aws_s3_bucket.example resource block with the lifecycle block ignoring acl changes.
Terraform
Need a hint?

Make sure all parts are present exactly as specified.