Which of the following is the correct resource type for creating an AWS S3 bucket in Terraform?
Resource types in Terraform usually start with the provider name, followed by the resource name.
The correct resource type for an AWS S3 bucket is aws_s3_bucket. It starts with the provider 'aws' followed by the resource 's3_bucket'.
Which of the following is a valid resource name in Terraform?
Resource names must start with a letter or underscore and can contain letters, digits, underscores, and dashes.
Option C is valid because it starts with a letter and contains only letters, digits, underscores, and dashes. Option C starts with a digit, which is invalid. Option C contains a space, and Option C contains an exclamation mark, both invalid characters.
Given the following Terraform configuration snippet, how many AWS EC2 instances will be created?
resource "aws_instance" "web" {
count = 3
ami = "ami-12345678"
instance_type = "t2.micro"
}
resource "aws_instance" "db" {
count = 2
ami = "ami-87654321"
instance_type = "t2.micro"
}Count defines how many instances of a resource are created.
The 'web' resource creates 3 instances and the 'db' resource creates 2 instances. Total instances = 3 + 2 = 5.
Which resource naming practice can lead to a security risk in Terraform configurations?
Think about what information might be exposed unintentionally.
Using descriptive names that reveal sensitive environment details (like 'prod-db-password') can expose information to unauthorized users. Generic names or neutral naming conventions reduce this risk.
What happens if you rename a resource block's name in Terraform configuration without using state commands?
Original:
resource "aws_s3_bucket" "mybucket" {
bucket = "example-bucket"
}
Renamed:
resource "aws_s3_bucket" "mybucket_renamed" {
bucket = "example-bucket"
}Think about how Terraform tracks resources in its state file.
Terraform tracks resources by their type and name. Renaming a resource makes Terraform think the old resource was removed and a new one added. It plans to delete the old resource and create a new one unless you use state commands to rename it in the state.