0
0
Terraformcloud~30 mins

Import block syntax (Terraform 1.5+) - Mini Project: Build & Apply

Choose your learning style9 modes available
Importing Existing AWS S3 Bucket Using Terraform 1.5+ Import Block Syntax
📖 Scenario: You have an existing AWS S3 bucket created outside Terraform. You want to manage it using Terraform without recreating it.
🎯 Goal: Use Terraform 1.5+ import block syntax to import the existing AWS S3 bucket into Terraform state and configure it.
📋 What You'll Learn
Create a Terraform resource block for the AWS S3 bucket
Add an import block inside the resource to specify the bucket to import
Use the correct syntax for the import block introduced in Terraform 1.5+
Configure the bucket with versioning enabled
💡 Why This Matters
🌍 Real World
Managing existing cloud resources with Terraform allows teams to have infrastructure as code without recreating resources, reducing downtime and errors.
💼 Career
Cloud engineers and DevOps professionals often need to import existing resources into Terraform to maintain and automate infrastructure management.
Progress0 / 4 steps
1
Create AWS S3 bucket resource block
Create a Terraform resource block named aws_s3_bucket with the resource name my_bucket. Set the bucket attribute to my-existing-bucket.
Terraform
Need a hint?

Use resource "aws_s3_bucket" "my_bucket" {} and set bucket = "my-existing-bucket".

2
Add import block to specify existing bucket
Inside the aws_s3_bucket.my_bucket resource block, add an import block. Set the id attribute to my-existing-bucket to specify the bucket to import.
Terraform
Need a hint?

The import block syntax is new in Terraform 1.5+. Use import { id = "my-existing-bucket" } inside the resource.

3
Enable versioning on the bucket
Inside the aws_s3_bucket.my_bucket resource block, add a versioning block. Set enabled to true to enable versioning.
Terraform
Need a hint?

Use versioning { enabled = true } inside the resource block to enable versioning.

4
Add provider configuration for AWS
Add a provider block for aws with the region set to us-east-1.
Terraform
Need a hint?

Use provider "aws" { region = "us-east-1" } at the top of your Terraform file.