UNPKG

@pulumi/gcp

Version:

A Pulumi package for creating and managing Google Cloud Platform resources.

397 lines • 16.5 kB
"use strict"; // *** WARNING: this file was generated by pulumi-language-nodejs. *** // *** Do not edit by hand unless you're certain you know what you are doing! *** Object.defineProperty(exports, "__esModule", { value: true }); exports.InstanceTemplate = void 0; const pulumi = require("@pulumi/pulumi"); const utilities = require("../utilities"); /** * > **Note**: Global instance templates can be used in any region. To lower the impact of outages outside your region and gain data residency within your region, use google_compute_region_instance_template. * * Manages a VM instance template resource within GCE. For more information see * [the official documentation](https://cloud.google.com/compute/docs/instance-templates) * and * [API](https://cloud.google.com/compute/docs/reference/latest/instanceTemplates). * * ## Example Usage * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const _default = new gcp.serviceaccount.Account("default", { * accountId: "service-account-id", * displayName: "Service Account", * }); * const myImage = gcp.compute.getImage({ * family: "debian-11", * project: "debian-cloud", * }); * const foobar = new gcp.compute.Disk("foobar", { * name: "existing-disk", * image: myImage.then(myImage => myImage.selfLink), * size: 10, * type: "pd-ssd", * zone: "us-central1-a", * }); * const dailyBackup = new gcp.compute.ResourcePolicy("daily_backup", { * name: "every-day-4am", * region: "us-central1", * snapshotSchedulePolicy: { * schedule: { * dailySchedule: { * daysInCycle: 1, * startTime: "04:00", * }, * }, * }, * }); * const defaultInstanceTemplate = new gcp.compute.InstanceTemplate("default", { * name: "appserver-template", * description: "This template is used to create app server instances.", * tags: [ * "foo", * "bar", * ], * labels: { * environment: "dev", * }, * instanceDescription: "description assigned to instances", * machineType: "e2-medium", * canIpForward: false, * scheduling: { * automaticRestart: true, * onHostMaintenance: "MIGRATE", * }, * disks: [ * { * sourceImage: "debian-cloud/debian-11", * autoDelete: true, * boot: true, * resourcePolicies: dailyBackup.id, * }, * { * source: foobar.name, * autoDelete: false, * boot: false, * }, * ], * networkInterfaces: [{ * network: "default", * }], * metadata: { * foo: "bar", * }, * serviceAccount: { * email: _default.email, * scopes: ["cloud-platform"], * }, * }); * ``` * * ### Automatic Envoy Deployment * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const _default = gcp.compute.getDefaultServiceAccount({}); * const myImage = gcp.compute.getImage({ * family: "debian-11", * project: "debian-cloud", * }); * const foobar = new gcp.compute.InstanceTemplate("foobar", { * name: "appserver-template", * machineType: "e2-medium", * canIpForward: false, * tags: [ * "foo", * "bar", * ], * disks: [{ * sourceImage: myImage.then(myImage => myImage.selfLink), * autoDelete: true, * boot: true, * }], * networkInterfaces: [{ * network: "default", * }], * scheduling: { * preemptible: false, * automaticRestart: true, * }, * metadata: { * "gce-software-declaration": `{ * "softwareRecipes": [{ * "name": "install-gce-service-proxy-agent", * "desired_state": "INSTALLED", * "installSteps": [{ * "scriptRun": { * "script": "#! /bin/bash\\nZONE=(curl --silent http://metadata.google.internal/computeMetadata/v1/instance/zone -H Metadata-Flavor:Google | cut -d/ -f4 )\\nexport SERVICE_PROXY_AGENT_DIRECTORY=(mktemp -d)\\nsudo gsutil cp gs://gce-service-proxy-"ZONE"/service-proxy-agent/releases/service-proxy-agent-0.2.tgz "SERVICE_PROXY_AGENT_DIRECTORY" || sudo gsutil cp gs://gce-service-proxy/service-proxy-agent/releases/service-proxy-agent-0.2.tgz "SERVICE_PROXY_AGENT_DIRECTORY"\\nsudo tar -xzf "SERVICE_PROXY_AGENT_DIRECTORY"/service-proxy-agent-0.2.tgz -C "SERVICE_PROXY_AGENT_DIRECTORY"\\n"SERVICE_PROXY_AGENT_DIRECTORY"/service-proxy-agent/service-proxy-agent-bootstrap.sh" * } * }] * }] * } * `, * "gce-service-proxy": `{ * "api-version": "0.2", * "proxy-spec": { * "proxy-port": 15001, * "network": "my-network", * "tracing": "ON", * "access-log": "/var/log/envoy/access.log" * } * "service": { * "serving-ports": [80, 81] * }, * "labels": { * "app_name": "bookserver_app", * "app_version": "STABLE" * } * } * `, * "enable-guest-attributes": "true", * "enable-osconfig": "true", * }, * serviceAccount: { * email: _default.then(_default => _default.email), * scopes: ["cloud-platform"], * }, * labels: { * "gce-service-proxy": "on", * }, * }); * ``` * * ### Confidential Computing * * Example with [Confidential Mode](https://cloud.google.com/confidential-computing/confidential-vm/docs/confidential-vm-overview) activated. * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const _default = new gcp.serviceaccount.Account("default", { * accountId: "my-custom-sa", * displayName: "Custom SA for VM Instance", * }); * const confidentialInstanceTemplate = new gcp.compute.InstanceTemplate("confidential_instance_template", { * networkInterfaces: [{ * accessConfigs: [{}], * network: "default", * }], * name: "my-confidential-instance-template", * region: "us-central1", * machineType: "n2d-standard-2", * minCpuPlatform: "AMD Milan", * confidentialInstanceConfig: { * enableConfidentialCompute: true, * confidentialInstanceType: "SEV", * }, * disks: [{ * sourceImage: "ubuntu-os-cloud/ubuntu-2204-lts", * }], * serviceAccount: { * email: _default.email, * scopes: ["cloud-platform"], * }, * }); * ``` * * ## Deploying the Latest Image * * A common way to use instance templates and managed instance groups is to deploy the * latest image in a family, usually the latest build of your application. There are two * ways to do this in the provider, and they have their pros and cons. The difference ends * up being in how "latest" is interpreted. You can either deploy the latest image available * when the provider runs, or you can have each instance check what the latest image is when * it's being created, either as part of a scaling event or being rebuilt by the instance * group manager. * * If you're not sure, we recommend deploying the latest image available when the provider runs, * because this means all the instances in your group will be based on the same image, always, * and means that no upgrades or changes to your instances happen outside of a `pulumi up`. * You can achieve this by using the `gcp.compute.Image` * data source, which will retrieve the latest image on every `pulumi apply`, and will update * the template to use that specific image: * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const myImage = gcp.compute.getImage({ * family: "debian-11", * project: "debian-cloud", * }); * const instanceTemplate = new gcp.compute.InstanceTemplate("instance_template", { * namePrefix: "instance-template-", * machineType: "e2-medium", * region: "us-central1", * disks: [{ * sourceImage: myImage.then(myImage => myImage.selfLink), * }], * }); * ``` * * To have instances update to the latest on every scaling event or instance re-creation, * use the family as the image for the disk, and it will use GCP's default behavior, setting * the image for the template to the family: * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const instanceTemplate = new gcp.compute.InstanceTemplate("instance_template", { * namePrefix: "instance-template-", * machineType: "e2-medium", * region: "us-central1", * disks: [{ * sourceImage: "debian-cloud/debian-11", * }], * }); * ``` * * ## Import * * Instance templates can be imported using any of these accepted formats: * * * `projects/{{project}}/global/instanceTemplates/{{name}}` * * * `{{project}}/{{name}}` * * * `{{name}}` * * When using the `pulumi import` command, instance templates can be imported using one of the formats above. For example: * * ```sh * $ pulumi import gcp:compute/instanceTemplate:InstanceTemplate default projects/{{project}}/global/instanceTemplates/{{name}} * ``` * * ```sh * $ pulumi import gcp:compute/instanceTemplate:InstanceTemplate default {{project}}/{{name}} * ``` * * ```sh * $ pulumi import gcp:compute/instanceTemplate:InstanceTemplate default {{name}} * ``` */ class InstanceTemplate extends pulumi.CustomResource { /** * Get an existing InstanceTemplate resource's state with the given name, ID, and optional extra * properties used to qualify the lookup. * * @param name The _unique_ name of the resulting resource. * @param id The _unique_ provider ID of the resource to lookup. * @param state Any extra arguments used during the lookup. * @param opts Optional settings to control the behavior of the CustomResource. */ static get(name, id, state, opts) { return new InstanceTemplate(name, state, { ...opts, id: id }); } /** * Returns true if the given object is an instance of InstanceTemplate. This is designed to work even * when multiple copies of the Pulumi SDK have been loaded into the same process. */ static isInstance(obj) { if (obj === undefined || obj === null) { return false; } return obj['__pulumiType'] === InstanceTemplate.__pulumiType; } constructor(name, argsOrState, opts) { let resourceInputs = {}; opts = opts || {}; if (opts.id) { const state = argsOrState; resourceInputs["advancedMachineFeatures"] = state?.advancedMachineFeatures; resourceInputs["canIpForward"] = state?.canIpForward; resourceInputs["confidentialInstanceConfig"] = state?.confidentialInstanceConfig; resourceInputs["creationTimestamp"] = state?.creationTimestamp; resourceInputs["description"] = state?.description; resourceInputs["disks"] = state?.disks; resourceInputs["effectiveLabels"] = state?.effectiveLabels; resourceInputs["enableDisplay"] = state?.enableDisplay; resourceInputs["guestAccelerators"] = state?.guestAccelerators; resourceInputs["instanceDescription"] = state?.instanceDescription; resourceInputs["keyRevocationActionType"] = state?.keyRevocationActionType; resourceInputs["labels"] = state?.labels; resourceInputs["machineType"] = state?.machineType; resourceInputs["metadata"] = state?.metadata; resourceInputs["metadataFingerprint"] = state?.metadataFingerprint; resourceInputs["metadataStartupScript"] = state?.metadataStartupScript; resourceInputs["minCpuPlatform"] = state?.minCpuPlatform; resourceInputs["name"] = state?.name; resourceInputs["namePrefix"] = state?.namePrefix; resourceInputs["networkInterfaces"] = state?.networkInterfaces; resourceInputs["networkPerformanceConfig"] = state?.networkPerformanceConfig; resourceInputs["numericId"] = state?.numericId; resourceInputs["partnerMetadata"] = state?.partnerMetadata; resourceInputs["project"] = state?.project; resourceInputs["pulumiLabels"] = state?.pulumiLabels; resourceInputs["region"] = state?.region; resourceInputs["reservationAffinity"] = state?.reservationAffinity; resourceInputs["resourceManagerTags"] = state?.resourceManagerTags; resourceInputs["resourcePolicies"] = state?.resourcePolicies; resourceInputs["scheduling"] = state?.scheduling; resourceInputs["selfLink"] = state?.selfLink; resourceInputs["selfLinkUnique"] = state?.selfLinkUnique; resourceInputs["serviceAccount"] = state?.serviceAccount; resourceInputs["shieldedInstanceConfig"] = state?.shieldedInstanceConfig; resourceInputs["tags"] = state?.tags; resourceInputs["tagsFingerprint"] = state?.tagsFingerprint; } else { const args = argsOrState; if (args?.disks === undefined && !opts.urn) { throw new Error("Missing required property 'disks'"); } if (args?.machineType === undefined && !opts.urn) { throw new Error("Missing required property 'machineType'"); } resourceInputs["advancedMachineFeatures"] = args?.advancedMachineFeatures; resourceInputs["canIpForward"] = args?.canIpForward; resourceInputs["confidentialInstanceConfig"] = args?.confidentialInstanceConfig; resourceInputs["description"] = args?.description; resourceInputs["disks"] = args?.disks; resourceInputs["enableDisplay"] = args?.enableDisplay; resourceInputs["guestAccelerators"] = args?.guestAccelerators; resourceInputs["instanceDescription"] = args?.instanceDescription; resourceInputs["keyRevocationActionType"] = args?.keyRevocationActionType; resourceInputs["labels"] = args?.labels; resourceInputs["machineType"] = args?.machineType; resourceInputs["metadata"] = args?.metadata; resourceInputs["metadataStartupScript"] = args?.metadataStartupScript; resourceInputs["minCpuPlatform"] = args?.minCpuPlatform; resourceInputs["name"] = args?.name; resourceInputs["namePrefix"] = args?.namePrefix; resourceInputs["networkInterfaces"] = args?.networkInterfaces; resourceInputs["networkPerformanceConfig"] = args?.networkPerformanceConfig; resourceInputs["partnerMetadata"] = args?.partnerMetadata; resourceInputs["project"] = args?.project; resourceInputs["region"] = args?.region; resourceInputs["reservationAffinity"] = args?.reservationAffinity; resourceInputs["resourceManagerTags"] = args?.resourceManagerTags; resourceInputs["resourcePolicies"] = args?.resourcePolicies; resourceInputs["scheduling"] = args?.scheduling; resourceInputs["serviceAccount"] = args?.serviceAccount; resourceInputs["shieldedInstanceConfig"] = args?.shieldedInstanceConfig; resourceInputs["tags"] = args?.tags; resourceInputs["creationTimestamp"] = undefined /*out*/; resourceInputs["effectiveLabels"] = undefined /*out*/; resourceInputs["metadataFingerprint"] = undefined /*out*/; resourceInputs["numericId"] = undefined /*out*/; resourceInputs["pulumiLabels"] = undefined /*out*/; resourceInputs["selfLink"] = undefined /*out*/; resourceInputs["selfLinkUnique"] = undefined /*out*/; resourceInputs["tagsFingerprint"] = undefined /*out*/; } opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts); const secretOpts = { additionalSecretOutputs: ["effectiveLabels", "pulumiLabels"] }; opts = pulumi.mergeOptions(opts, secretOpts); super(InstanceTemplate.__pulumiType, name, resourceInputs, opts); } } exports.InstanceTemplate = InstanceTemplate; /** @internal */ InstanceTemplate.__pulumiType = 'gcp:compute/instanceTemplate:InstanceTemplate'; //# sourceMappingURL=instanceTemplate.js.map