resource "google_artifact_registry_repository" "main" {
# this is the repo for hosting my Docker images
# it does not have a data source afaik because it is beta
}
对于我的 google_artifact_registry_repository 资源,我的一个方法是使用数据源块来执行 Terraform apply 并查看是否返回值。但问题在于 google_artifact_registry_repository 没有数据源块。因此,我必须使用资源块创建此资源,并且每个 CI/CD 构建都可以依赖于它的存在。是否有一种解决方法可以读取其存在?
resource "google_storage_bucket" "bucket" {
# bucket containing the folder below
}
resource "google_storage_bucket_object" "content_folder" {
# folder containing Terraform default.tfstate for my Cloud Run Service
}
对于我的google_storage_bucket和google_storage_bucket_object资源,如果我使用数据源块执行Terraform应用程序以查看这些资源是否存在,则遇到的一个问题是当找不到资源时,Terraform需要很长时间才能返回状态。如果我能够在10-15秒内确定资源是否存在,那就太好了,如果不存在,就假定这些资源不存在。
data "google_storage_bucket" "bucket" {
# bucket containing the folder below
}
output bucket {
value = data.google_storage_bucket.bucket
}
当资源存在时,我可以使用 Terraform 输出桶来获取该值。如果资源不存在,Terraform 返回响应的时间太长了。对此有什么建议吗?