使用 Compute Engine API 连接器创建 Compute Engine 虚拟机实例

根据通过 Google 表单收集的规范调用 Compute Engine API 连接器,以创建 Compute Engine 虚拟机实例。

深入探索

如需查看包含此代码示例的详细文档,请参阅以下内容:

代码示例

YAML

main:
   params: [input]
   steps:
   - init:
       assign:
            - projectId: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
            - zone: ${input.zone}
            - machineType: ${input.machineType}
            - diskSize: ${input.diskSize}
            - imageProject: ${input.imageProject}
            - imageFamily: ${input.imageFamily}
            - vmName: ${input.vmName}
            - email: ${input.email}
   - createResource:
       call: googleapis.compute.v1.instances.insert
       args:
           project: ${projectId}
           zone: ${zone}
           body:
               name: ${vmName}
               machineType: ${"projects/" + projectId + "/zones/" + zone + "/machineTypes/" + machineType}
               disks:
                - initializeParams:
                    diskSizeGb: ${diskSize}
                    sourceImage: ${"projects/" + imageProject + "/global/images/family/" + imageFamily}
                  type: PERSISTENT
                  boot: true
                  autoDelete: true
               networkInterfaces:
                - network: "global/networks/default"
       result: insertResult
   - retStep:
       return: ${insertResult}

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器