UNPKG

@pulumi/gcp

Version:

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

151 lines 6.92 kB
"use strict"; // *** WARNING: this file was generated by pulumi-language-nodejs. *** // *** Do not edit by hand unless you're certain you know what you are doing! *** var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAccountAccessTokenOutput = exports.getAccountAccessToken = void 0; const pulumi = __importStar(require("@pulumi/pulumi")); const utilities = __importStar(require("../utilities")); /** * This data source provides a google `oauth2` `accessToken` for a different service account than the one initially running the script. * * For more information see * [the official documentation](https://cloud.google.com/iam/docs/creating-short-lived-service-account-credentials) as well as [iamcredentials.generateAccessToken()](https://cloud.google.com/iam/credentials/reference/rest/v1/projects.serviceAccounts/generateAccessToken) * * ## Example Usage * * To allow `service_A` to impersonate `service_B`, grant the [Service Account Token Creator](https://cloud.google.com/iam/docs/service-accounts#the_service_account_token_creator_role) on B to A. * * In the IAM policy below, `service_A` is given the Token Creator role impersonate `service_B` * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const token_creator_iam = new gcp.serviceaccount.IAMBinding("token-creator-iam", { * serviceAccountId: "projects/-/serviceAccounts/service_B@projectB.iam.gserviceaccount.com", * role: "roles/iam.serviceAccountTokenCreator", * members: ["serviceAccount:service_A@projectA.iam.gserviceaccount.com"], * }); * ``` * * Once the IAM permissions are set, you can apply the new token to a provider bootstrapped with it. Any resources that references the aliased provider will run as the new identity. * * In the example below, `gcp.organizations.Project` will run as `service_B`. * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * export = async () => { * const _default = await gcp.organizations.getClientConfig({}); * const defaultGetAccountAccessToken = await gcp.serviceaccount.getAccountAccessToken({ * targetServiceAccount: "service_B@projectB.iam.gserviceaccount.com", * scopes: [ * "userinfo-email", * "cloud-platform", * ], * lifetime: "300s", * }); * const me = await gcp.organizations.getClientOpenIdUserInfo({}); * return { * "target-email": me.email, * }; * } * ``` * * > *Note*: the generated token is non-refreshable and can have a maximum `lifetime` of `3600` seconds. */ function getAccountAccessToken(args, opts) { opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts || {}); return pulumi.runtime.invoke("gcp:serviceaccount/getAccountAccessToken:getAccountAccessToken", { "delegates": args.delegates, "lifetime": args.lifetime, "scopes": args.scopes, "targetServiceAccount": args.targetServiceAccount, }, opts); } exports.getAccountAccessToken = getAccountAccessToken; /** * This data source provides a google `oauth2` `accessToken` for a different service account than the one initially running the script. * * For more information see * [the official documentation](https://cloud.google.com/iam/docs/creating-short-lived-service-account-credentials) as well as [iamcredentials.generateAccessToken()](https://cloud.google.com/iam/credentials/reference/rest/v1/projects.serviceAccounts/generateAccessToken) * * ## Example Usage * * To allow `service_A` to impersonate `service_B`, grant the [Service Account Token Creator](https://cloud.google.com/iam/docs/service-accounts#the_service_account_token_creator_role) on B to A. * * In the IAM policy below, `service_A` is given the Token Creator role impersonate `service_B` * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const token_creator_iam = new gcp.serviceaccount.IAMBinding("token-creator-iam", { * serviceAccountId: "projects/-/serviceAccounts/service_B@projectB.iam.gserviceaccount.com", * role: "roles/iam.serviceAccountTokenCreator", * members: ["serviceAccount:service_A@projectA.iam.gserviceaccount.com"], * }); * ``` * * Once the IAM permissions are set, you can apply the new token to a provider bootstrapped with it. Any resources that references the aliased provider will run as the new identity. * * In the example below, `gcp.organizations.Project` will run as `service_B`. * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * export = async () => { * const _default = await gcp.organizations.getClientConfig({}); * const defaultGetAccountAccessToken = await gcp.serviceaccount.getAccountAccessToken({ * targetServiceAccount: "service_B@projectB.iam.gserviceaccount.com", * scopes: [ * "userinfo-email", * "cloud-platform", * ], * lifetime: "300s", * }); * const me = await gcp.organizations.getClientOpenIdUserInfo({}); * return { * "target-email": me.email, * }; * } * ``` * * > *Note*: the generated token is non-refreshable and can have a maximum `lifetime` of `3600` seconds. */ function getAccountAccessTokenOutput(args, opts) { opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts || {}); return pulumi.runtime.invokeOutput("gcp:serviceaccount/getAccountAccessToken:getAccountAccessToken", { "delegates": args.delegates, "lifetime": args.lifetime, "scopes": args.scopes, "targetServiceAccount": args.targetServiceAccount, }, opts); } exports.getAccountAccessTokenOutput = getAccountAccessTokenOutput; //# sourceMappingURL=getAccountAccessToken.js.map