Add a second bucket
Learn
A second resource
A plan reflects everything the configuration would create. Add a second resource block and the count grows:
Plan: 2 to add, 0 to change, 0 to destroy.
Two things must be unique, at two different levels:
- the local name (
first,second) only within this configuration: it's how Terraform tells the two blocks apart (aws_s3_bucket.second); - the bucket name across all of AWS, because S3 bucket names are global.
A resource can also expose values with an output, e.g.:
output "bucket_name" {
value = aws_s3_bucket.first.bucket
}
Outputs show up under "Changes to Outputs" in the plan — try adding one once both buckets are planning cleanly.
Your task
Declare a second aws_s3_bucket — give it a new local name (such as second) and a different, unique bucket value — then re-run plan. Two resources should now be planned to add.
Interview prep
Two things to be fluent in before a first infra interview.
What's the difference between validate and plan?
validate is an offline syntax/consistency check. plan resolves the provider and computes the diff between your configuration and reality, printing what it would add/change/destroy — still without making any changes.
In resource "aws_s3_bucket" "first", what are the two labels?
The first is the resource type (aws_s3_bucket, provided by the AWS provider); the second is your local name (first), used to reference the resource elsewhere as aws_s3_bucket.first.<attr>.