UNPKG

@pulumi/gcp

Version:

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

128 lines 5.88 kB
"use strict"; // *** WARNING: this file was generated by the Pulumi Terraform Bridge (tfgen) Tool. *** // *** Do not edit by hand unless you're certain you know what you are doing! *** Object.defineProperty(exports, "__esModule", { value: true }); exports.getAccountAccessTokenOutput = exports.getAccountAccessToken = void 0; const pulumi = require("@pulumi/pulumi"); const utilities = 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