Complete the code to reference the AWS VPC data source.
data "aws_vpc" "main" { id = [1] }
The id attribute should reference a variable holding the VPC ID, such as var.vpc_id.
Complete the code to create a subnet using the VPC ID from the data source.
resource "aws_subnet" "example" { vpc_id = [1] cidr_block = "10.0.1.0/24" }
The subnet's vpc_id should reference the ID from the data source: data.aws_vpc.main.id.
Fix the error in the data source dependency to correctly get the subnet IDs.
data "aws_subnet_ids" "selected" { vpc_id = [1] }
data. prefix.The vpc_id must reference the data source with data.aws_vpc.main.id to ensure proper dependency.
Fill both blanks to create a security group that depends on the VPC data source.
resource "aws_security_group" "example" { name = "example-sg" description = "Example security group" vpc_id = [1] ingress { from_port = 80 to_port = 80 protocol = "tcp" cidr_blocks = [[2]] } }
The vpc_id should come from the data source data.aws_vpc.main.id. The ingress cidr_blocks should allow traffic from "0.0.0.0/0" for public access.
Fill all three blanks to output the subnet IDs from the data source with a condition.
output "public_subnet_ids" { value = [for id in [1] : id if [2](id, [3])] }
The output iterates over subnet IDs from the data source data.aws_subnet_ids.selected.ids, filtering IDs that start with "subnet-" using the starts_with function.