I have multiple Terraform projects, in project A I create a bucket like this:
resource "aws_s3_bucket" "s3_bucket" {
bucket_prefix = "s3-bucket-"
}
this create a bucket with a random characters in the ends:
s3-bucket-20230927170795326300000001
Now I want to refer the name of this bucket in another project B, so I create:
data "aws_s3_bucket" "s3_bucket" {
bucket = "s3-bucket-"
}
But this will not work because the name is random, is there any trick to solve this?
2
Answers
You can use the
bucket
argument in the data source for that but with a full bucket name, e.g:You can try importing the bucket into project B:
https://developer.hashicorp.com/terraform/cli/import