Class Service


  • public class Service
    extends com.pulumi.resources.CustomResource
    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 ```java package generated_program; import com.pulumi.Context; import com.pulumi.Pulumi; import com.pulumi.core.Output; import com.pulumi.gcp.cloudrun.Service; import com.pulumi.gcp.cloudrun.ServiceArgs; import com.pulumi.gcp.cloudrun.inputs.ServiceTemplateArgs; import com.pulumi.gcp.cloudrun.inputs.ServiceTemplateSpecArgs; import com.pulumi.gcp.cloudrun.inputs.ServiceTrafficArgs; import com.pulumi.gcp.serviceAccount.Account; import com.pulumi.gcp.serviceAccount.AccountArgs; import com.pulumi.gcp.cloudrun.IamBinding; import com.pulumi.gcp.cloudrun.IamBindingArgs; import com.pulumi.gcp.projects.IAMBinding; import com.pulumi.gcp.projects.IAMBindingArgs; import com.pulumi.gcp.pubsub.Topic; import com.pulumi.gcp.pubsub.Subscription; import com.pulumi.gcp.pubsub.SubscriptionArgs; import com.pulumi.gcp.pubsub.inputs.SubscriptionPushConfigArgs; import com.pulumi.gcp.pubsub.inputs.SubscriptionPushConfigOidcTokenArgs; import java.util.List; import java.util.ArrayList; import java.util.Map; import java.io.File; import java.nio.file.Files; import java.nio.file.Paths; public class App { public static void main(String[] args) { Pulumi.run(App::stack); } public static void stack(Context ctx) { var default_ = new Service("default", ServiceArgs.builder() .location("us-central1") .template(ServiceTemplateArgs.builder() .spec(ServiceTemplateSpecArgs.builder() .containers(ServiceTemplateSpecContainerArgs.builder() .image("gcr.io/cloudrun/hello") .build()) .build()) .build()) .traffics(ServiceTrafficArgs.builder() .percent(100) .latestRevision(true) .build()) .build()); var sa = new Account("sa", AccountArgs.builder() .accountId("cloud-run-pubsub-invoker") .displayName("Cloud Run Pub/Sub Invoker") .build()); var binding = new IamBinding("binding", IamBindingArgs.builder() .location(default_.location()) .service(default_.name()) .role("roles/run.invoker") .members(sa.email().applyValue(email -> String.format("serviceAccount:%s", email))) .build()); var project = new IAMBinding("project", IAMBindingArgs.builder() .role("roles/iam.serviceAccountTokenCreator") .members(sa.email().applyValue(email -> String.format("serviceAccount:%s", email))) .build()); var topic = new Topic("topic"); var subscription = new Subscription("subscription", SubscriptionArgs.builder() .topic(topic.name()) .pushConfig(SubscriptionPushConfigArgs.builder() .pushEndpoint(default_.statuses().applyValue(statuses -> statuses[0].url())) .oidcToken(SubscriptionPushConfigOidcTokenArgs.builder() .serviceAccountEmail(sa.email()) .build()) .attributes(Map.of("x-goog-version", "v1")) .build()) .build()); } } ``` ### Cloud Run Service Basic ```java package generated_program; import com.pulumi.Context; import com.pulumi.Pulumi; import com.pulumi.core.Output; import com.pulumi.gcp.cloudrun.Service; import com.pulumi.gcp.cloudrun.ServiceArgs; import com.pulumi.gcp.cloudrun.inputs.ServiceTemplateArgs; import com.pulumi.gcp.cloudrun.inputs.ServiceTemplateSpecArgs; import com.pulumi.gcp.cloudrun.inputs.ServiceTrafficArgs; import java.util.List; import java.util.ArrayList; import java.util.Map; import java.io.File; import java.nio.file.Files; import java.nio.file.Paths; public class App { public static void main(String[] args) { Pulumi.run(App::stack); } public static void stack(Context ctx) { var default_ = new Service("default", ServiceArgs.builder() .location("us-central1") .template(ServiceTemplateArgs.builder() .spec(ServiceTemplateSpecArgs.builder() .containers(ServiceTemplateSpecContainerArgs.builder() .image("us-docker.pkg.dev/cloudrun/container/hello") .build()) .build()) .build()) .traffics(ServiceTrafficArgs.builder() .latestRevision(true) .percent(100) .build()) .build()); } } ``` ### Cloud Run Service Sql ```java package generated_program; import com.pulumi.Context; import com.pulumi.Pulumi; import com.pulumi.core.Output; import com.pulumi.gcp.sql.DatabaseInstance; import com.pulumi.gcp.sql.DatabaseInstanceArgs; import com.pulumi.gcp.sql.inputs.DatabaseInstanceSettingsArgs; import com.pulumi.gcp.cloudrun.Service; import com.pulumi.gcp.cloudrun.ServiceArgs; import com.pulumi.gcp.cloudrun.inputs.ServiceTemplateArgs; import com.pulumi.gcp.cloudrun.inputs.ServiceTemplateSpecArgs; import com.pulumi.gcp.cloudrun.inputs.ServiceTemplateMetadataArgs; import java.util.List; import java.util.ArrayList; import java.util.Map; import java.io.File; import java.nio.file.Files; import java.nio.file.Paths; public class App { public static void main(String[] args) { Pulumi.run(App::stack); } public static void stack(Context ctx) { var instance = new DatabaseInstance("instance", DatabaseInstanceArgs.builder() .region("us-east1") .databaseVersion("MYSQL_5_7") .settings(DatabaseInstanceSettingsArgs.builder() .tier("db-f1-micro") .build()) .deletionProtection("true") .build()); var default_ = new Service("default", ServiceArgs.builder() .location("us-central1") .template(ServiceTemplateArgs.builder() .spec(ServiceTemplateSpecArgs.builder() .containers(ServiceTemplateSpecContainerArgs.builder() .image("us-docker.pkg.dev/cloudrun/container/hello") .build()) .build()) .metadata(ServiceTemplateMetadataArgs.builder() .annotations(Map.ofEntries( Map.entry("autoscaling.knative.dev/maxScale", "1000"), Map.entry("run.googleapis.com/cloudsql-instances", instance.connectionName()), Map.entry("run.googleapis.com/client-name", "demo") )) .build()) .build()) .autogenerateRevisionName(true) .build()); } } ``` ### Cloud Run Service Noauth ```java package generated_program; import com.pulumi.Context; import com.pulumi.Pulumi; import com.pulumi.core.Output; import com.pulumi.gcp.cloudrun.Service; import com.pulumi.gcp.cloudrun.ServiceArgs; import com.pulumi.gcp.cloudrun.inputs.ServiceTemplateArgs; import com.pulumi.gcp.cloudrun.inputs.ServiceTemplateSpecArgs; import com.pulumi.gcp.organizations.OrganizationsFunctions; import com.pulumi.gcp.organizations.inputs.GetIAMPolicyArgs; import com.pulumi.gcp.cloudrun.IamPolicy; import com.pulumi.gcp.cloudrun.IamPolicyArgs; import java.util.List; import java.util.ArrayList; import java.util.Map; import java.io.File; import java.nio.file.Files; import java.nio.file.Paths; public class App { public static void main(String[] args) { Pulumi.run(App::stack); } public static void stack(Context ctx) { var default_ = new Service("default", ServiceArgs.builder() .location("us-central1") .template(ServiceTemplateArgs.builder() .spec(ServiceTemplateSpecArgs.builder() .containers(ServiceTemplateSpecContainerArgs.builder() .image("us-docker.pkg.dev/cloudrun/container/hello") .build()) .build()) .build()) .build()); final var noauthIAMPolicy = OrganizationsFunctions.getIAMPolicy(GetIAMPolicyArgs.builder() .bindings(GetIAMPolicyBindingArgs.builder() .role("roles/run.invoker") .members("allUsers") .build()) .build()); var noauthIamPolicy = new IamPolicy("noauthIamPolicy", IamPolicyArgs.builder() .location(default_.location()) .project(default_.project()) .service(default_.name()) .policyData(noauthIAMPolicy.applyValue(getIAMPolicyResult -> getIAMPolicyResult.policyData())) .build()); } } ``` ### Cloud Run Service Probes ```java package generated_program; import com.pulumi.Context; import com.pulumi.Pulumi; import com.pulumi.core.Output; import com.pulumi.gcp.cloudrun.Service; import com.pulumi.gcp.cloudrun.ServiceArgs; import com.pulumi.gcp.cloudrun.inputs.ServiceTemplateArgs; import com.pulumi.gcp.cloudrun.inputs.ServiceTemplateSpecArgs; import com.pulumi.gcp.cloudrun.inputs.ServiceTrafficArgs; import java.util.List; import java.util.ArrayList; import java.util.Map; import java.io.File; import java.nio.file.Files; import java.nio.file.Paths; public class App { public static void main(String[] args) { Pulumi.run(App::stack); } public static void stack(Context ctx) { var default_ = new Service("default", ServiceArgs.builder() .location("us-central1") .template(ServiceTemplateArgs.builder() .spec(ServiceTemplateSpecArgs.builder() .containers(ServiceTemplateSpecContainerArgs.builder() .image("us-docker.pkg.dev/cloudrun/container/hello") .startupProbe(ServiceTemplateSpecContainerStartupProbeArgs.builder() .initialDelaySeconds(0) .timeoutSeconds(1) .periodSeconds(3) .failureThreshold(1) .tcpSocket(ServiceTemplateSpecContainerStartupProbeTcpSocketArgs.builder() .port(8080) .build()) .build()) .livenessProbe(ServiceTemplateSpecContainerLivenessProbeArgs.builder() .httpGet(ServiceTemplateSpecContainerLivenessProbeHttpGetArgs.builder() .path("/") .build()) .build()) .build()) .build()) .build()) .traffics(ServiceTrafficArgs.builder() .percent(100) .latestRevision(true) .build()) .build()); } } ``` ### Cloud Run Service Multicontainer ```java package generated_program; import com.pulumi.Context; import com.pulumi.Pulumi; import com.pulumi.core.Output; import com.pulumi.gcp.cloudrun.Service; import com.pulumi.gcp.cloudrun.ServiceArgs; import com.pulumi.gcp.cloudrun.inputs.ServiceMetadataArgs; import com.pulumi.gcp.cloudrun.inputs.ServiceTemplateArgs; import com.pulumi.gcp.cloudrun.inputs.ServiceTemplateMetadataArgs; import com.pulumi.gcp.cloudrun.inputs.ServiceTemplateSpecArgs; import static com.pulumi.codegen.internal.Serialization.*; import com.pulumi.resources.CustomResourceOptions; import java.util.List; import java.util.ArrayList; import java.util.Map; import java.io.File; import java.nio.file.Files; import java.nio.file.Paths; public class App { public static void main(String[] args) { Pulumi.run(App::stack); } public static void stack(Context ctx) { var default_ = new Service("default", ServiceArgs.builder() .location("us-central1") .metadata(ServiceMetadataArgs.builder() .annotations(Map.of("run.googleapis.com/launch-stage", "BETA")) .build()) .template(ServiceTemplateArgs.builder() .metadata(ServiceTemplateMetadataArgs.builder() .annotations(Map.of("run.googleapis.com/container-dependencies", serializeJson( jsonObject( jsonProperty("hello-1", jsonArray("hello-2")) )))) .build()) .spec(ServiceTemplateSpecArgs.builder() .containers( ServiceTemplateSpecContainerArgs.builder() .name("hello-1") .ports(ServiceTemplateSpecContainerPortArgs.builder() .containerPort(8080) .build()) .image("us-docker.pkg.dev/cloudrun/container/hello") .volumeMounts(ServiceTemplateSpecContainerVolumeMountArgs.builder() .name("shared-volume") .mountPath("/mnt/shared") .build()) .build(), ServiceTemplateSpecContainerArgs.builder() .name("hello-2") .image("us-docker.pkg.dev/cloudrun/container/hello") .envs(ServiceTemplateSpecContainerEnvArgs.builder() .name("PORT") .value("8081") .build()) .startupProbe(ServiceTemplateSpecContainerStartupProbeArgs.builder() .httpGet(ServiceTemplateSpecContainerStartupProbeHttpGetArgs.builder() .port(8081) .build()) .build()) .volumeMounts(ServiceTemplateSpecContainerVolumeMountArgs.builder() .name("shared-volume") .mountPath("/mnt/shared") .build()) .build()) .volumes(ServiceTemplateSpecVolumeArgs.builder() .name("shared-volume") .emptyDir(ServiceTemplateSpecVolumeEmptyDirArgs.builder() .medium("Memory") .sizeLimit("128Mi") .build()) .build()) .build()) .build()) .build(), CustomResourceOptions.builder() .provider(google_beta) .build()); } } ``` ## Import Service can be imported using any of these accepted formats ```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}} ```
    • Nested Class Summary

      • Nested classes/interfaces inherited from class com.pulumi.resources.CustomResource

        com.pulumi.resources.CustomResource.CustomResourceInternal
      • Nested classes/interfaces inherited from class com.pulumi.resources.Resource

        com.pulumi.resources.Resource.LazyField<T extends java.lang.Object>, com.pulumi.resources.Resource.LazyFields, com.pulumi.resources.Resource.ResourceInternal
    • Field Summary

      • Fields inherited from class com.pulumi.resources.Resource

        childResources, remote
    • Constructor Summary

      Constructors 
      Constructor Description
      Service​(java.lang.String name)  
      Service​(java.lang.String name, ServiceArgs args)  
      Service​(java.lang.String name, ServiceArgs args, com.pulumi.resources.CustomResourceOptions options)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>> autogenerateRevisionName()  
      static Service get​(java.lang.String name, com.pulumi.core.Output<java.lang.String> id, ServiceState state, com.pulumi.resources.CustomResourceOptions options)
      Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.
      com.pulumi.core.Output<java.lang.String> location()  
      com.pulumi.core.Output<ServiceMetadata> metadata()  
      com.pulumi.core.Output<java.lang.String> name()  
      com.pulumi.core.Output<java.lang.String> project()  
      com.pulumi.core.Output<java.util.List<ServiceStatus>> statuses()  
      com.pulumi.core.Output<java.util.Optional<ServiceTemplate>> template()  
      com.pulumi.core.Output<java.util.List<ServiceTraffic>> traffics()  
      • Methods inherited from class com.pulumi.resources.CustomResource

        getId, id, idFuture
      • Methods inherited from class com.pulumi.resources.Resource

        getChildResources, getResourceName, getResourceType, getUrn, pulumiChildResources, pulumiResourceName, pulumiResourceType, urn
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Service

        public Service​(java.lang.String name)
        Parameters:
        name - The _unique_ name of the resulting resource.
      • Service

        public Service​(java.lang.String name,
                       ServiceArgs args)
        Parameters:
        name - The _unique_ name of the resulting resource.
        args - The arguments to use to populate this resource's properties.
      • Service

        public Service​(java.lang.String name,
                       ServiceArgs args,
                       @Nullable
                       com.pulumi.resources.CustomResourceOptions options)
        Parameters:
        name - The _unique_ name of the resulting resource.
        args - The arguments to use to populate this resource's properties.
        options - A bag of options that control this resource's behavior.
    • Method Detail

      • autogenerateRevisionName

        public com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>> autogenerateRevisionName()
        Returns:
        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.)
      • location

        public com.pulumi.core.Output<java.lang.String> location()
        Returns:
        The location of the cloud run instance. eg us-central1
      • metadata

        public com.pulumi.core.Output<ServiceMetadata> metadata()
        Returns:
        Metadata associated with this Service, including name, namespace, labels, and annotations. Structure is documented below.
      • name

        public com.pulumi.core.Output<java.lang.String> name()
        Returns:
        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
      • project

        public com.pulumi.core.Output<java.lang.String> project()
        Returns:
        The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
      • statuses

        public com.pulumi.core.Output<java.util.List<ServiceStatus>> statuses()
        Returns:
        (Output) Status of the condition, one of True, False, Unknown.
      • template

        public com.pulumi.core.Output<java.util.Optional<ServiceTemplate>> template()
        Returns:
        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.
      • traffics

        public com.pulumi.core.Output<java.util.List<ServiceTraffic>> traffics()
        Returns:
        Traffic specifies how to distribute traffic over a collection of Knative Revisions and Configurations Structure is documented below.
      • get

        public static Service get​(java.lang.String name,
                                  com.pulumi.core.Output<java.lang.String> id,
                                  @Nullable
                                  ServiceState state,
                                  @Nullable
                                  com.pulumi.resources.CustomResourceOptions options)
        Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.
        Parameters:
        name - The _unique_ name of the resulting resource.
        id - The _unique_ provider ID of the resource to lookup.
        state -
        options - Optional settings to control the behavior of the CustomResource.