Terraform: aws_s3_bucket.id attribute is misnamed for what it actually returns.

Created on 3 Nov 2016  ·  4Comments  ·  Source: hashicorp/terraform

Terraform Version

$ terraform -v
Terraform v0.7.7

Affected Resource(s)

  • as_s3_bucket resource (and associated documentation)

The .id attribute is misnamed for what it actually returns.

Expected Behavior

The following attributes are exported:
id - The name of the bucket.

This is counter-intuitive and inconsistent. Throughout all of terraform the .id of an AWS object is the actual AWS object ID. NOT the name.

This attribute is more correct if changed to .name and .id were either the actual AWS object ID, or perhaps the ARN (though, there is, correctly, a .arn attribute already).

bug provideaws

Most helpful comment

Bringing Sexy back!
I do agree the use of "id" is confusing. When working with AWS resources if you hear/read the word ID you expect a hex hash that identifies the resource.

I spent some time trying to figure out why my output resource was giving me the name and not a "hash" for the s3 bucket. Yes I know buckets do not have a hash BUT after writing:
"aws_s3_bucket.b.id" in my output resource, It makes me expect a hash.

Just my 2 cents.

All 4 comments

Hey @pll – for AWS S3, the Bucket name is the ID. S3 Bucket names are globally unique, regardless of region, and the AWS API provides no other ID for them. The API doesn't even return an ARN for the bucket, we have to construct it ourselves in the code.

I understand the confusion in the naming here though, however for this particular resource it is accurate.

Throughout all of terraform the .id of an AWS object is the actual AWS object ID. NOT the name.

We certainly would like to maintain this but there are exceptions. AutoScaling, S3, and CloudWatch are just a few where we do use name as the ID (for better or worse). In some of those scenarios, the ID is the Name.

Hey @catsby,

I disagree that this is accurate for this resource. What is returned is a name, not an id.

The boto3 api calls it a name: http://boto3.readthedocs.io/en/latest/reference/services/s3.html#bucket
So does the Go API: https://docs.aws.amazon.com/sdk-for-go/api/service/s3/#example_S3_GetObject
As does the JAVA API: http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/AmazonS3Client.html#createBucket-java.lang.String-

No where that I can find in the official AWS documentation does Amazon refer to a bucket name as an "id". It is consistently bucketName. Terraform is inconsistent with AWS on this matter, and therefore, will cause confusion.

Bringing Sexy back!
I do agree the use of "id" is confusing. When working with AWS resources if you hear/read the word ID you expect a hex hash that identifies the resource.

I spent some time trying to figure out why my output resource was giving me the name and not a "hash" for the s3 bucket. Yes I know buckets do not have a hash BUT after writing:
"aws_s3_bucket.b.id" in my output resource, It makes me expect a hash.

Just my 2 cents.

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings