Complete the code to declare a resource that creates an AWS S3 bucket.
resource "aws_s3_bucket" "my_bucket" { bucket = [1] }
The resource block creates a new AWS S3 bucket with the specified name. The bucket name must be a string.
Complete the code to declare a data source that reads an existing AWS S3 bucket.
data "aws_s3_bucket" "existing_bucket" { bucket = [1] }
The data block reads information about an existing AWS S3 bucket. The bucket name must be a string literal.
Fix the error in referencing the bucket name from a data source in the resource block.
resource "aws_s3_bucket_policy" "policy" { bucket = [1].bucket policy = jsonencode({ Statement = [] }) }
To reference an existing bucket from a data source, use data.aws_s3_bucket.existing_bucket.bucket. This accesses the bucket attribute from the data source.
Fill both blanks to create a resource that uses a data source to get the VPC ID.
data "aws_vpc" "selected" { filter { name = [1] values = ["default"] } } resource "aws_subnet" "example" { vpc_id = [2].id cidr_block = "10.0.1.0/24" }
The data source filter uses the tag name to find the default VPC. The resource references the data source's ID attribute.
Fill all three blanks to create a resource that uses a data source to get an AMI ID and launch an EC2 instance.
data "aws_ami" "ubuntu" { most_recent = true filter { name = [1] values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"] } owners = [[2]] } resource "aws_instance" "web" { ami = [3].id instance_type = "t2.micro" }
The data source filters AMIs by the name attribute. The owner ID is a string. The resource references the data source's ID attribute.