@pulumi/gcp
Version:
A Pulumi package for creating and managing Google Cloud Platform resources.
370 lines (369 loc) • 16.4 kB
TypeScript
import * as pulumi from "@pulumi/pulumi";
import * as inputs from "../types/input";
import * as outputs from "../types/output";
/**
* 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 googleProjectIam 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),
* });
* ```
*
* ### 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"],
* });
* ```
*
* ### 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\")",
* },
* });
* ```
*
* ### 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:jane@example.com",
* });
* // 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}`,
* });
* ```
*
* ### 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: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\")",
* },
* });
* ```
*
* ### 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),
* });
* ```
*
* ### 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"],
* });
* ```
*
* ### 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\")",
* },
* });
* ```
*
* ### 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:jane@example.com",
* });
* // 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}`,
* });
* ```
*
* ### 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: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\")",
* },
* });
* ```
*
* ## Import
*
* ### Importing with conditions:
*
* Here are examples of importing IAM memberships and bindings that include conditions:
*
* ```sh
* $ pulumi import gcp:serviceaccount/iAMBinding:IAMBinding 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/iAMBinding:IAMBinding admin-account-iam "projects/{your-project-id}/serviceAccounts/{your-service-account-email} roles/iam.serviceAccountUser user:foo@example.com expires_after_2019_12_31"
* ```
*/
export declare class IAMBinding extends pulumi.CustomResource {
/**
* Get an existing IAMBinding 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?: IAMBindingState, opts?: pulumi.CustomResourceOptions): IAMBinding;
/**
* Returns true if the given object is an instance of IAMBinding. 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 IAMBinding;
/**
* An [IAM Condition](https://cloud.google.com/iam/docs/conditions-overview) for a given binding.
* Structure is documented below.
*/
readonly condition: pulumi.Output<outputs.serviceaccount.IAMBindingCondition | undefined>;
/**
* (Computed) The etag of the service account IAM policy.
*/
readonly etag: pulumi.Output<string>;
/**
* 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, alice@gmail.com or joe@example.com.
* * **serviceAccount:{emailid}**: An email address that represents a service account. For example, my-other-app@appspot.gserviceaccount.com.
* * **group:{emailid}**: An email address that represents a Google group. For example, admins@example.com.
* * **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.
*/
readonly members: pulumi.Output<string[]>;
/**
* 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}`.
*/
readonly role: pulumi.Output<string>;
/**
* The fully-qualified name of the service account to apply policy to.
*/
readonly serviceAccountId: pulumi.Output<string>;
/**
* Create a IAMBinding 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: IAMBindingArgs, opts?: pulumi.CustomResourceOptions);
}
/**
* Input properties used for looking up and filtering IAMBinding resources.
*/
export interface IAMBindingState {
/**
* An [IAM Condition](https://cloud.google.com/iam/docs/conditions-overview) for a given binding.
* Structure is documented below.
*/
condition?: pulumi.Input<inputs.serviceaccount.IAMBindingCondition>;
/**
* (Computed) The etag of the service account IAM policy.
*/
etag?: pulumi.Input<string>;
/**
* 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, alice@gmail.com or joe@example.com.
* * **serviceAccount:{emailid}**: An email address that represents a service account. For example, my-other-app@appspot.gserviceaccount.com.
* * **group:{emailid}**: An email address that represents a Google group. For example, admins@example.com.
* * **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.
*/
members?: pulumi.Input<pulumi.Input<string>[]>;
/**
* 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}`.
*/
role?: pulumi.Input<string>;
/**
* The fully-qualified name of the service account to apply policy to.
*/
serviceAccountId?: pulumi.Input<string>;
}
/**
* The set of arguments for constructing a IAMBinding resource.
*/
export interface IAMBindingArgs {
/**
* An [IAM Condition](https://cloud.google.com/iam/docs/conditions-overview) for a given binding.
* Structure is documented below.
*/
condition?: pulumi.Input<inputs.serviceaccount.IAMBindingCondition>;
/**
* 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, alice@gmail.com or joe@example.com.
* * **serviceAccount:{emailid}**: An email address that represents a service account. For example, my-other-app@appspot.gserviceaccount.com.
* * **group:{emailid}**: An email address that represents a Google group. For example, admins@example.com.
* * **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.
*/
members: pulumi.Input<pulumi.Input<string>[]>;
/**
* 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}`.
*/
role: pulumi.Input<string>;
/**
* The fully-qualified name of the service account to apply policy to.
*/
serviceAccountId: pulumi.Input<string>;
}