Given the Terraform resource below, what is the correct way to reference the id attribute of the aws_instance resource named web in another resource?
resource "aws_instance" "web" {
ami = "ami-123456"
instance_type = "t2.micro"
}Think about how Terraform references resource attributes using dot notation.
Terraform references resource attributes using the syntax resource_type.resource_name.attribute. Here, aws_instance.web.id correctly accesses the id attribute of the web instance.
Which option correctly defines an AWS S3 bucket resource with versioning enabled in Terraform?
Versioning is a nested block with an enabled argument set to true.
The correct syntax for enabling versioning in an AWS S3 bucket resource is to use a nested versioning block with enabled = true. Option C follows this syntax exactly.
You want to create an AWS EC2 instance that only allows SSH access from your office IP. Which resource argument configuration correctly achieves this?
Security groups control network access. SSH uses port 22 and ingress rules allow incoming traffic.
Option A correctly creates a security group with an ingress rule allowing TCP port 22 from the office IP range, then attaches it to the EC2 instance using vpc_security_group_ids. This setup restricts SSH access properly.
If you change the instance_type argument of an existing aws_instance resource in Terraform and apply the changes, what will happen?
Consider how Terraform handles changes to immutable resource arguments.
Changing the instance_type of an AWS EC2 instance requires replacement because the instance type cannot be changed in place. Terraform will destroy the old instance and create a new one with the updated type.
Review the following Terraform resource configuration for an AWS RDS instance. Which option correctly identifies the security risk present?
resource "aws_db_instance" "example" {
allocated_storage = 20
engine = "mysql"
engine_version = "8.0"
instance_class = "db.t3.micro"
name = "mydb"
username = "admin"
password = "password123"
parameter_group_name = "default.mysql8.0"
skip_final_snapshot = true
}Think about sensitive data handling best practices in Terraform.
Hardcoding sensitive information like passwords in Terraform files risks exposure if the files are stored in version control. Best practice is to use secure methods like environment variables or secret managers.