如何使用自定义映像创建 IBM Cloud VSI

How to create an IBM Cloud VSI using a custom image

我想使用 Terraform 使用现有的客户映像创建新的虚拟服务器,就像在 https://cloud.ibm.com/vpc-ext/compute/images 下手动操作一样。 我使用了一个示例代码片段,只替换了图像的名称 (r010-...)。

data "ibm_is_image" "centos" {
   name = "r010-489ff05b-1494-4a05-8b12-c6f44a958859"
}

# Virtual Server Insance
resource "ibm_is_instance" "vsi1" {
   name    = "${local.BASENAME}-vsi1"
   vpc     = ibm_is_vpc.vpc-instance.id
   keys    = [data.ibm_is_ssh_key.ssh_key_id.id]
   zone    = local.ZONE
   image   = data.ibm_is_image.centos.id
   profile = "cx2-2x4"
   
   # References to the subnet and security groups
   primary_network_interface {
     subnet          = ibm_is_subnet.subnet1.id
     security_groups = [ibm_is_security_group.sg1.id]
   }
}

错误信息是:

Error: No image found with name  r010-489ff05b-1494-4a05-8b12-c6f44a958859

好像只能使用public个AWS镜像

你的custom images are private. The visibility is an attribute that you can specify when looking up the data using ibm_is_image.

因此,我建议尝试:

data "ibm_is_image" "centos" {
   name       = "r010-489ff05b-1494-4a05-8b12-c6f44a958859"
   visibility = "private"
}

这里有一个例子:https://github.com/IBM-Cloud/isv-vsi-product-deploy-sample/blob/main/image-map.tf

此 terraform 文件具有不同区域的图像 ID。根据您的 VSI 区域,它将获取图像 ID。

您似乎在此处使用 id 代替 name

data "ibm_is_image" "centos" {
   name = "r010-489ff05b-1494-4a05-8b12-c6f44a958859"
}

尝试使用图像的name

我把名字和身份证弄混了。图像名称是预期的,而不是 id。谢谢!