UNPKG

@pulumi/gcp

Version:

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

141 lines 6.64 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.ProvisionScript = void 0; const pulumi = __importStar(require("@pulumi/pulumi")); const utilities = __importStar(require("../utilities")); /** * Executes a SQL script to provision in-database resources on a Cloud SQL Instance. For more information, see the [Cloud SQL official documentation](https://cloud.google.com/sql/docs/postgres/executesql-instance), or the [JSON API](https://cloud.google.com/sql/docs/admin-api/v1beta4/instances/executeSql). * * > **Warning:** The SQL script and its execution response might transit through intermediate locations between your client and the location of the target instance. * * > **Note:** Terraform connects to the instance via [IAM database authentication](https://cloud.google.com/sql/docs/mysql/authentication) to execute the script, so the identity account used to apply your Terraform config must exist as an IAM user or IAM service account in the instance. You also need to grant roles or privileges to this IAM user or IAM service account so it has permission to execute statements in your provision scripts. See the example below. * * ## Example Usage * * Example managing a Cloud SQL Postgres instance with a provision script. * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * * const instance = new gcp.sql.DatabaseInstance("instance", { * name: "my-instance", * databaseVersion: "POSTGRES_17", * settings: { * tier: "db-perf-optimized-N-2", * dataApiAccess: "ALLOW_DATA_API", * databaseFlags: [{ * name: "cloudsql.iam_authentication", * value: "on", * }], * }, * }); * // Create a database user for your account and grant roles so it has privilege to access the database. * // Set the type to "CLOUD_IAM_USER" for huamn account or "CLOUD_IAM_SERVICE_ACCOUNT" for service account. * // If a service account is used and the instance is Postgres, please trim the ".gserviceaccount.com" suffix * // to avoid exceeding the username length limit. * const iamUser = new gcp.sql.User("iam_user", { * name: "account-used-to-apply-this-config@example.com", * instance: instance.name, * type: "CLOUD_IAM_USER", * databaseRoles: ["cloudsqlsuperuser"], * }); * const database = new gcp.sql.Database("database", { * name: "my-database", * instance: instance.name, * }); * const table = new gcp.sql.ProvisionScript("table", { * script: "CREATE TABLE IF NOT EXISTS table1 ( col VARCHAR(16) NOT NULL );", * instance: instance.name, * database: database.name, * description: "sql script to create tables", * }, { * dependsOn: [iamUser], * }); * ``` * * Example managing a Cloud SQL MySQL instance with a provision script. */ class ProvisionScript extends pulumi.CustomResource { /** * Get an existing ProvisionScript 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, id, state, opts) { return new ProvisionScript(name, state, { ...opts, id: id }); } /** @internal */ static __pulumiType = 'gcp:sql/provisionScript:ProvisionScript'; /** * Returns true if the given object is an instance of ProvisionScript. This is designed to work even * when multiple copies of the Pulumi SDK have been loaded into the same process. */ static isInstance(obj) { if (obj === undefined || obj === null) { return false; } return obj['__pulumiType'] === ProvisionScript.__pulumiType; } constructor(name, argsOrState, opts) { let resourceInputs = {}; opts = opts || {}; if (opts.id) { const state = argsOrState; resourceInputs["database"] = state?.database; resourceInputs["deletionPolicy"] = state?.deletionPolicy; resourceInputs["description"] = state?.description; resourceInputs["instance"] = state?.instance; resourceInputs["project"] = state?.project; resourceInputs["script"] = state?.script; } else { const args = argsOrState; if (args?.instance === undefined && !opts.urn) { throw new Error("Missing required property 'instance'"); } if (args?.script === undefined && !opts.urn) { throw new Error("Missing required property 'script'"); } resourceInputs["database"] = args?.database; resourceInputs["deletionPolicy"] = args?.deletionPolicy; resourceInputs["description"] = args?.description; resourceInputs["instance"] = args?.instance; resourceInputs["project"] = args?.project; resourceInputs["script"] = args?.script; } opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts); super(ProvisionScript.__pulumiType, name, resourceInputs, opts); } } exports.ProvisionScript = ProvisionScript; //# sourceMappingURL=provisionScript.js.map