Complete the code to define an AWS S3 bucket with a name.
resource "aws_s3_bucket" "my_bucket" { bucket = "[1]" }
The bucket argument requires the actual bucket name as a string. Here, "my-unique-bucket-123" is a valid bucket name.
Complete the code to reference the ARN attribute of the AWS S3 bucket resource.
output "bucket_arn" { value = aws_s3_bucket.my_bucket.[1] }
The arn attribute gives the Amazon Resource Name of the bucket, which uniquely identifies it.
Fix the error in the resource block by completing the missing argument for versioning configuration.
resource "aws_s3_bucket" "my_bucket" { bucket = "my-versioned-bucket" versioning { [1] = "Enabled" } }
true instead of string "Enabled".The correct argument to enable versioning inside the versioning block is status set to "Enabled".
Fill both blanks to create a resource with tags and a lifecycle block to prevent deletion.
resource "aws_s3_bucket" "my_bucket" { bucket = "my-tagged-bucket" tags = { [1] = "Production" } lifecycle { [2] = true } }
The tag key should be 'Environment' to label the bucket. The lifecycle block uses 'prevent_destroy' = true to prevent Terraform from deleting the bucket.
Fill all three blanks to output the bucket name, ARN, and region attributes.
output "bucket_info" { value = { name = aws_s3_bucket.my_bucket.[1], arn = aws_s3_bucket.my_bucket.[2], region = aws_s3_bucket.my_bucket.[3] } }
The bucket's name is accessed with 'bucket', the ARN with 'arn', and the region with 'region' attributes.