UNPKG

@pulumi/gcp

Version:

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

244 lines • 9.54 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.User = void 0; const pulumi = __importStar(require("@pulumi/pulumi")); const utilities = __importStar(require("../utilities")); /** * Creates a new Google SQL User on a Google SQL User Instance. For more information, see the [official documentation](https://cloud.google.com/sql/), or the [JSON API](https://cloud.google.com/sql/docs/admin-api/v1beta4/users). * * Read more about sensitive data in state. Passwords will not be retrieved when running * "terraform import". * * > **Note:** Write-Only argument `passwordWo` is available to use in place of `password`. Write-Only arguments are supported in HashiCorp Terraform 1.11.0 and later. Learn more. * * ## Example Usage * * Example creating a SQL User. * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * import * as random from "@pulumi/random"; * * const dbNameSuffix = new random.index.Id("db_name_suffix", {byteLength: 4}); * const main = new gcp.sql.DatabaseInstance("main", { * name: `main-instance-${dbNameSuffix.hex}`, * databaseVersion: "MYSQL_5_7", * settings: { * tier: "db-f1-micro", * }, * }); * const users = new gcp.sql.User("users", { * name: "me", * instance: main.name, * host: "me.com", * password: "changeme", * }); * ``` * * Example creating a SQL User with database roles(applicable for Postgres/MySQL * only). * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * import * as random from "@pulumi/random"; * * const dbNameSuffix = new random.index.Id("db_name_suffix", {byteLength: 4}); * const main = new gcp.sql.DatabaseInstance("main", { * name: `main-instance-${dbNameSuffix.hex}`, * databaseVersion: "POSTGRES_15", * settings: { * tier: "db-f1-micro", * }, * }); * const users = new gcp.sql.User("users", { * name: "me", * instance: main.name, * host: "me.com", * password: "changeme", * databaseRoles: ["cloudsqlsuperuser"], * }); * ``` * * Example using [Cloud SQL IAM database authentication](https://cloud.google.com/sql/docs/mysql/authentication). * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * import * as random from "@pulumi/random"; * import * as std from "@pulumi/std"; * * const dbNameSuffix = new random.index.Id("db_name_suffix", {byteLength: 4}); * const main = new gcp.sql.DatabaseInstance("main", { * name: `main-instance-${dbNameSuffix.hex}`, * databaseVersion: "POSTGRES_15", * settings: { * tier: "db-f1-micro", * databaseFlags: [{ * name: "cloudsql.iam_authentication", * value: "on", * }], * }, * }); * const iamUser = new gcp.sql.User("iam_user", { * name: "me@example.com", * instance: main.name, * type: "CLOUD_IAM_USER", * }); * const iamServiceAccountUser = new gcp.sql.User("iam_service_account_user", { * name: std.trimsuffix({ * input: serviceAccount.email, * suffix: ".gserviceaccount.com", * }).then(invoke => invoke.result), * instance: main.name, * type: "CLOUD_IAM_SERVICE_ACCOUNT", * }); * ``` * * Example using [Cloud SQL IAM Group authentication](https://cloud.google.com/sql/docs/mysql/iam-authentication#iam-group-auth). * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as gcp from "@pulumi/gcp"; * import * as random from "@pulumi/random"; * * const dbNameSuffix = new random.index.Id("db_name_suffix", {byteLength: 4}); * const main = new gcp.sql.DatabaseInstance("main", { * name: `main-instance-${dbNameSuffix.hex}`, * databaseVersion: "MYSQL_8_0", * settings: { * tier: "db-f1-micro", * databaseFlags: [{ * name: "cloudsql_iam_authentication", * value: "on", * }], * }, * }); * const iamGroupUser = new gcp.sql.User("iam_group_user", { * name: "iam_group@example.com", * instance: main.name, * type: "CLOUD_IAM_GROUP", * }); * ``` * * ## Import * * SQL users for MySQL databases can be imported using the `project`, `instance`, `host` and `name`, e.g. * * * `{{project_id}}/{{instance}}/{{host}}/{{name}}` * * SQL users for PostgreSQL databases can be imported using the `project`, `instance` and `name`, e.g. * * * `{{project_id}}/{{instance}}/{{name}}` * * When using the `pulumi import` command, NAME_HERE can be imported using one of the formats above. For example: * * MySQL database * * ```sh * $ pulumi import gcp:sql/user:User default {{project_id}}/{{instance}}/{{host}}/{{name}} * ``` * * PostgreSQL database * * ```sh * $ pulumi import gcp:sql/user:User default {{project_id}}/{{instance}}/{{name}} * ``` */ class User extends pulumi.CustomResource { /** * Get an existing User 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 User(name, state, { ...opts, id: id }); } /** @internal */ static __pulumiType = 'gcp:sql/user:User'; /** * Returns true if the given object is an instance of User. 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'] === User.__pulumiType; } constructor(name, argsOrState, opts) { let resourceInputs = {}; opts = opts || {}; if (opts.id) { const state = argsOrState; resourceInputs["databaseRoles"] = state?.databaseRoles; resourceInputs["deletionPolicy"] = state?.deletionPolicy; resourceInputs["host"] = state?.host; resourceInputs["iamEmail"] = state?.iamEmail; resourceInputs["instance"] = state?.instance; resourceInputs["name"] = state?.name; resourceInputs["password"] = state?.password; resourceInputs["passwordPolicy"] = state?.passwordPolicy; resourceInputs["passwordWo"] = state?.passwordWo; resourceInputs["passwordWoVersion"] = state?.passwordWoVersion; resourceInputs["project"] = state?.project; resourceInputs["sqlServerUserDetails"] = state?.sqlServerUserDetails; resourceInputs["type"] = state?.type; } else { const args = argsOrState; if (args?.instance === undefined && !opts.urn) { throw new Error("Missing required property 'instance'"); } resourceInputs["databaseRoles"] = args?.databaseRoles; resourceInputs["deletionPolicy"] = args?.deletionPolicy; resourceInputs["host"] = args?.host; resourceInputs["instance"] = args?.instance; resourceInputs["name"] = args?.name; resourceInputs["password"] = args?.password ? pulumi.secret(args.password) : undefined; resourceInputs["passwordPolicy"] = args?.passwordPolicy; resourceInputs["passwordWo"] = args?.passwordWo ? pulumi.secret(args.passwordWo) : undefined; resourceInputs["passwordWoVersion"] = args?.passwordWoVersion; resourceInputs["project"] = args?.project; resourceInputs["type"] = args?.type; resourceInputs["iamEmail"] = undefined /*out*/; resourceInputs["sqlServerUserDetails"] = undefined /*out*/; } opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts); const secretOpts = { additionalSecretOutputs: ["password", "passwordWo"] }; opts = pulumi.mergeOptions(opts, secretOpts); super(User.__pulumiType, name, resourceInputs, opts); } } exports.User = User; //# sourceMappingURL=user.js.map