Reputation: 309
In the terraform documentation we are provided with the markup as attached below. I cant find any mention of what the purpose of the field "b" is and how it should be used in general.
resource "aws_s3_bucket" "b" {
bucket = "my_tf_test_bucket"
}
resource "aws_s3_bucket_policy" "b" {
bucket = "${aws_s3_bucket.b.id}"
policy =<<POLICY
{
"Version": "2012-10-17",
"Id": "MYBUCKETPOLICY",
"Statement": [
{
"Sid": "IPAllow",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": "arn:aws:s3:::my_tf_test_bucket/*",
"Condition": {
"IpAddress": {"aws:SourceIp": "8.8.8.8/32"}
}
}
]
}
POLICY
}
Upvotes: 1
Views: 825
Reputation: 921
"b" is simply the NAME of the resource that you are creating.
Terraform resources are defined in "blocks", and each resource block creates a resource of the given TYPE (first parameter) and NAME (second parameter). The combination of the type and name must be unique.
So, in your example, you are creating a resource of TYPE aws_s3_bucket
and NAME b
.
Each resource defined has an id
, that you can use to refer this resource in other resources, using a syntax like TYPE.NAME.id, for example ${aws_s3_bucket.b.id}
You can find further information in the doc here: https://www.terraform.io/docs/configuration/resources.html
Upvotes: 3