英文:
How to add dependency via arn in terraform?
问题
我有Terraform代码,用于创建一些AWS资源。例如,我创建一个S3存储桶,并根据它创建另一个资源,或者依赖于这个S3资源。我知道Terraform会确定这个新对象资源依赖于第一个S3存储桶资源,因为我已经将这个=> aws_s3_bucket.s3.id 传递给新资源。我不确定这是ARN、存储桶名称还是Terraform维护的某个内部ID。但是是否可以通过传递ARN或其他内容来添加这种依赖关系呢?
假设我有一个已经在其他地方创建的存储桶名称,我可以在下面的示例中简单地传递它的ARN,所以不是aws_s3_bucket.s3.id,而是传递存储桶名称,如var.bucket name,这样会起作用吗?
我尝试过传递这个=> aws_s3_bucket.s3.id,这样可以工作。但我想知道是否可以传递ARN。
英文:
I have terraform code , to create few aws resources. for example . i create a s3 bucket and create another resource based on or which depends on this s3 resource. I know terraform will figure out that this new object resource is dependent on the first s3 bucket resource, as i have passed this => aws_s3_bucket.s3.id , to the new resource. I'm not sure if this is a arn or bucket name or some intrinsic id that terraform maintains. but is it possible to add such dependency by passing in arn or something else?
so say , i had a bucket name that is already created somewhere else, and I can simply pass its arn in my example below , so instead of aws_s3_bucket.s3.id , i can pass bucket name , as var.bucket name
will that work?
resource "aws_s3_bucket" "s3" {
bucket = "s3-bucket-name"
acl = "private"
...
}
resource "aws_s3_bucket_object" "init" {
bucket = aws_s3_bucket.s3.id
key = "bin.tar.gz"
....
}
I've tried passing this => aws_s3_bucket.s3.id, which works. but want to know if i can pass an arn
答案1
得分: 1
aws_s3_bucket.s3.id
实际上是存储桶名称;aws_s3_bucket_object.init.bucket
预期的是存储桶名称,传递存储桶 ARN 将导致错误;aws_s3_bucket_object.init.bucket
预期的是一个字符串,您可以以任何方式传递它,只要它是有效的字符串存储桶名称,var.bucket
完全可行。
英文:
aws_s3_bucket.s3.id
is actually the bucket name;aws_s3_bucket_object.init.bucket
expects a bucket name, passing a bucket ARN will result in an error;aws_s3_bucket_object.init.bucket
expects a string, it doesn't matter how you pass it there, sovar.bucket
will totally work as long as it's a valid string bucket name.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论