@pulumi/gcp
Version:
A Pulumi package for creating and managing Google Cloud Platform resources.
193 lines • 7.8 kB
JavaScript
;
// *** 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.User = void 0;
const pulumi = require("@pulumi/pulumi");
const utilities = 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).
*
* ## 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.RandomId("db_name_suffix", {byteLength: 4});
* const main = new gcp.sql.DatabaseInstance("main", {
* name: pulumi.interpolate`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 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.RandomId("db_name_suffix", {byteLength: 4});
* const main = new gcp.sql.DatabaseInstance("main", {
* name: pulumi.interpolate`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.RandomId("db_name_suffix", {byteLength: 4});
* const main = new gcp.sql.DatabaseInstance("main", {
* name: pulumi.interpolate`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",
* });
* ```
*
* ## Ephemeral Attributes Reference
*
* The following write-only attributes are supported:
*
* * `passwordWo` - (Optional) The password for the user. Can be updated. For Postgres
* instances this is a Required field, unless type is set to either CLOUD_IAM_USER
* or CLOUD_IAM_SERVICE_ACCOUNT. Don't set this field for CLOUD_IAM_USER
* and CLOUD_IAM_SERVICE_ACCOUNT user types for any Cloud SQL instance.
* **Note**: This property is write-only and will not be read from the API.
*
* ## 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, Object.assign(Object.assign({}, opts), { id: id }));
}
/**
* 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["deletionPolicy"] = state ? state.deletionPolicy : undefined;
resourceInputs["host"] = state ? state.host : undefined;
resourceInputs["instance"] = state ? state.instance : undefined;
resourceInputs["name"] = state ? state.name : undefined;
resourceInputs["password"] = state ? state.password : undefined;
resourceInputs["passwordPolicy"] = state ? state.passwordPolicy : undefined;
resourceInputs["project"] = state ? state.project : undefined;
resourceInputs["sqlServerUserDetails"] = state ? state.sqlServerUserDetails : undefined;
resourceInputs["type"] = state ? state.type : undefined;
}
else {
const args = argsOrState;
if ((!args || args.instance === undefined) && !opts.urn) {
throw new Error("Missing required property 'instance'");
}
resourceInputs["deletionPolicy"] = args ? args.deletionPolicy : undefined;
resourceInputs["host"] = args ? args.host : undefined;
resourceInputs["instance"] = args ? args.instance : undefined;
resourceInputs["name"] = args ? args.name : undefined;
resourceInputs["password"] = (args === null || args === void 0 ? void 0 : args.password) ? pulumi.secret(args.password) : undefined;
resourceInputs["passwordPolicy"] = args ? args.passwordPolicy : undefined;
resourceInputs["project"] = args ? args.project : undefined;
resourceInputs["type"] = args ? args.type : undefined;
resourceInputs["sqlServerUserDetails"] = undefined /*out*/;
}
opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts);
const secretOpts = { additionalSecretOutputs: ["password"] };
opts = pulumi.mergeOptions(opts, secretOpts);
super(User.__pulumiType, name, resourceInputs, opts);
}
}
exports.User = User;
/** @internal */
User.__pulumiType = 'gcp:sql/user:User';
//# sourceMappingURL=user.js.map