UNPKG

@pulumi/gcp

Version:

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

531 lines (530 loc) • 19.1 kB
import * as pulumi from "@pulumi/pulumi"; import * as inputs from "../types/input"; import * as outputs from "../types/output"; /** * A Cloud Run service has a unique endpoint and autoscales containers. * * To get more information about Service, see: * * * [API documentation](https://cloud.google.com/run/docs/reference/rest/v1/namespaces.services) * * How-to Guides * * [Official Documentation](https://cloud.google.com/run/docs/) * * > **Warning:** We recommend using the `gcp.cloudrunv2.Service` resource which offers a better * developer experience and broader support of Cloud Run features. * * ## Example Usage * * ### Cloud Run Service Pubsub * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const _default = new gcp.cloudrun.Service("default", { * name: "cloud_run_service_name", * location: "us-central1", * template: { * spec: { * containers: [{ * image: "gcr.io/cloudrun/hello", * }], * }, * }, * traffics: [{ * percent: 100, * latestRevision: true, * }], * }); * const sa = new gcp.serviceaccount.Account("sa", { * accountId: "cloud-run-pubsub-invoker", * displayName: "Cloud Run Pub/Sub Invoker", * }); * const binding = new gcp.cloudrun.IamBinding("binding", { * location: _default.location, * service: _default.name, * role: "roles/run.invoker", * members: [pulumi.interpolate`serviceAccount:${sa.email}`], * }); * const project = new gcp.projects.IAMBinding("project", { * role: "roles/iam.serviceAccountTokenCreator", * members: [pulumi.interpolate`serviceAccount:${sa.email}`], * }); * const topic = new gcp.pubsub.Topic("topic", {name: "pubsub_topic"}); * const subscription = new gcp.pubsub.Subscription("subscription", { * name: "pubsub_subscription", * topic: topic.name, * pushConfig: { * pushEndpoint: _default.statuses.apply(statuses => statuses[0].url), * oidcToken: { * serviceAccountEmail: sa.email, * }, * attributes: { * "x-goog-version": "v1", * }, * }, * }); * ``` * * ### Cloud Run Service Basic * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const _default = new gcp.cloudrun.Service("default", { * name: "cloudrun-srv", * location: "us-central1", * template: { * spec: { * containers: [{ * image: "us-docker.pkg.dev/cloudrun/container/hello", * }], * }, * }, * traffics: [{ * percent: 100, * latestRevision: true, * }], * }); * ``` * ### Cloud Run Service Gpu * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const _default = new gcp.cloudrun.Service("default", { * name: "cloudrun-srv", * location: "us-central1", * metadata: { * annotations: { * "run.googleapis.com/launch-stage": "BETA", * }, * }, * template: { * metadata: { * annotations: { * "autoscaling.knative.dev/maxScale": "1", * "run.googleapis.com/cpu-throttling": "false", * }, * }, * spec: { * containers: [{ * image: "gcr.io/cloudrun/hello", * resources: { * limits: { * cpu: "4", * memory: "16Gi", * "nvidia.com/gpu": "1", * }, * }, * }], * nodeSelector: { * "run.googleapis.com/accelerator": "nvidia-l4", * }, * }, * }, * }); * ``` * ### Cloud Run Service Sql * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const instance = new gcp.sql.DatabaseInstance("instance", { * name: "cloudrun-sql", * region: "us-east1", * databaseVersion: "MYSQL_5_7", * settings: { * tier: "db-f1-micro", * }, * deletionProtection: true, * }); * const _default = new gcp.cloudrun.Service("default", { * name: "cloudrun-srv", * location: "us-central1", * template: { * spec: { * containers: [{ * image: "us-docker.pkg.dev/cloudrun/container/hello", * }], * }, * metadata: { * annotations: { * "autoscaling.knative.dev/maxScale": "1000", * "run.googleapis.com/cloudsql-instances": instance.connectionName, * "run.googleapis.com/client-name": "demo", * }, * }, * }, * autogenerateRevisionName: true, * }); * ``` * ### Cloud Run Service Noauth * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const _default = new gcp.cloudrun.Service("default", { * name: "cloudrun-srv", * location: "us-central1", * template: { * spec: { * containers: [{ * image: "us-docker.pkg.dev/cloudrun/container/hello", * }], * }, * }, * }); * const noauth = gcp.organizations.getIAMPolicy({ * bindings: [{ * role: "roles/run.invoker", * members: ["allUsers"], * }], * }); * const noauthIamPolicy = new gcp.cloudrun.IamPolicy("noauth", { * location: _default.location, * project: _default.project, * service: _default.name, * policyData: noauth.then(noauth => noauth.policyData), * }); * ``` * ### Cloud Run Service Probes * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const _default = new gcp.cloudrun.Service("default", { * name: "cloudrun-srv", * location: "us-central1", * template: { * spec: { * containers: [{ * image: "us-docker.pkg.dev/cloudrun/container/hello", * startupProbe: { * initialDelaySeconds: 0, * timeoutSeconds: 1, * periodSeconds: 3, * failureThreshold: 1, * tcpSocket: { * port: 8080, * }, * }, * livenessProbe: { * httpGet: { * path: "/", * }, * }, * }], * }, * }, * traffics: [{ * percent: 100, * latestRevision: true, * }], * }); * ``` * ### Cloud Run Service Multicontainer * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const _default = new gcp.cloudrun.Service("default", { * name: "cloudrun-srv", * location: "us-central1", * template: { * metadata: { * annotations: { * "run.googleapis.com/container-dependencies": JSON.stringify({ * "hello-1": ["hello-2"], * }), * }, * }, * spec: { * containers: [ * { * name: "hello-1", * ports: [{ * containerPort: 8080, * }], * image: "us-docker.pkg.dev/cloudrun/container/hello", * volumeMounts: [{ * name: "shared-volume", * mountPath: "/mnt/shared", * }], * }, * { * name: "hello-2", * image: "us-docker.pkg.dev/cloudrun/container/hello", * envs: [{ * name: "PORT", * value: "8081", * }], * startupProbe: { * httpGet: { * port: 8081, * }, * }, * volumeMounts: [{ * name: "shared-volume", * mountPath: "/mnt/shared", * }], * }, * ], * volumes: [{ * name: "shared-volume", * emptyDir: { * medium: "Memory", * sizeLimit: "128Mi", * }, * }], * }, * }, * }); * ``` * ### Cloud Run Service Iap * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const _default = new gcp.cloudrun.Service("default", { * name: "cloudrun-srv", * location: "us-central1", * metadata: { * annotations: { * "run.googleapis.com/launch-stage": "BETA", * "run.googleapis.com/iap-enabled": "true", * }, * }, * template: { * spec: { * containers: [{ * image: "gcr.io/cloudrun/hello", * }], * }, * }, * }); * ``` * * ## Import * * Service can be imported using any of these accepted formats: * * * `locations/{{location}}/namespaces/{{project}}/services/{{name}}` * * * `{{location}}/{{project}}/{{name}}` * * * `{{location}}/{{name}}` * * When using the `pulumi import` command, Service can be imported using one of the formats above. For example: * * ```sh * $ pulumi import gcp:cloudrun/service:Service default locations/{{location}}/namespaces/{{project}}/services/{{name}} * ``` * * ```sh * $ pulumi import gcp:cloudrun/service:Service default {{location}}/{{project}}/{{name}} * ``` * * ```sh * $ pulumi import gcp:cloudrun/service:Service default {{location}}/{{name}} * ``` */ export declare class Service extends pulumi.CustomResource { /** * Get an existing Service 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: string, id: pulumi.Input<pulumi.ID>, state?: ServiceState, opts?: pulumi.CustomResourceOptions): Service; /** * Returns true if the given object is an instance of Service. This is designed to work even * when multiple copies of the Pulumi SDK have been loaded into the same process. */ static isInstance(obj: any): obj is Service; /** * If set to `true`, the revision name (template.metadata.name) will be omitted and * autogenerated by Cloud Run. This cannot be set to `true` while `template.metadata.name` * is also set. * (For legacy support, if `template.metadata.name` is unset in state while * this field is set to false, the revision name will still autogenerate.) */ readonly autogenerateRevisionName: pulumi.Output<boolean | undefined>; /** * The location of the cloud run instance. eg us-central1 */ readonly location: pulumi.Output<string>; /** * Metadata associated with this Service, including name, namespace, labels, * and annotations. * Structure is documented below. */ readonly metadata: pulumi.Output<outputs.cloudrun.ServiceMetadata>; /** * Name must be unique within a Google Cloud project and region. * Is required when creating resources. Name is primarily intended * for creation idempotence and configuration definition. Cannot be updated. * More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names */ readonly name: pulumi.Output<string>; /** * The ID of the project in which the resource belongs. * If it is not provided, the provider project is used. */ readonly project: pulumi.Output<string>; /** * (Output) * Status of the condition, one of True, False, Unknown. */ readonly statuses: pulumi.Output<outputs.cloudrun.ServiceStatus[]>; /** * template holds the latest specification for the Revision to * be stamped out. The template references the container image, and may also * include labels and annotations that should be attached to the Revision. * To correlate a Revision, and/or to force a Revision to be created when the * spec doesn't otherwise change, a nonce label may be provided in the * template metadata. For more details, see: * https://github.com/knative/serving/blob/main/docs/client-conventions.md#associate-modifications-with-revisions * Cloud Run does not currently support referencing a build that is * responsible for materializing the container image from source. * Structure is documented below. */ readonly template: pulumi.Output<outputs.cloudrun.ServiceTemplate | undefined>; /** * Traffic specifies how to distribute traffic over a collection of Knative Revisions * and Configurations * Structure is documented below. */ readonly traffics: pulumi.Output<outputs.cloudrun.ServiceTraffic[]>; /** * Create a Service resource with the given unique name, arguments, and options. * * @param name The _unique_ name of the resource. * @param args The arguments to use to populate this resource's properties. * @param opts A bag of options that control this resource's behavior. */ constructor(name: string, args: ServiceArgs, opts?: pulumi.CustomResourceOptions); } /** * Input properties used for looking up and filtering Service resources. */ export interface ServiceState { /** * If set to `true`, the revision name (template.metadata.name) will be omitted and * autogenerated by Cloud Run. This cannot be set to `true` while `template.metadata.name` * is also set. * (For legacy support, if `template.metadata.name` is unset in state while * this field is set to false, the revision name will still autogenerate.) */ autogenerateRevisionName?: pulumi.Input<boolean>; /** * The location of the cloud run instance. eg us-central1 */ location?: pulumi.Input<string>; /** * Metadata associated with this Service, including name, namespace, labels, * and annotations. * Structure is documented below. */ metadata?: pulumi.Input<inputs.cloudrun.ServiceMetadata>; /** * Name must be unique within a Google Cloud project and region. * Is required when creating resources. Name is primarily intended * for creation idempotence and configuration definition. Cannot be updated. * More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names */ name?: pulumi.Input<string>; /** * The ID of the project in which the resource belongs. * If it is not provided, the provider project is used. */ project?: pulumi.Input<string>; /** * (Output) * Status of the condition, one of True, False, Unknown. */ statuses?: pulumi.Input<pulumi.Input<inputs.cloudrun.ServiceStatus>[]>; /** * template holds the latest specification for the Revision to * be stamped out. The template references the container image, and may also * include labels and annotations that should be attached to the Revision. * To correlate a Revision, and/or to force a Revision to be created when the * spec doesn't otherwise change, a nonce label may be provided in the * template metadata. For more details, see: * https://github.com/knative/serving/blob/main/docs/client-conventions.md#associate-modifications-with-revisions * Cloud Run does not currently support referencing a build that is * responsible for materializing the container image from source. * Structure is documented below. */ template?: pulumi.Input<inputs.cloudrun.ServiceTemplate>; /** * Traffic specifies how to distribute traffic over a collection of Knative Revisions * and Configurations * Structure is documented below. */ traffics?: pulumi.Input<pulumi.Input<inputs.cloudrun.ServiceTraffic>[]>; } /** * The set of arguments for constructing a Service resource. */ export interface ServiceArgs { /** * If set to `true`, the revision name (template.metadata.name) will be omitted and * autogenerated by Cloud Run. This cannot be set to `true` while `template.metadata.name` * is also set. * (For legacy support, if `template.metadata.name` is unset in state while * this field is set to false, the revision name will still autogenerate.) */ autogenerateRevisionName?: pulumi.Input<boolean>; /** * The location of the cloud run instance. eg us-central1 */ location: pulumi.Input<string>; /** * Metadata associated with this Service, including name, namespace, labels, * and annotations. * Structure is documented below. */ metadata?: pulumi.Input<inputs.cloudrun.ServiceMetadata>; /** * Name must be unique within a Google Cloud project and region. * Is required when creating resources. Name is primarily intended * for creation idempotence and configuration definition. Cannot be updated. * More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names */ name?: pulumi.Input<string>; /** * The ID of the project in which the resource belongs. * If it is not provided, the provider project is used. */ project?: pulumi.Input<string>; /** * template holds the latest specification for the Revision to * be stamped out. The template references the container image, and may also * include labels and annotations that should be attached to the Revision. * To correlate a Revision, and/or to force a Revision to be created when the * spec doesn't otherwise change, a nonce label may be provided in the * template metadata. For more details, see: * https://github.com/knative/serving/blob/main/docs/client-conventions.md#associate-modifications-with-revisions * Cloud Run does not currently support referencing a build that is * responsible for materializing the container image from source. * Structure is documented below. */ template?: pulumi.Input<inputs.cloudrun.ServiceTemplate>; /** * Traffic specifies how to distribute traffic over a collection of Knative Revisions * and Configurations * Structure is documented below. */ traffics?: pulumi.Input<pulumi.Input<inputs.cloudrun.ServiceTraffic>[]>; }