如何使用Terraform为Google Compute Image设置区域/多区域位置
你需要在google_compute_image资源块中添加storage_locations配置项,该参数为数组类型,可用于指定镜像的存储位置,支持单区域(regional)和多区域(multi-regional)两种取值。
修改后的配置示例如下:
resource "google_compute_image" "default" { name = "myimage-release-2021" family = "myimage" # 存储位置配置 # 单区域示例:storage_locations = ["asia-east1"] # 多区域示例:storage_locations = ["asia"] storage_locations = [var.image_storage_location] source_disk = "projects/${var.provider_project}/zones/${var.provider_zone}/disks/${var.instances.instance_name}" }
补充说明:
- 若要创建区域镜像,直接传入对应GCP区域ID即可,例如
us-central1、europe-west1 - 若要创建多区域镜像,传入对应多区域标识符即可,例如
us(美国多区域)、eu(欧洲多区域)、asia(亚太多区域) - 该参数仅支持传入单个值,不能同时指定多个不同的存储位置
- 若不主动配置该参数,镜像默认会存储在源磁盘所属区域对应的多区域中
内容的提问来源于stack exchange,提问作者adhithia
相关产品推荐
相关产品推荐

