1. Packages
  2. Google Cloud (GCP) Classic
  3. API Docs
  4. projects
  5. ServiceIdentity
Google Cloud Classic v7.16.0 published on Wednesday, Mar 27, 2024 by Pulumi

gcp.projects.ServiceIdentity

Explore with Pulumi AI

gcp logo
Google Cloud Classic v7.16.0 published on Wednesday, Mar 27, 2024 by Pulumi

    Generate service identity for a service.

    Note: Once created, this resource cannot be updated or destroyed. These actions are a no-op.

    Note: This resource can be used to retrieve the emails of the Google-managed service accounts of the APIs that Google has configured with a Service Identity. You can run gcloud beta services identity create --service SERVICE_NAME.googleapis.com to verify if an API supports this.

    To get more information about Service Identity, see:

    Example Usage

    Service Identity Basic

    import * as pulumi from "@pulumi/pulumi";
    import * as gcp from "@pulumi/gcp";
    
    const project = gcp.organizations.getProject({});
    const hcSa = new gcp.projects.ServiceIdentity("hc_sa", {
        project: project.then(project => project.projectId),
        service: "healthcare.googleapis.com",
    });
    const hcSaBqJobuser = new gcp.projects.IAMMember("hc_sa_bq_jobuser", {
        project: project.then(project => project.projectId),
        role: "roles/bigquery.jobUser",
        member: pulumi.interpolate`serviceAccount:${hcSa.email}`,
    });
    
    import pulumi
    import pulumi_gcp as gcp
    
    project = gcp.organizations.get_project()
    hc_sa = gcp.projects.ServiceIdentity("hc_sa",
        project=project.project_id,
        service="healthcare.googleapis.com")
    hc_sa_bq_jobuser = gcp.projects.IAMMember("hc_sa_bq_jobuser",
        project=project.project_id,
        role="roles/bigquery.jobUser",
        member=hc_sa.email.apply(lambda email: f"serviceAccount:{email}"))
    
    package main
    
    import (
    	"fmt"
    
    	"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/organizations"
    	"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/projects"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		project, err := organizations.LookupProject(ctx, nil, nil)
    		if err != nil {
    			return err
    		}
    		hcSa, err := projects.NewServiceIdentity(ctx, "hc_sa", &projects.ServiceIdentityArgs{
    			Project: pulumi.String(project.ProjectId),
    			Service: pulumi.String("healthcare.googleapis.com"),
    		})
    		if err != nil {
    			return err
    		}
    		_, err = projects.NewIAMMember(ctx, "hc_sa_bq_jobuser", &projects.IAMMemberArgs{
    			Project: pulumi.String(project.ProjectId),
    			Role:    pulumi.String("roles/bigquery.jobUser"),
    			Member: hcSa.Email.ApplyT(func(email string) (string, error) {
    				return fmt.Sprintf("serviceAccount:%v", email), nil
    			}).(pulumi.StringOutput),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Gcp = Pulumi.Gcp;
    
    return await Deployment.RunAsync(() => 
    {
        var project = Gcp.Organizations.GetProject.Invoke();
    
        var hcSa = new Gcp.Projects.ServiceIdentity("hc_sa", new()
        {
            Project = project.Apply(getProjectResult => getProjectResult.ProjectId),
            Service = "healthcare.googleapis.com",
        });
    
        var hcSaBqJobuser = new Gcp.Projects.IAMMember("hc_sa_bq_jobuser", new()
        {
            Project = project.Apply(getProjectResult => getProjectResult.ProjectId),
            Role = "roles/bigquery.jobUser",
            Member = hcSa.Email.Apply(email => $"serviceAccount:{email}"),
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.gcp.organizations.OrganizationsFunctions;
    import com.pulumi.gcp.organizations.inputs.GetProjectArgs;
    import com.pulumi.gcp.projects.ServiceIdentity;
    import com.pulumi.gcp.projects.ServiceIdentityArgs;
    import com.pulumi.gcp.projects.IAMMember;
    import com.pulumi.gcp.projects.IAMMemberArgs;
    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) {
            final var project = OrganizationsFunctions.getProject();
    
            var hcSa = new ServiceIdentity("hcSa", ServiceIdentityArgs.builder()        
                .project(project.applyValue(getProjectResult -> getProjectResult.projectId()))
                .service("healthcare.googleapis.com")
                .build());
    
            var hcSaBqJobuser = new IAMMember("hcSaBqJobuser", IAMMemberArgs.builder()        
                .project(project.applyValue(getProjectResult -> getProjectResult.projectId()))
                .role("roles/bigquery.jobUser")
                .member(hcSa.email().applyValue(email -> String.format("serviceAccount:%s", email)))
                .build());
    
        }
    }
    
    resources:
      hcSa:
        type: gcp:projects:ServiceIdentity
        name: hc_sa
        properties:
          project: ${project.projectId}
          service: healthcare.googleapis.com
      hcSaBqJobuser:
        type: gcp:projects:IAMMember
        name: hc_sa_bq_jobuser
        properties:
          project: ${project.projectId}
          role: roles/bigquery.jobUser
          member: serviceAccount:${hcSa.email}
    variables:
      project:
        fn::invoke:
          Function: gcp:organizations:getProject
          Arguments: {}
    

    Create ServiceIdentity Resource

    new ServiceIdentity(name: string, args: ServiceIdentityArgs, opts?: CustomResourceOptions);
    @overload
    def ServiceIdentity(resource_name: str,
                        opts: Optional[ResourceOptions] = None,
                        project: Optional[str] = None,
                        service: Optional[str] = None)
    @overload
    def ServiceIdentity(resource_name: str,
                        args: ServiceIdentityArgs,
                        opts: Optional[ResourceOptions] = None)
    func NewServiceIdentity(ctx *Context, name string, args ServiceIdentityArgs, opts ...ResourceOption) (*ServiceIdentity, error)
    public ServiceIdentity(string name, ServiceIdentityArgs args, CustomResourceOptions? opts = null)
    public ServiceIdentity(String name, ServiceIdentityArgs args)
    public ServiceIdentity(String name, ServiceIdentityArgs args, CustomResourceOptions options)
    
    type: gcp:projects:ServiceIdentity
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    
    name string
    The unique name of the resource.
    args ServiceIdentityArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    resource_name str
    The unique name of the resource.
    args ServiceIdentityArgs
    The arguments to resource properties.
    opts ResourceOptions
    Bag of options to control resource's behavior.
    ctx Context
    Context object for the current deployment.
    name string
    The unique name of the resource.
    args ServiceIdentityArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args ServiceIdentityArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args ServiceIdentityArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    ServiceIdentity Resource Properties

    To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

    Inputs

    The ServiceIdentity resource accepts the following input properties:

    Service string
    The service to generate identity for.


    Project string
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
    Service string
    The service to generate identity for.


    Project string
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
    service String
    The service to generate identity for.


    project String
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
    service string
    The service to generate identity for.


    project string
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
    service str
    The service to generate identity for.


    project str
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
    service String
    The service to generate identity for.


    project String
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the ServiceIdentity resource produces the following output properties:

    Email string
    The email address of the Google managed service account.
    Id string
    The provider-assigned unique ID for this managed resource.
    Email string
    The email address of the Google managed service account.
    Id string
    The provider-assigned unique ID for this managed resource.
    email String
    The email address of the Google managed service account.
    id String
    The provider-assigned unique ID for this managed resource.
    email string
    The email address of the Google managed service account.
    id string
    The provider-assigned unique ID for this managed resource.
    email str
    The email address of the Google managed service account.
    id str
    The provider-assigned unique ID for this managed resource.
    email String
    The email address of the Google managed service account.
    id String
    The provider-assigned unique ID for this managed resource.

    Look up Existing ServiceIdentity Resource

    Get an existing ServiceIdentity resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

    public static get(name: string, id: Input<ID>, state?: ServiceIdentityState, opts?: CustomResourceOptions): ServiceIdentity
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            email: Optional[str] = None,
            project: Optional[str] = None,
            service: Optional[str] = None) -> ServiceIdentity
    func GetServiceIdentity(ctx *Context, name string, id IDInput, state *ServiceIdentityState, opts ...ResourceOption) (*ServiceIdentity, error)
    public static ServiceIdentity Get(string name, Input<string> id, ServiceIdentityState? state, CustomResourceOptions? opts = null)
    public static ServiceIdentity get(String name, Output<String> id, ServiceIdentityState state, CustomResourceOptions options)
    Resource lookup is not supported in YAML
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    resource_name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    name
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    state
    Any extra arguments used during the lookup.
    opts
    A bag of options that control this resource's behavior.
    The following state arguments are supported:
    Email string
    The email address of the Google managed service account.
    Project string
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
    Service string
    The service to generate identity for.


    Email string
    The email address of the Google managed service account.
    Project string
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
    Service string
    The service to generate identity for.


    email String
    The email address of the Google managed service account.
    project String
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
    service String
    The service to generate identity for.


    email string
    The email address of the Google managed service account.
    project string
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
    service string
    The service to generate identity for.


    email str
    The email address of the Google managed service account.
    project str
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
    service str
    The service to generate identity for.


    email String
    The email address of the Google managed service account.
    project String
    The ID of the project in which the resource belongs. If it is not provided, the provider project is used.
    service String
    The service to generate identity for.


    Import

    This resource does not support import.

    Package Details

    Repository
    Google Cloud (GCP) Classic pulumi/pulumi-gcp
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the google-beta Terraform Provider.
    gcp logo
    Google Cloud Classic v7.16.0 published on Wednesday, Mar 27, 2024 by Pulumi