UNPKG

@pulumi/gcp

Version:

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

395 lines • 17.6 kB
"use strict"; // *** WARNING: this file was generated by the Pulumi Terraform Bridge (tfgen) Tool. *** // *** 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-2004-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, Object.assign(Object.assign({}, 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 ? state.advancedMachineFeatures : undefined; resourceInputs["canIpForward"] = state ? state.canIpForward : undefined; resourceInputs["confidentialInstanceConfig"] = state ? state.confidentialInstanceConfig : undefined; resourceInputs["creationTimestamp"] = state ? state.creationTimestamp : undefined; resourceInputs["description"] = state ? state.description : undefined; resourceInputs["disks"] = state ? state.disks : undefined; resourceInputs["effectiveLabels"] = state ? state.effectiveLabels : undefined; resourceInputs["enableDisplay"] = state ? state.enableDisplay : undefined; resourceInputs["guestAccelerators"] = state ? state.guestAccelerators : undefined; resourceInputs["instanceDescription"] = state ? state.instanceDescription : undefined; resourceInputs["keyRevocationActionType"] = state ? state.keyRevocationActionType : undefined; resourceInputs["labels"] = state ? state.labels : undefined; resourceInputs["machineType"] = state ? state.machineType : undefined; resourceInputs["metadata"] = state ? state.metadata : undefined; resourceInputs["metadataFingerprint"] = state ? state.metadataFingerprint : undefined; resourceInputs["metadataStartupScript"] = state ? state.metadataStartupScript : undefined; resourceInputs["minCpuPlatform"] = state ? state.minCpuPlatform : undefined; resourceInputs["name"] = state ? state.name : undefined; resourceInputs["namePrefix"] = state ? state.namePrefix : undefined; resourceInputs["networkInterfaces"] = state ? state.networkInterfaces : undefined; resourceInputs["networkPerformanceConfig"] = state ? state.networkPerformanceConfig : undefined; resourceInputs["partnerMetadata"] = state ? state.partnerMetadata : undefined; resourceInputs["project"] = state ? state.project : undefined; resourceInputs["pulumiLabels"] = state ? state.pulumiLabels : undefined; resourceInputs["region"] = state ? state.region : undefined; resourceInputs["reservationAffinity"] = state ? state.reservationAffinity : undefined; resourceInputs["resourceManagerTags"] = state ? state.resourceManagerTags : undefined; resourceInputs["resourcePolicies"] = state ? state.resourcePolicies : undefined; resourceInputs["scheduling"] = state ? state.scheduling : undefined; resourceInputs["selfLink"] = state ? state.selfLink : undefined; resourceInputs["selfLinkUnique"] = state ? state.selfLinkUnique : undefined; resourceInputs["serviceAccount"] = state ? state.serviceAccount : undefined; resourceInputs["shieldedInstanceConfig"] = state ? state.shieldedInstanceConfig : undefined; resourceInputs["tags"] = state ? state.tags : undefined; resourceInputs["tagsFingerprint"] = state ? state.tagsFingerprint : undefined; } else { const args = argsOrState; if ((!args || args.disks === undefined) && !opts.urn) { throw new Error("Missing required property 'disks'"); } if ((!args || args.machineType === undefined) && !opts.urn) { throw new Error("Missing required property 'machineType'"); } resourceInputs["advancedMachineFeatures"] = args ? args.advancedMachineFeatures : undefined; resourceInputs["canIpForward"] = args ? args.canIpForward : undefined; resourceInputs["confidentialInstanceConfig"] = args ? args.confidentialInstanceConfig : undefined; resourceInputs["description"] = args ? args.description : undefined; resourceInputs["disks"] = args ? args.disks : undefined; resourceInputs["enableDisplay"] = args ? args.enableDisplay : undefined; resourceInputs["guestAccelerators"] = args ? args.guestAccelerators : undefined; resourceInputs["instanceDescription"] = args ? args.instanceDescription : undefined; resourceInputs["keyRevocationActionType"] = args ? args.keyRevocationActionType : undefined; resourceInputs["labels"] = args ? args.labels : undefined; resourceInputs["machineType"] = args ? args.machineType : undefined; resourceInputs["metadata"] = args ? args.metadata : undefined; resourceInputs["metadataStartupScript"] = args ? args.metadataStartupScript : undefined; resourceInputs["minCpuPlatform"] = args ? args.minCpuPlatform : undefined; resourceInputs["name"] = args ? args.name : undefined; resourceInputs["namePrefix"] = args ? args.namePrefix : undefined; resourceInputs["networkInterfaces"] = args ? args.networkInterfaces : undefined; resourceInputs["networkPerformanceConfig"] = args ? args.networkPerformanceConfig : undefined; resourceInputs["partnerMetadata"] = args ? args.partnerMetadata : undefined; resourceInputs["project"] = args ? args.project : undefined; resourceInputs["region"] = args ? args.region : undefined; resourceInputs["reservationAffinity"] = args ? args.reservationAffinity : undefined; resourceInputs["resourceManagerTags"] = args ? args.resourceManagerTags : undefined; resourceInputs["resourcePolicies"] = args ? args.resourcePolicies : undefined; resourceInputs["scheduling"] = args ? args.scheduling : undefined; resourceInputs["serviceAccount"] = args ? args.serviceAccount : undefined; resourceInputs["shieldedInstanceConfig"] = args ? args.shieldedInstanceConfig : undefined; resourceInputs["tags"] = args ? args.tags : undefined; resourceInputs["creationTimestamp"] = undefined /*out*/; resourceInputs["effectiveLabels"] = undefined /*out*/; resourceInputs["metadataFingerprint"] = 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