com.pulumi.gcp.serviceaccount.kotlin.IAMMemberArgs.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pulumi-gcp-kotlin Show documentation
Show all versions of pulumi-gcp-kotlin Show documentation
Build cloud applications and infrastructure by combining the safety and reliability of infrastructure as code with the power of the Kotlin programming language.
@file:Suppress("NAME_SHADOWING", "DEPRECATION")
package com.pulumi.gcp.serviceaccount.kotlin
import com.pulumi.core.Output
import com.pulumi.core.Output.of
import com.pulumi.gcp.serviceaccount.IAMMemberArgs.builder
import com.pulumi.gcp.serviceaccount.kotlin.inputs.IAMMemberConditionArgs
import com.pulumi.gcp.serviceaccount.kotlin.inputs.IAMMemberConditionArgsBuilder
import com.pulumi.kotlin.ConvertibleToJava
import com.pulumi.kotlin.PulumiTagMarker
import com.pulumi.kotlin.applySuspend
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmName
/**
* When managing IAM roles, you can treat a service account either as a resource or as an identity. This resource is to add iam policy bindings to a service account resource, such as allowing the members to run operations as or modify the service account. To configure permissions for a service account on other GCP resources, use the google_project_iam set of resources.
* Three different resources help you manage your IAM policy for a service account. Each of these resources serves a different use case:
* * `gcp.serviceaccount.IAMPolicy`: Authoritative. Sets the IAM policy for the service account and replaces any existing policy already attached.
* * `gcp.serviceaccount.IAMBinding`: Authoritative for a given role. Updates the IAM policy to grant a role to a list of members. Other roles within the IAM policy for the service account are preserved.
* * `gcp.serviceaccount.IAMMember`: Non-authoritative. Updates the IAM policy to grant a role to a new member. Other members for the role for the service account are preserved.
* > **Note:** `gcp.serviceaccount.IAMPolicy` **cannot** be used in conjunction with `gcp.serviceaccount.IAMBinding` and `gcp.serviceaccount.IAMMember` or they will fight over what your policy should be.
* > **Note:** `gcp.serviceaccount.IAMBinding` resources **can be** used in conjunction with `gcp.serviceaccount.IAMMember` resources **only if** they do not grant privilege to the same role.
* ## Example Usage
* ### Service Account IAM Policy
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as gcp from "@pulumi/gcp";
* const admin = gcp.organizations.getIAMPolicy({
* bindings: [{
* role: "roles/iam.serviceAccountUser",
* members: ["user:jane@example.com"],
* }],
* });
* const sa = new gcp.serviceaccount.Account("sa", {
* accountId: "my-service-account",
* displayName: "A service account that only Jane can interact with",
* });
* const admin_account_iam = new gcp.serviceaccount.IAMPolicy("admin-account-iam", {
* serviceAccountId: sa.name,
* policyData: admin.then(admin => admin.policyData),
* });
* ```
* ```python
* import pulumi
* import pulumi_gcp as gcp
* admin = gcp.organizations.get_iam_policy(bindings=[gcp.organizations.GetIAMPolicyBindingArgs(
* role="roles/iam.serviceAccountUser",
* members=["user:jane@example.com"],
* )])
* sa = gcp.serviceaccount.Account("sa",
* account_id="my-service-account",
* display_name="A service account that only Jane can interact with")
* admin_account_iam = gcp.serviceaccount.IAMPolicy("admin-account-iam",
* service_account_id=sa.name,
* policy_data=admin.policy_data)
* ```
* ```csharp
* using System.Collections.Generic;
* using System.Linq;
* using Pulumi;
* using Gcp = Pulumi.Gcp;
* return await Deployment.RunAsync(() =>
* {
* var admin = Gcp.Organizations.GetIAMPolicy.Invoke(new()
* {
* Bindings = new[]
* {
* new Gcp.Organizations.Inputs.GetIAMPolicyBindingInputArgs
* {
* Role = "roles/iam.serviceAccountUser",
* Members = new[]
* {
* "user:[email protected]",
* },
* },
* },
* });
* var sa = new Gcp.ServiceAccount.Account("sa", new()
* {
* AccountId = "my-service-account",
* DisplayName = "A service account that only Jane can interact with",
* });
* var admin_account_iam = new Gcp.ServiceAccount.IAMPolicy("admin-account-iam", new()
* {
* ServiceAccountId = sa.Name,
* PolicyData = admin.Apply(getIAMPolicyResult => getIAMPolicyResult.PolicyData),
* });
* });
* ```
* ```go
* package main
* import (
* "github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/organizations"
* "github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/serviceaccount"
* "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
* )
* func main() {
* pulumi.Run(func(ctx *pulumi.Context) error {
* admin, err := organizations.LookupIAMPolicy(ctx, &organizations.LookupIAMPolicyArgs{
* Bindings: []organizations.GetIAMPolicyBinding{
* {
* Role: "roles/iam.serviceAccountUser",
* Members: []string{
* "user:[email protected]",
* },
* },
* },
* }, nil)
* if err != nil {
* return err
* }
* sa, err := serviceaccount.NewAccount(ctx, "sa", &serviceaccount.AccountArgs{
* AccountId: pulumi.String("my-service-account"),
* DisplayName: pulumi.String("A service account that only Jane can interact with"),
* })
* if err != nil {
* return err
* }
* _, err = serviceaccount.NewIAMPolicy(ctx, "admin-account-iam", &serviceaccount.IAMPolicyArgs{
* ServiceAccountId: sa.Name,
* PolicyData: pulumi.String(admin.PolicyData),
* })
* if err != nil {
* return err
* }
* return nil
* })
* }
* ```
* ```java
* 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.GetIAMPolicyArgs;
* import com.pulumi.gcp.serviceaccount.Account;
* import com.pulumi.gcp.serviceaccount.AccountArgs;
* import com.pulumi.gcp.serviceaccount.IAMPolicy;
* import com.pulumi.gcp.serviceaccount.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) {
* final var admin = OrganizationsFunctions.getIAMPolicy(GetIAMPolicyArgs.builder()
* .bindings(GetIAMPolicyBindingArgs.builder()
* .role("roles/iam.serviceAccountUser")
* .members("user:[email protected]")
* .build())
* .build());
* var sa = new Account("sa", AccountArgs.builder()
* .accountId("my-service-account")
* .displayName("A service account that only Jane can interact with")
* .build());
* var admin_account_iam = new IAMPolicy("admin-account-iam", IAMPolicyArgs.builder()
* .serviceAccountId(sa.name())
* .policyData(admin.applyValue(getIAMPolicyResult -> getIAMPolicyResult.policyData()))
* .build());
* }
* }
* ```
* ```yaml
* resources:
* sa:
* type: gcp:serviceaccount:Account
* properties:
* accountId: my-service-account
* displayName: A service account that only Jane can interact with
* admin-account-iam:
* type: gcp:serviceaccount:IAMPolicy
* properties:
* serviceAccountId: ${sa.name}
* policyData: ${admin.policyData}
* variables:
* admin:
* fn::invoke:
* Function: gcp:organizations:getIAMPolicy
* Arguments:
* bindings:
* - role: roles/iam.serviceAccountUser
* members:
* - user:[email protected]
* ```
*
* ### Service Account IAM Binding
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as gcp from "@pulumi/gcp";
* const sa = new gcp.serviceaccount.Account("sa", {
* accountId: "my-service-account",
* displayName: "A service account that only Jane can use",
* });
* const admin_account_iam = new gcp.serviceaccount.IAMBinding("admin-account-iam", {
* serviceAccountId: sa.name,
* role: "roles/iam.serviceAccountUser",
* members: ["user:jane@example.com"],
* });
* ```
* ```python
* import pulumi
* import pulumi_gcp as gcp
* sa = gcp.serviceaccount.Account("sa",
* account_id="my-service-account",
* display_name="A service account that only Jane can use")
* admin_account_iam = gcp.serviceaccount.IAMBinding("admin-account-iam",
* service_account_id=sa.name,
* role="roles/iam.serviceAccountUser",
* members=["user:jane@example.com"])
* ```
* ```csharp
* using System.Collections.Generic;
* using System.Linq;
* using Pulumi;
* using Gcp = Pulumi.Gcp;
* return await Deployment.RunAsync(() =>
* {
* var sa = new Gcp.ServiceAccount.Account("sa", new()
* {
* AccountId = "my-service-account",
* DisplayName = "A service account that only Jane can use",
* });
* var admin_account_iam = new Gcp.ServiceAccount.IAMBinding("admin-account-iam", new()
* {
* ServiceAccountId = sa.Name,
* Role = "roles/iam.serviceAccountUser",
* Members = new[]
* {
* "user:[email protected]",
* },
* });
* });
* ```
* ```go
* package main
* import (
* "github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/serviceaccount"
* "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
* )
* func main() {
* pulumi.Run(func(ctx *pulumi.Context) error {
* sa, err := serviceaccount.NewAccount(ctx, "sa", &serviceaccount.AccountArgs{
* AccountId: pulumi.String("my-service-account"),
* DisplayName: pulumi.String("A service account that only Jane can use"),
* })
* if err != nil {
* return err
* }
* _, err = serviceaccount.NewIAMBinding(ctx, "admin-account-iam", &serviceaccount.IAMBindingArgs{
* ServiceAccountId: sa.Name,
* Role: pulumi.String("roles/iam.serviceAccountUser"),
* Members: pulumi.StringArray{
* pulumi.String("user:[email protected]"),
* },
* })
* if err != nil {
* return err
* }
* return nil
* })
* }
* ```
* ```java
* package generated_program;
* import com.pulumi.Context;
* import com.pulumi.Pulumi;
* import com.pulumi.core.Output;
* import com.pulumi.gcp.serviceaccount.Account;
* import com.pulumi.gcp.serviceaccount.AccountArgs;
* import com.pulumi.gcp.serviceaccount.IAMBinding;
* import com.pulumi.gcp.serviceaccount.IAMBindingArgs;
* 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 sa = new Account("sa", AccountArgs.builder()
* .accountId("my-service-account")
* .displayName("A service account that only Jane can use")
* .build());
* var admin_account_iam = new IAMBinding("admin-account-iam", IAMBindingArgs.builder()
* .serviceAccountId(sa.name())
* .role("roles/iam.serviceAccountUser")
* .members("user:[email protected]")
* .build());
* }
* }
* ```
* ```yaml
* resources:
* sa:
* type: gcp:serviceaccount:Account
* properties:
* accountId: my-service-account
* displayName: A service account that only Jane can use
* admin-account-iam:
* type: gcp:serviceaccount:IAMBinding
* properties:
* serviceAccountId: ${sa.name}
* role: roles/iam.serviceAccountUser
* members:
* - user:[email protected]
* ```
*
* ### Service Account IAM Binding With IAM Conditions:
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as gcp from "@pulumi/gcp";
* const sa = new gcp.serviceaccount.Account("sa", {
* accountId: "my-service-account",
* displayName: "A service account that only Jane can use",
* });
* const admin_account_iam = new gcp.serviceaccount.IAMBinding("admin-account-iam", {
* serviceAccountId: sa.name,
* role: "roles/iam.serviceAccountUser",
* members: ["user:jane@example.com"],
* condition: {
* title: "expires_after_2019_12_31",
* description: "Expiring at midnight of 2019-12-31",
* expression: "request.time < timestamp(\"2020-01-01T00:00:00Z\")",
* },
* });
* ```
* ```python
* import pulumi
* import pulumi_gcp as gcp
* sa = gcp.serviceaccount.Account("sa",
* account_id="my-service-account",
* display_name="A service account that only Jane can use")
* admin_account_iam = gcp.serviceaccount.IAMBinding("admin-account-iam",
* service_account_id=sa.name,
* role="roles/iam.serviceAccountUser",
* members=["user:jane@example.com"],
* condition=gcp.serviceaccount.IAMBindingConditionArgs(
* title="expires_after_2019_12_31",
* description="Expiring at midnight of 2019-12-31",
* expression="request.time < timestamp(\"2020-01-01T00:00:00Z\")",
* ))
* ```
* ```csharp
* using System.Collections.Generic;
* using System.Linq;
* using Pulumi;
* using Gcp = Pulumi.Gcp;
* return await Deployment.RunAsync(() =>
* {
* var sa = new Gcp.ServiceAccount.Account("sa", new()
* {
* AccountId = "my-service-account",
* DisplayName = "A service account that only Jane can use",
* });
* var admin_account_iam = new Gcp.ServiceAccount.IAMBinding("admin-account-iam", new()
* {
* ServiceAccountId = sa.Name,
* Role = "roles/iam.serviceAccountUser",
* Members = new[]
* {
* "user:[email protected]",
* },
* Condition = new Gcp.ServiceAccount.Inputs.IAMBindingConditionArgs
* {
* Title = "expires_after_2019_12_31",
* Description = "Expiring at midnight of 2019-12-31",
* Expression = "request.time < timestamp(\"2020-01-01T00:00:00Z\")",
* },
* });
* });
* ```
* ```go
* package main
* import (
* "github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/serviceaccount"
* "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
* )
* func main() {
* pulumi.Run(func(ctx *pulumi.Context) error {
* sa, err := serviceaccount.NewAccount(ctx, "sa", &serviceaccount.AccountArgs{
* AccountId: pulumi.String("my-service-account"),
* DisplayName: pulumi.String("A service account that only Jane can use"),
* })
* if err != nil {
* return err
* }
* _, err = serviceaccount.NewIAMBinding(ctx, "admin-account-iam", &serviceaccount.IAMBindingArgs{
* ServiceAccountId: sa.Name,
* Role: pulumi.String("roles/iam.serviceAccountUser"),
* Members: pulumi.StringArray{
* pulumi.String("user:[email protected]"),
* },
* Condition: &serviceaccount.IAMBindingConditionArgs{
* Title: pulumi.String("expires_after_2019_12_31"),
* Description: pulumi.String("Expiring at midnight of 2019-12-31"),
* Expression: pulumi.String("request.time < timestamp(\"2020-01-01T00:00:00Z\")"),
* },
* })
* if err != nil {
* return err
* }
* return nil
* })
* }
* ```
* ```java
* package generated_program;
* import com.pulumi.Context;
* import com.pulumi.Pulumi;
* import com.pulumi.core.Output;
* import com.pulumi.gcp.serviceaccount.Account;
* import com.pulumi.gcp.serviceaccount.AccountArgs;
* import com.pulumi.gcp.serviceaccount.IAMBinding;
* import com.pulumi.gcp.serviceaccount.IAMBindingArgs;
* import com.pulumi.gcp.serviceaccount.inputs.IAMBindingConditionArgs;
* 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 sa = new Account("sa", AccountArgs.builder()
* .accountId("my-service-account")
* .displayName("A service account that only Jane can use")
* .build());
* var admin_account_iam = new IAMBinding("admin-account-iam", IAMBindingArgs.builder()
* .serviceAccountId(sa.name())
* .role("roles/iam.serviceAccountUser")
* .members("user:[email protected]")
* .condition(IAMBindingConditionArgs.builder()
* .title("expires_after_2019_12_31")
* .description("Expiring at midnight of 2019-12-31")
* .expression("request.time < timestamp(\"2020-01-01T00:00:00Z\")")
* .build())
* .build());
* }
* }
* ```
* ```yaml
* resources:
* sa:
* type: gcp:serviceaccount:Account
* properties:
* accountId: my-service-account
* displayName: A service account that only Jane can use
* admin-account-iam:
* type: gcp:serviceaccount:IAMBinding
* properties:
* serviceAccountId: ${sa.name}
* role: roles/iam.serviceAccountUser
* members:
* - user:[email protected]
* condition:
* title: expires_after_2019_12_31
* description: Expiring at midnight of 2019-12-31
* expression: request.time < timestamp("2020-01-01T00:00:00Z")
* ```
*
* ### Service Account IAM Member
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as gcp from "@pulumi/gcp";
* const default = gcp.compute.getDefaultServiceAccount({});
* const sa = new gcp.serviceaccount.Account("sa", {
* accountId: "my-service-account",
* displayName: "A service account that Jane can use",
* });
* const admin_account_iam = new gcp.serviceaccount.IAMMember("admin-account-iam", {
* serviceAccountId: sa.name,
* role: "roles/iam.serviceAccountUser",
* member: "user:[email protected]",
* });
* // Allow SA service account use the default GCE account
* const gce_default_account_iam = new gcp.serviceaccount.IAMMember("gce-default-account-iam", {
* serviceAccountId: _default.then(_default => _default.name),
* role: "roles/iam.serviceAccountUser",
* member: pulumi.interpolate`serviceAccount:${sa.email}`,
* });
* ```
* ```python
* import pulumi
* import pulumi_gcp as gcp
* default = gcp.compute.get_default_service_account()
* sa = gcp.serviceaccount.Account("sa",
* account_id="my-service-account",
* display_name="A service account that Jane can use")
* admin_account_iam = gcp.serviceaccount.IAMMember("admin-account-iam",
* service_account_id=sa.name,
* role="roles/iam.serviceAccountUser",
* member="user:[email protected]")
* # Allow SA service account use the default GCE account
* gce_default_account_iam = gcp.serviceaccount.IAMMember("gce-default-account-iam",
* service_account_id=default.name,
* role="roles/iam.serviceAccountUser",
* member=sa.email.apply(lambda email: f"serviceAccount:{email}"))
* ```
* ```csharp
* using System.Collections.Generic;
* using System.Linq;
* using Pulumi;
* using Gcp = Pulumi.Gcp;
* return await Deployment.RunAsync(() =>
* {
* var @default = Gcp.Compute.GetDefaultServiceAccount.Invoke();
* var sa = new Gcp.ServiceAccount.Account("sa", new()
* {
* AccountId = "my-service-account",
* DisplayName = "A service account that Jane can use",
* });
* var admin_account_iam = new Gcp.ServiceAccount.IAMMember("admin-account-iam", new()
* {
* ServiceAccountId = sa.Name,
* Role = "roles/iam.serviceAccountUser",
* Member = "user:[email protected]",
* });
* // Allow SA service account use the default GCE account
* var gce_default_account_iam = new Gcp.ServiceAccount.IAMMember("gce-default-account-iam", new()
* {
* ServiceAccountId = @default.Apply(@default => @default.Apply(getDefaultServiceAccountResult => getDefaultServiceAccountResult.Name)),
* Role = "roles/iam.serviceAccountUser",
* Member = sa.Email.Apply(email => $"serviceAccount:{email}"),
* });
* });
* ```
* ```go
* package main
* import (
* "fmt"
* "github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/compute"
* "github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/serviceaccount"
* "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
* )
* func main() {
* pulumi.Run(func(ctx *pulumi.Context) error {
* _default, err := compute.GetDefaultServiceAccount(ctx, nil, nil)
* if err != nil {
* return err
* }
* sa, err := serviceaccount.NewAccount(ctx, "sa", &serviceaccount.AccountArgs{
* AccountId: pulumi.String("my-service-account"),
* DisplayName: pulumi.String("A service account that Jane can use"),
* })
* if err != nil {
* return err
* }
* _, err = serviceaccount.NewIAMMember(ctx, "admin-account-iam", &serviceaccount.IAMMemberArgs{
* ServiceAccountId: sa.Name,
* Role: pulumi.String("roles/iam.serviceAccountUser"),
* Member: pulumi.String("user:[email protected]"),
* })
* if err != nil {
* return err
* }
* // Allow SA service account use the default GCE account
* _, err = serviceaccount.NewIAMMember(ctx, "gce-default-account-iam", &serviceaccount.IAMMemberArgs{
* ServiceAccountId: pulumi.String(_default.Name),
* Role: pulumi.String("roles/iam.serviceAccountUser"),
* Member: sa.Email.ApplyT(func(email string) (string, error) {
* return fmt.Sprintf("serviceAccount:%v", email), nil
* }).(pulumi.StringOutput),
* })
* if err != nil {
* return err
* }
* return nil
* })
* }
* ```
* ```java
* package generated_program;
* import com.pulumi.Context;
* import com.pulumi.Pulumi;
* import com.pulumi.core.Output;
* import com.pulumi.gcp.compute.ComputeFunctions;
* import com.pulumi.gcp.compute.inputs.GetDefaultServiceAccountArgs;
* import com.pulumi.gcp.serviceaccount.Account;
* import com.pulumi.gcp.serviceaccount.AccountArgs;
* import com.pulumi.gcp.serviceaccount.IAMMember;
* import com.pulumi.gcp.serviceaccount.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 default = ComputeFunctions.getDefaultServiceAccount();
* var sa = new Account("sa", AccountArgs.builder()
* .accountId("my-service-account")
* .displayName("A service account that Jane can use")
* .build());
* var admin_account_iam = new IAMMember("admin-account-iam", IAMMemberArgs.builder()
* .serviceAccountId(sa.name())
* .role("roles/iam.serviceAccountUser")
* .member("user:[email protected]")
* .build());
* // Allow SA service account use the default GCE account
* var gce_default_account_iam = new IAMMember("gce-default-account-iam", IAMMemberArgs.builder()
* .serviceAccountId(default_.name())
* .role("roles/iam.serviceAccountUser")
* .member(sa.email().applyValue(email -> String.format("serviceAccount:%s", email)))
* .build());
* }
* }
* ```
* ```yaml
* resources:
* sa:
* type: gcp:serviceaccount:Account
* properties:
* accountId: my-service-account
* displayName: A service account that Jane can use
* admin-account-iam:
* type: gcp:serviceaccount:IAMMember
* properties:
* serviceAccountId: ${sa.name}
* role: roles/iam.serviceAccountUser
* member: user:[email protected]
* # Allow SA service account use the default GCE account
* gce-default-account-iam:
* type: gcp:serviceaccount:IAMMember
* properties:
* serviceAccountId: ${default.name}
* role: roles/iam.serviceAccountUser
* member: serviceAccount:${sa.email}
* variables:
* default:
* fn::invoke:
* Function: gcp:compute:getDefaultServiceAccount
* Arguments: {}
* ```
*
* ### Service Account IAM Member With IAM Conditions:
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as gcp from "@pulumi/gcp";
* const sa = new gcp.serviceaccount.Account("sa", {
* accountId: "my-service-account",
* displayName: "A service account that Jane can use",
* });
* const admin_account_iam = new gcp.serviceaccount.IAMMember("admin-account-iam", {
* serviceAccountId: sa.name,
* role: "roles/iam.serviceAccountUser",
* member: "user:[email protected]",
* condition: {
* title: "expires_after_2019_12_31",
* description: "Expiring at midnight of 2019-12-31",
* expression: "request.time < timestamp(\"2020-01-01T00:00:00Z\")",
* },
* });
* ```
* ```python
* import pulumi
* import pulumi_gcp as gcp
* sa = gcp.serviceaccount.Account("sa",
* account_id="my-service-account",
* display_name="A service account that Jane can use")
* admin_account_iam = gcp.serviceaccount.IAMMember("admin-account-iam",
* service_account_id=sa.name,
* role="roles/iam.serviceAccountUser",
* member="user:[email protected]",
* condition=gcp.serviceaccount.IAMMemberConditionArgs(
* title="expires_after_2019_12_31",
* description="Expiring at midnight of 2019-12-31",
* expression="request.time < timestamp(\"2020-01-01T00:00:00Z\")",
* ))
* ```
* ```csharp
* using System.Collections.Generic;
* using System.Linq;
* using Pulumi;
* using Gcp = Pulumi.Gcp;
* return await Deployment.RunAsync(() =>
* {
* var sa = new Gcp.ServiceAccount.Account("sa", new()
* {
* AccountId = "my-service-account",
* DisplayName = "A service account that Jane can use",
* });
* var admin_account_iam = new Gcp.ServiceAccount.IAMMember("admin-account-iam", new()
* {
* ServiceAccountId = sa.Name,
* Role = "roles/iam.serviceAccountUser",
* Member = "user:[email protected]",
* Condition = new Gcp.ServiceAccount.Inputs.IAMMemberConditionArgs
* {
* Title = "expires_after_2019_12_31",
* Description = "Expiring at midnight of 2019-12-31",
* Expression = "request.time < timestamp(\"2020-01-01T00:00:00Z\")",
* },
* });
* });
* ```
* ```go
* package main
* import (
* "github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/serviceaccount"
* "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
* )
* func main() {
* pulumi.Run(func(ctx *pulumi.Context) error {
* sa, err := serviceaccount.NewAccount(ctx, "sa", &serviceaccount.AccountArgs{
* AccountId: pulumi.String("my-service-account"),
* DisplayName: pulumi.String("A service account that Jane can use"),
* })
* if err != nil {
* return err
* }
* _, err = serviceaccount.NewIAMMember(ctx, "admin-account-iam", &serviceaccount.IAMMemberArgs{
* ServiceAccountId: sa.Name,
* Role: pulumi.String("roles/iam.serviceAccountUser"),
* Member: pulumi.String("user:[email protected]"),
* Condition: &serviceaccount.IAMMemberConditionArgs{
* Title: pulumi.String("expires_after_2019_12_31"),
* Description: pulumi.String("Expiring at midnight of 2019-12-31"),
* Expression: pulumi.String("request.time < timestamp(\"2020-01-01T00:00:00Z\")"),
* },
* })
* if err != nil {
* return err
* }
* return nil
* })
* }
* ```
* ```java
* package generated_program;
* import com.pulumi.Context;
* import com.pulumi.Pulumi;
* import com.pulumi.core.Output;
* import com.pulumi.gcp.serviceaccount.Account;
* import com.pulumi.gcp.serviceaccount.AccountArgs;
* import com.pulumi.gcp.serviceaccount.IAMMember;
* import com.pulumi.gcp.serviceaccount.IAMMemberArgs;
* import com.pulumi.gcp.serviceaccount.inputs.IAMMemberConditionArgs;
* 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 sa = new Account("sa", AccountArgs.builder()
* .accountId("my-service-account")
* .displayName("A service account that Jane can use")
* .build());
* var admin_account_iam = new IAMMember("admin-account-iam", IAMMemberArgs.builder()
* .serviceAccountId(sa.name())
* .role("roles/iam.serviceAccountUser")
* .member("user:[email protected]")
* .condition(IAMMemberConditionArgs.builder()
* .title("expires_after_2019_12_31")
* .description("Expiring at midnight of 2019-12-31")
* .expression("request.time < timestamp(\"2020-01-01T00:00:00Z\")")
* .build())
* .build());
* }
* }
* ```
* ```yaml
* resources:
* sa:
* type: gcp:serviceaccount:Account
* properties:
* accountId: my-service-account
* displayName: A service account that Jane can use
* admin-account-iam:
* type: gcp:serviceaccount:IAMMember
* properties:
* serviceAccountId: ${sa.name}
* role: roles/iam.serviceAccountUser
* member: user:[email protected]
* condition:
* title: expires_after_2019_12_31
* description: Expiring at midnight of 2019-12-31
* expression: request.time < timestamp("2020-01-01T00:00:00Z")
* ```
*
* ### Additional Examples
* ### Service Account IAM Policy
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as gcp from "@pulumi/gcp";
* const admin = gcp.organizations.getIAMPolicy({
* bindings: [{
* role: "roles/iam.serviceAccountUser",
* members: ["user:jane@example.com"],
* }],
* });
* const sa = new gcp.serviceaccount.Account("sa", {
* accountId: "my-service-account",
* displayName: "A service account that only Jane can interact with",
* });
* const admin_account_iam = new gcp.serviceaccount.IAMPolicy("admin-account-iam", {
* serviceAccountId: sa.name,
* policyData: admin.then(admin => admin.policyData),
* });
* ```
* ```python
* import pulumi
* import pulumi_gcp as gcp
* admin = gcp.organizations.get_iam_policy(bindings=[gcp.organizations.GetIAMPolicyBindingArgs(
* role="roles/iam.serviceAccountUser",
* members=["user:jane@example.com"],
* )])
* sa = gcp.serviceaccount.Account("sa",
* account_id="my-service-account",
* display_name="A service account that only Jane can interact with")
* admin_account_iam = gcp.serviceaccount.IAMPolicy("admin-account-iam",
* service_account_id=sa.name,
* policy_data=admin.policy_data)
* ```
* ```csharp
* using System.Collections.Generic;
* using System.Linq;
* using Pulumi;
* using Gcp = Pulumi.Gcp;
* return await Deployment.RunAsync(() =>
* {
* var admin = Gcp.Organizations.GetIAMPolicy.Invoke(new()
* {
* Bindings = new[]
* {
* new Gcp.Organizations.Inputs.GetIAMPolicyBindingInputArgs
* {
* Role = "roles/iam.serviceAccountUser",
* Members = new[]
* {
* "user:[email protected]",
* },
* },
* },
* });
* var sa = new Gcp.ServiceAccount.Account("sa", new()
* {
* AccountId = "my-service-account",
* DisplayName = "A service account that only Jane can interact with",
* });
* var admin_account_iam = new Gcp.ServiceAccount.IAMPolicy("admin-account-iam", new()
* {
* ServiceAccountId = sa.Name,
* PolicyData = admin.Apply(getIAMPolicyResult => getIAMPolicyResult.PolicyData),
* });
* });
* ```
* ```go
* package main
* import (
* "github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/organizations"
* "github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/serviceaccount"
* "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
* )
* func main() {
* pulumi.Run(func(ctx *pulumi.Context) error {
* admin, err := organizations.LookupIAMPolicy(ctx, &organizations.LookupIAMPolicyArgs{
* Bindings: []organizations.GetIAMPolicyBinding{
* {
* Role: "roles/iam.serviceAccountUser",
* Members: []string{
* "user:[email protected]",
* },
* },
* },
* }, nil)
* if err != nil {
* return err
* }
* sa, err := serviceaccount.NewAccount(ctx, "sa", &serviceaccount.AccountArgs{
* AccountId: pulumi.String("my-service-account"),
* DisplayName: pulumi.String("A service account that only Jane can interact with"),
* })
* if err != nil {
* return err
* }
* _, err = serviceaccount.NewIAMPolicy(ctx, "admin-account-iam", &serviceaccount.IAMPolicyArgs{
* ServiceAccountId: sa.Name,
* PolicyData: pulumi.String(admin.PolicyData),
* })
* if err != nil {
* return err
* }
* return nil
* })
* }
* ```
* ```java
* 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.GetIAMPolicyArgs;
* import com.pulumi.gcp.serviceaccount.Account;
* import com.pulumi.gcp.serviceaccount.AccountArgs;
* import com.pulumi.gcp.serviceaccount.IAMPolicy;
* import com.pulumi.gcp.serviceaccount.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) {
* final var admin = OrganizationsFunctions.getIAMPolicy(GetIAMPolicyArgs.builder()
* .bindings(GetIAMPolicyBindingArgs.builder()
* .role("roles/iam.serviceAccountUser")
* .members("user:[email protected]")
* .build())
* .build());
* var sa = new Account("sa", AccountArgs.builder()
* .accountId("my-service-account")
* .displayName("A service account that only Jane can interact with")
* .build());
* var admin_account_iam = new IAMPolicy("admin-account-iam", IAMPolicyArgs.builder()
* .serviceAccountId(sa.name())
* .policyData(admin.applyValue(getIAMPolicyResult -> getIAMPolicyResult.policyData()))
* .build());
* }
* }
* ```
* ```yaml
* resources:
* sa:
* type: gcp:serviceaccount:Account
* properties:
* accountId: my-service-account
* displayName: A service account that only Jane can interact with
* admin-account-iam:
* type: gcp:serviceaccount:IAMPolicy
* properties:
* serviceAccountId: ${sa.name}
* policyData: ${admin.policyData}
* variables:
* admin:
* fn::invoke:
* Function: gcp:organizations:getIAMPolicy
* Arguments:
* bindings:
* - role: roles/iam.serviceAccountUser
* members:
* - user:[email protected]
* ```
*
* ### Service Account IAM Binding
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as gcp from "@pulumi/gcp";
* const sa = new gcp.serviceaccount.Account("sa", {
* accountId: "my-service-account",
* displayName: "A service account that only Jane can use",
* });
* const admin_account_iam = new gcp.serviceaccount.IAMBinding("admin-account-iam", {
* serviceAccountId: sa.name,
* role: "roles/iam.serviceAccountUser",
* members: ["user:jane@example.com"],
* });
* ```
* ```python
* import pulumi
* import pulumi_gcp as gcp
* sa = gcp.serviceaccount.Account("sa",
* account_id="my-service-account",
* display_name="A service account that only Jane can use")
* admin_account_iam = gcp.serviceaccount.IAMBinding("admin-account-iam",
* service_account_id=sa.name,
* role="roles/iam.serviceAccountUser",
* members=["user:jane@example.com"])
* ```
* ```csharp
* using System.Collections.Generic;
* using System.Linq;
* using Pulumi;
* using Gcp = Pulumi.Gcp;
* return await Deployment.RunAsync(() =>
* {
* var sa = new Gcp.ServiceAccount.Account("sa", new()
* {
* AccountId = "my-service-account",
* DisplayName = "A service account that only Jane can use",
* });
* var admin_account_iam = new Gcp.ServiceAccount.IAMBinding("admin-account-iam", new()
* {
* ServiceAccountId = sa.Name,
* Role = "roles/iam.serviceAccountUser",
* Members = new[]
* {
* "user:[email protected]",
* },
* });
* });
* ```
* ```go
* package main
* import (
* "github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/serviceaccount"
* "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
* )
* func main() {
* pulumi.Run(func(ctx *pulumi.Context) error {
* sa, err := serviceaccount.NewAccount(ctx, "sa", &serviceaccount.AccountArgs{
* AccountId: pulumi.String("my-service-account"),
* DisplayName: pulumi.String("A service account that only Jane can use"),
* })
* if err != nil {
* return err
* }
* _, err = serviceaccount.NewIAMBinding(ctx, "admin-account-iam", &serviceaccount.IAMBindingArgs{
* ServiceAccountId: sa.Name,
* Role: pulumi.String("roles/iam.serviceAccountUser"),
* Members: pulumi.StringArray{
* pulumi.String("user:[email protected]"),
* },
* })
* if err != nil {
* return err
* }
* return nil
* })
* }
* ```
* ```java
* package generated_program;
* import com.pulumi.Context;
* import com.pulumi.Pulumi;
* import com.pulumi.core.Output;
* import com.pulumi.gcp.serviceaccount.Account;
* import com.pulumi.gcp.serviceaccount.AccountArgs;
* import com.pulumi.gcp.serviceaccount.IAMBinding;
* import com.pulumi.gcp.serviceaccount.IAMBindingArgs;
* 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 sa = new Account("sa", AccountArgs.builder()
* .accountId("my-service-account")
* .displayName("A service account that only Jane can use")
* .build());
* var admin_account_iam = new IAMBinding("admin-account-iam", IAMBindingArgs.builder()
* .serviceAccountId(sa.name())
* .role("roles/iam.serviceAccountUser")
* .members("user:[email protected]")
* .build());
* }
* }
* ```
* ```yaml
* resources:
* sa:
* type: gcp:serviceaccount:Account
* properties:
* accountId: my-service-account
* displayName: A service account that only Jane can use
* admin-account-iam:
* type: gcp:serviceaccount:IAMBinding
* properties:
* serviceAccountId: ${sa.name}
* role: roles/iam.serviceAccountUser
* members:
* - user:[email protected]
* ```
*
* ### Service Account IAM Binding With IAM Conditions:
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as gcp from "@pulumi/gcp";
* const sa = new gcp.serviceaccount.Account("sa", {
* accountId: "my-service-account",
* displayName: "A service account that only Jane can use",
* });
* const admin_account_iam = new gcp.serviceaccount.IAMBinding("admin-account-iam", {
* serviceAccountId: sa.name,
* role: "roles/iam.serviceAccountUser",
* members: ["user:jane@example.com"],
* condition: {
* title: "expires_after_2019_12_31",
* description: "Expiring at midnight of 2019-12-31",
* expression: "request.time < timestamp(\"2020-01-01T00:00:00Z\")",
* },
* });
* ```
* ```python
* import pulumi
* import pulumi_gcp as gcp
* sa = gcp.serviceaccount.Account("sa",
* account_id="my-service-account",
* display_name="A service account that only Jane can use")
* admin_account_iam = gcp.serviceaccount.IAMBinding("admin-account-iam",
* service_account_id=sa.name,
* role="roles/iam.serviceAccountUser",
* members=["user:jane@example.com"],
* condition=gcp.serviceaccount.IAMBindingConditionArgs(
* title="expires_after_2019_12_31",
* description="Expiring at midnight of 2019-12-31",
* expression="request.time < timestamp(\"2020-01-01T00:00:00Z\")",
* ))
* ```
* ```csharp
* using System.Collections.Generic;
* using System.Linq;
* using Pulumi;
* using Gcp = Pulumi.Gcp;
* return await Deployment.RunAsync(() =>
* {
* var sa = new Gcp.ServiceAccount.Account("sa", new()
* {
* AccountId = "my-service-account",
* DisplayName = "A service account that only Jane can use",
* });
* var admin_account_iam = new Gcp.ServiceAccount.IAMBinding("admin-account-iam", new()
* {
* ServiceAccountId = sa.Name,
* Role = "roles/iam.serviceAccountUser",
* Members = new[]
* {
* "user:[email protected]",
* },
* Condition = new Gcp.ServiceAccount.Inputs.IAMBindingConditionArgs
* {
* Title = "expires_after_2019_12_31",
* Description = "Expiring at midnight of 2019-12-31",
* Expression = "request.time < timestamp(\"2020-01-01T00:00:00Z\")",
* },
* });
* });
* ```
* ```go
* package main
* import (
* "github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/serviceaccount"
* "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
* )
* func main() {
* pulumi.Run(func(ctx *pulumi.Context) error {
* sa, err := serviceaccount.NewAccount(ctx, "sa", &serviceaccount.AccountArgs{
* AccountId: pulumi.String("my-service-account"),
* DisplayName: pulumi.String("A service account that only Jane can use"),
* })
* if err != nil {
* return err
* }
* _, err = serviceaccount.NewIAMBinding(ctx, "admin-account-iam", &serviceaccount.IAMBindingArgs{
* ServiceAccountId: sa.Name,
* Role: pulumi.String("roles/iam.serviceAccountUser"),
* Members: pulumi.StringArray{
* pulumi.String("user:[email protected]"),
* },
* Condition: &serviceaccount.IAMBindingConditionArgs{
* Title: pulumi.String("expires_after_2019_12_31"),
* Description: pulumi.String("Expiring at midnight of 2019-12-31"),
* Expression: pulumi.String("request.time < timestamp(\"2020-01-01T00:00:00Z\")"),
* },
* })
* if err != nil {
* return err
* }
* return nil
* })
* }
* ```
* ```java
* package generated_program;
* import com.pulumi.Context;
* import com.pulumi.Pulumi;
* import com.pulumi.core.Output;
* import com.pulumi.gcp.serviceaccount.Account;
* import com.pulumi.gcp.serviceaccount.AccountArgs;
* import com.pulumi.gcp.serviceaccount.IAMBinding;
* import com.pulumi.gcp.serviceaccount.IAMBindingArgs;
* import com.pulumi.gcp.serviceaccount.inputs.IAMBindingConditionArgs;
* 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 sa = new Account("sa", AccountArgs.builder()
* .accountId("my-service-account")
* .displayName("A service account that only Jane can use")
* .build());
* var admin_account_iam = new IAMBinding("admin-account-iam", IAMBindingArgs.builder()
* .serviceAccountId(sa.name())
* .role("roles/iam.serviceAccountUser")
* .members("user:[email protected]")
* .condition(IAMBindingConditionArgs.builder()
* .title("expires_after_2019_12_31")
* .description("Expiring at midnight of 2019-12-31")
* .expression("request.time < timestamp(\"2020-01-01T00:00:00Z\")")
* .build())
* .build());
* }
* }
* ```
* ```yaml
* resources:
* sa:
* type: gcp:serviceaccount:Account
* properties:
* accountId: my-service-account
* displayName: A service account that only Jane can use
* admin-account-iam:
* type: gcp:serviceaccount:IAMBinding
* properties:
* serviceAccountId: ${sa.name}
* role: roles/iam.serviceAccountUser
* members:
* - user:[email protected]
* condition:
* title: expires_after_2019_12_31
* description: Expiring at midnight of 2019-12-31
* expression: request.time < timestamp("2020-01-01T00:00:00Z")
* ```
*
* ### Service Account IAM Member
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as gcp from "@pulumi/gcp";
* const default = gcp.compute.getDefaultServiceAccount({});
* const sa = new gcp.serviceaccount.Account("sa", {
* accountId: "my-service-account",
* displayName: "A service account that Jane can use",
* });
* const admin_account_iam = new gcp.serviceaccount.IAMMember("admin-account-iam", {
* serviceAccountId: sa.name,
* role: "roles/iam.serviceAccountUser",
* member: "user:[email protected]",
* });
* // Allow SA service account use the default GCE account
* const gce_default_account_iam = new gcp.serviceaccount.IAMMember("gce-default-account-iam", {
* serviceAccountId: _default.then(_default => _default.name),
* role: "roles/iam.serviceAccountUser",
* member: pulumi.interpolate`serviceAccount:${sa.email}`,
* });
* ```
* ```python
* import pulumi
* import pulumi_gcp as gcp
* default = gcp.compute.get_default_service_account()
* sa = gcp.serviceaccount.Account("sa",
* account_id="my-service-account",
* display_name="A service account that Jane can use")
* admin_account_iam = gcp.serviceaccount.IAMMember("admin-account-iam",
* service_account_id=sa.name,
* role="roles/iam.serviceAccountUser",
* member="user:[email protected]")
* # Allow SA service account use the default GCE account
* gce_default_account_iam = gcp.serviceaccount.IAMMember("gce-default-account-iam",
* service_account_id=default.name,
* role="roles/iam.serviceAccountUser",
* member=sa.email.apply(lambda email: f"serviceAccount:{email}"))
* ```
* ```csharp
* using System.Collections.Generic;
* using System.Linq;
* using Pulumi;
* using Gcp = Pulumi.Gcp;
* return await Deployment.RunAsync(() =>
* {
* var @default = Gcp.Compute.GetDefaultServiceAccount.Invoke();
* var sa = new Gcp.ServiceAccount.Account("sa", new()
* {
* AccountId = "my-service-account",
* DisplayName = "A service account that Jane can use",
* });
* var admin_account_iam = new Gcp.ServiceAccount.IAMMember("admin-account-iam", new()
* {
* ServiceAccountId = sa.Name,
* Role = "roles/iam.serviceAccountUser",
* Member = "user:[email protected]",
* });
* // Allow SA service account use the default GCE account
* var gce_default_account_iam = new Gcp.ServiceAccount.IAMMember("gce-default-account-iam", new()
* {
* ServiceAccountId = @default.Apply(@default => @default.Apply(getDefaultServiceAccountResult => getDefaultServiceAccountResult.Name)),
* Role = "roles/iam.serviceAccountUser",
* Member = sa.Email.Apply(email => $"serviceAccount:{email}"),
* });
* });
* ```
* ```go
* package main
* import (
* "fmt"
* "github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/compute"
* "github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/serviceaccount"
* "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
* )
* func main() {
* pulumi.Run(func(ctx *pulumi.Context) error {
* _default, err := compute.GetDefaultServiceAccount(ctx, nil, nil)
* if err != nil {
* return err
* }
* sa, err := serviceaccount.NewAccount(ctx, "sa", &serviceaccount.AccountArgs{
* AccountId: pulumi.String("my-service-account"),
* DisplayName: pulumi.String("A service account that Jane can use"),
* })
* if err != nil {
* return err
* }
* _, err = serviceaccount.NewIAMMember(ctx, "admin-account-iam", &serviceaccount.IAMMemberArgs{
* ServiceAccountId: sa.Name,
* Role: pulumi.String("roles/iam.serviceAccountUser"),
* Member: pulumi.String("user:[email protected]"),
* })
* if err != nil {
* return err
* }
* // Allow SA service account use the default GCE account
* _, err = serviceaccount.NewIAMMember(ctx, "gce-default-account-iam", &serviceaccount.IAMMemberArgs{
* ServiceAccountId: pulumi.String(_default.Name),
* Role: pulumi.String("roles/iam.serviceAccountUser"),
* Member: sa.Email.ApplyT(func(email string) (string, error) {
* return fmt.Sprintf("serviceAccount:%v", email), nil
* }).(pulumi.StringOutput),
* })
* if err != nil {
* return err
* }
* return nil
* })
* }
* ```
* ```java
* package generated_program;
* import com.pulumi.Context;
* import com.pulumi.Pulumi;
* import com.pulumi.core.Output;
* import com.pulumi.gcp.compute.ComputeFunctions;
* import com.pulumi.gcp.compute.inputs.GetDefaultServiceAccountArgs;
* import com.pulumi.gcp.serviceaccount.Account;
* import com.pulumi.gcp.serviceaccount.AccountArgs;
* import com.pulumi.gcp.serviceaccount.IAMMember;
* import com.pulumi.gcp.serviceaccount.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 default = ComputeFunctions.getDefaultServiceAccount();
* var sa = new Account("sa", AccountArgs.builder()
* .accountId("my-service-account")
* .displayName("A service account that Jane can use")
* .build());
* var admin_account_iam = new IAMMember("admin-account-iam", IAMMemberArgs.builder()
* .serviceAccountId(sa.name())
* .role("roles/iam.serviceAccountUser")
* .member("user:[email protected]")
* .build());
* // Allow SA service account use the default GCE account
* var gce_default_account_iam = new IAMMember("gce-default-account-iam", IAMMemberArgs.builder()
* .serviceAccountId(default_.name())
* .role("roles/iam.serviceAccountUser")
* .member(sa.email().applyValue(email -> String.format("serviceAccount:%s", email)))
* .build());
* }
* }
* ```
* ```yaml
* resources:
* sa:
* type: gcp:serviceaccount:Account
* properties:
* accountId: my-service-account
* displayName: A service account that Jane can use
* admin-account-iam:
* type: gcp:serviceaccount:IAMMember
* properties:
* serviceAccountId: ${sa.name}
* role: roles/iam.serviceAccountUser
* member: user:[email protected]
* # Allow SA service account use the default GCE account
* gce-default-account-iam:
* type: gcp:serviceaccount:IAMMember
* properties:
* serviceAccountId: ${default.name}
* role: roles/iam.serviceAccountUser
* member: serviceAccount:${sa.email}
* variables:
* default:
* fn::invoke:
* Function: gcp:compute:getDefaultServiceAccount
* Arguments: {}
* ```
*
* ### Service Account IAM Member With IAM Conditions:
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as gcp from "@pulumi/gcp";
* const sa = new gcp.serviceaccount.Account("sa", {
* accountId: "my-service-account",
* displayName: "A service account that Jane can use",
* });
* const admin_account_iam = new gcp.serviceaccount.IAMMember("admin-account-iam", {
* serviceAccountId: sa.name,
* role: "roles/iam.serviceAccountUser",
* member: "user:[email protected]",
* condition: {
* title: "expires_after_2019_12_31",
* description: "Expiring at midnight of 2019-12-31",
* expression: "request.time < timestamp(\"2020-01-01T00:00:00Z\")",
* },
* });
* ```
* ```python
* import pulumi
* import pulumi_gcp as gcp
* sa = gcp.serviceaccount.Account("sa",
* account_id="my-service-account",
* display_name="A service account that Jane can use")
* admin_account_iam = gcp.serviceaccount.IAMMember("admin-account-iam",
* service_account_id=sa.name,
* role="roles/iam.serviceAccountUser",
* member="user:[email protected]",
* condition=gcp.serviceaccount.IAMMemberConditionArgs(
* title="expires_after_2019_12_31",
* description="Expiring at midnight of 2019-12-31",
* expression="request.time < timestamp(\"2020-01-01T00:00:00Z\")",
* ))
* ```
* ```csharp
* using System.Collections.Generic;
* using System.Linq;
* using Pulumi;
* using Gcp = Pulumi.Gcp;
* return await Deployment.RunAsync(() =>
* {
* var sa = new Gcp.ServiceAccount.Account("sa", new()
* {
* AccountId = "my-service-account",
* DisplayName = "A service account that Jane can use",
* });
* var admin_account_iam = new Gcp.ServiceAccount.IAMMember("admin-account-iam", new()
* {
* ServiceAccountId = sa.Name,
* Role = "roles/iam.serviceAccountUser",
* Member = "user:[email protected]",
* Condition = new Gcp.ServiceAccount.Inputs.IAMMemberConditionArgs
* {
* Title = "expires_after_2019_12_31",
* Description = "Expiring at midnight of 2019-12-31",
* Expression = "request.time < timestamp(\"2020-01-01T00:00:00Z\")",
* },
* });
* });
* ```
* ```go
* package main
* import (
* "github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/serviceaccount"
* "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
* )
* func main() {
* pulumi.Run(func(ctx *pulumi.Context) error {
* sa, err := serviceaccount.NewAccount(ctx, "sa", &serviceaccount.AccountArgs{
* AccountId: pulumi.String("my-service-account"),
* DisplayName: pulumi.String("A service account that Jane can use"),
* })
* if err != nil {
* return err
* }
* _, err = serviceaccount.NewIAMMember(ctx, "admin-account-iam", &serviceaccount.IAMMemberArgs{
* ServiceAccountId: sa.Name,
* Role: pulumi.String("roles/iam.serviceAccountUser"),
* Member: pulumi.String("user:[email protected]"),
* Condition: &serviceaccount.IAMMemberConditionArgs{
* Title: pulumi.String("expires_after_2019_12_31"),
* Description: pulumi.String("Expiring at midnight of 2019-12-31"),
* Expression: pulumi.String("request.time < timestamp(\"2020-01-01T00:00:00Z\")"),
* },
* })
* if err != nil {
* return err
* }
* return nil
* })
* }
* ```
* ```java
* package generated_program;
* import com.pulumi.Context;
* import com.pulumi.Pulumi;
* import com.pulumi.core.Output;
* import com.pulumi.gcp.serviceaccount.Account;
* import com.pulumi.gcp.serviceaccount.AccountArgs;
* import com.pulumi.gcp.serviceaccount.IAMMember;
* import com.pulumi.gcp.serviceaccount.IAMMemberArgs;
* import com.pulumi.gcp.serviceaccount.inputs.IAMMemberConditionArgs;
* 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 sa = new Account("sa", AccountArgs.builder()
* .accountId("my-service-account")
* .displayName("A service account that Jane can use")
* .build());
* var admin_account_iam = new IAMMember("admin-account-iam", IAMMemberArgs.builder()
* .serviceAccountId(sa.name())
* .role("roles/iam.serviceAccountUser")
* .member("user:[email protected]")
* .condition(IAMMemberConditionArgs.builder()
* .title("expires_after_2019_12_31")
* .description("Expiring at midnight of 2019-12-31")
* .expression("request.time < timestamp(\"2020-01-01T00:00:00Z\")")
* .build())
* .build());
* }
* }
* ```
* ```yaml
* resources:
* sa:
* type: gcp:serviceaccount:Account
* properties:
* accountId: my-service-account
* displayName: A service account that Jane can use
* admin-account-iam:
* type: gcp:serviceaccount:IAMMember
* properties:
* serviceAccountId: ${sa.name}
* role: roles/iam.serviceAccountUser
* member: user:[email protected]
* condition:
* title: expires_after_2019_12_31
* description: Expiring at midnight of 2019-12-31
* expression: request.time < timestamp("2020-01-01T00:00:00Z")
* ```
*
* ## Import
* ### Importing with conditions:
* Here are examples of importing IAM memberships and bindings that include conditions:
* ```sh
* $ pulumi import gcp:serviceaccount/iAMMember:IAMMember admin-account-iam "projects/{your-project-id}/serviceAccounts/{your-service-account-email} roles/iam.serviceAccountUser expires_after_2019_12_31"
* ```
* ```sh
* $ pulumi import gcp:serviceaccount/iAMMember:IAMMember admin-account-iam "projects/{your-project-id}/serviceAccounts/{your-service-account-email} roles/iam.serviceAccountUser user:[email protected] expires_after_2019_12_31"
* ```
* @property condition An [IAM Condition](https://cloud.google.com/iam/docs/conditions-overview) for a given binding.
* Structure is documented below.
* @property member Identities that will be granted the privilege in `role`.
* Each entry can have one of the following values:
* * **allUsers**: A special identifier that represents anyone who is on the internet; with or without a Google account.
* * **allAuthenticatedUsers**: A special identifier that represents anyone who is authenticated with a Google account or a service account.
* * **user:{emailid}**: An email address that represents a specific Google account. For example, [email protected] or [email protected].
* * **serviceAccount:{emailid}**: An email address that represents a service account. For example, [email protected].
* * **group:{emailid}**: An email address that represents a Google group. For example, [email protected].
* * **domain:{domain}**: A G Suite domain (primary, instead of alias) name that represents all the users of that domain. For example, google.com or example.com.
* @property role The role that should be applied. Only one
* `gcp.serviceaccount.IAMBinding` can be used per role. Note that custom roles must be of the format
* `[projects|organizations]/{parent-name}/roles/{role-name}`.
* @property serviceAccountId The fully-qualified name of the service account to apply policy to.
*/
public data class IAMMemberArgs(
public val condition: Output? = null,
public val member: Output? = null,
public val role: Output? = null,
public val serviceAccountId: Output? = null,
) : ConvertibleToJava {
override fun toJava(): com.pulumi.gcp.serviceaccount.IAMMemberArgs =
com.pulumi.gcp.serviceaccount.IAMMemberArgs.builder()
.condition(condition?.applyValue({ args0 -> args0.let({ args0 -> args0.toJava() }) }))
.member(member?.applyValue({ args0 -> args0 }))
.role(role?.applyValue({ args0 -> args0 }))
.serviceAccountId(serviceAccountId?.applyValue({ args0 -> args0 })).build()
}
/**
* Builder for [IAMMemberArgs].
*/
@PulumiTagMarker
public class IAMMemberArgsBuilder internal constructor() {
private var condition: Output? = null
private var member: Output? = null
private var role: Output? = null
private var serviceAccountId: Output? = null
/**
* @param value An [IAM Condition](https://cloud.google.com/iam/docs/conditions-overview) for a given binding.
* Structure is documented below.
*/
@JvmName("dtmpwnoepthafmgw")
public suspend fun condition(`value`: Output) {
this.condition = value
}
/**
* @param value Identities that will be granted the privilege in `role`.
* Each entry can have one of the following values:
* * **allUsers**: A special identifier that represents anyone who is on the internet; with or without a Google account.
* * **allAuthenticatedUsers**: A special identifier that represents anyone who is authenticated with a Google account or a service account.
* * **user:{emailid}**: An email address that represents a specific Google account. For example, [email protected] or [email protected].
* * **serviceAccount:{emailid}**: An email address that represents a service account. For example, [email protected].
* * **group:{emailid}**: An email address that represents a Google group. For example, [email protected].
* * **domain:{domain}**: A G Suite domain (primary, instead of alias) name that represents all the users of that domain. For example, google.com or example.com.
*/
@JvmName("ogtnntoyraqtlvvg")
public suspend fun member(`value`: Output) {
this.member = value
}
/**
* @param value The role that should be applied. Only one
* `gcp.serviceaccount.IAMBinding` can be used per role. Note that custom roles must be of the format
* `[projects|organizations]/{parent-name}/roles/{role-name}`.
*/
@JvmName("fcqtbdfpitjfhdct")
public suspend fun role(`value`: Output) {
this.role = value
}
/**
* @param value The fully-qualified name of the service account to apply policy to.
*/
@JvmName("ahfjespvmbeuqalg")
public suspend fun serviceAccountId(`value`: Output) {
this.serviceAccountId = value
}
/**
* @param value An [IAM Condition](https://cloud.google.com/iam/docs/conditions-overview) for a given binding.
* Structure is documented below.
*/
@JvmName("atcmpaqpescdimkp")
public suspend fun condition(`value`: IAMMemberConditionArgs?) {
val toBeMapped = value
val mapped = toBeMapped?.let({ args0 -> of(args0) })
this.condition = mapped
}
/**
* @param argument An [IAM Condition](https://cloud.google.com/iam/docs/conditions-overview) for a given binding.
* Structure is documented below.
*/
@JvmName("fmxoftvmveotaioi")
public suspend fun condition(argument: suspend IAMMemberConditionArgsBuilder.() -> Unit) {
val toBeMapped = IAMMemberConditionArgsBuilder().applySuspend { argument() }.build()
val mapped = of(toBeMapped)
this.condition = mapped
}
/**
* @param value Identities that will be granted the privilege in `role`.
* Each entry can have one of the following values:
* * **allUsers**: A special identifier that represents anyone who is on the internet; with or without a Google account.
* * **allAuthenticatedUsers**: A special identifier that represents anyone who is authenticated with a Google account or a service account.
* * **user:{emailid}**: An email address that represents a specific Google account. For example, [email protected] or [email protected].
* * **serviceAccount:{emailid}**: An email address that represents a service account. For example, [email protected].
* * **group:{emailid}**: An email address that represents a Google group. For example, [email protected].
* * **domain:{domain}**: A G Suite domain (primary, instead of alias) name that represents all the users of that domain. For example, google.com or example.com.
*/
@JvmName("jxnhmxxxljvceqtx")
public suspend fun member(`value`: String?) {
val toBeMapped = value
val mapped = toBeMapped?.let({ args0 -> of(args0) })
this.member = mapped
}
/**
* @param value The role that should be applied. Only one
* `gcp.serviceaccount.IAMBinding` can be used per role. Note that custom roles must be of the format
* `[projects|organizations]/{parent-name}/roles/{role-name}`.
*/
@JvmName("xhccvryosyfruyxf")
public suspend fun role(`value`: String?) {
val toBeMapped = value
val mapped = toBeMapped?.let({ args0 -> of(args0) })
this.role = mapped
}
/**
* @param value The fully-qualified name of the service account to apply policy to.
*/
@JvmName("ucbofbkfmqltujja")
public suspend fun serviceAccountId(`value`: String?) {
val toBeMapped = value
val mapped = toBeMapped?.let({ args0 -> of(args0) })
this.serviceAccountId = mapped
}
internal fun build(): IAMMemberArgs = IAMMemberArgs(
condition = condition,
member = member,
role = role,
serviceAccountId = serviceAccountId,
)
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy