Skip to main content

Lab 22: CloudFormation Template Deployment Using Terraform

The Nautilus DevOps team is working on automating infrastructure deployment using AWS CloudFormation. As part of this effort, they need to create a CloudFormation stack that provisions an S3 bucket with versioning enabled.

Create a CloudFormation stack named nautilus-stack using Terraform. This stack should contain an S3 bucket named nautilus-bucket-13951 as a resource, and the bucket must have versioning enabled. The Terraform working directory is /home/bob/terraform. Create the main.tf file (do not create a different .tf file) to accomplish this task.

Note: Right-click under the EXPLORER section in VS Code and select Open in Integrated Terminal to launch the terminal.

Create main.tf

resource "aws_cloudformation_stack" "nautilus_stack" {
name = "nautilus-stack"

template_body = jsonencode({
AWSTemplateFormatVersion = "2010-09-09"
Description = "CloudFormation stack with an S3 bucket with versioning enabled."

Resources = {
NautilusBucket = {
Type = "AWS::S3::Bucket"
Properties = {
BucketName = "nautilus-bucket-13951"
VersioningConfiguration = {
Status = "Enabled"
}
}
}
}
})
}

terraform init
terraform plan -out kke.plan && terraform apply kke.plan
# or apply forcefully without creating plan and applying it
terraform apply -auto-approve