@pulumi/gcp
Version:
A Pulumi package for creating and managing Google Cloud Platform resources.
320 lines • 15.4 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.DatabaseInstance = void 0;
const pulumi = require("@pulumi/pulumi");
const utilities = require("../utilities");
/**
* Creates a new Google SQL Database Instance. For more information, see the [official documentation](https://cloud.google.com/sql/docs/mysql/create-instance),
* or the [JSON API](https://cloud.google.com/sql/docs/admin-api/v1beta4/instances).
*
* > **NOTE on `gcp.sql.DatabaseInstance`:** - Second-generation instances include a
* default 'root'@'%' user with no password. This user will be deleted by the provider on
* instance creation. You should use `gcp.sql.User` to define a custom user with
* a restricted host and strong password.
*
* > **Note**: On newer versions of the provider, you must explicitly set `deletion_protection=false`
* (and run `pulumi update` to write the field to state) in order to destroy an instance.
* It is recommended to not set this field (or set it to true) until you're ready to destroy the instance and its databases.
*
* ## Example Usage
*
* ### SQL Second Generation Instance
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as gcp from "@pulumi/gcp";
*
* const main = new gcp.sql.DatabaseInstance("main", {
* name: "main-instance",
* databaseVersion: "POSTGRES_15",
* region: "us-central1",
* settings: {
* tier: "db-f1-micro",
* },
* });
* ```
*
* ### Private IP Instance
* > **NOTE:** For private IP instance setup, note that the `gcp.sql.DatabaseInstance` does not actually interpolate values from `gcp.servicenetworking.Connection`. You must explicitly add a `dependsOn`reference as shown below.
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as gcp from "@pulumi/gcp";
* import * as random from "@pulumi/random";
*
* const privateNetwork = new gcp.compute.Network("private_network", {name: "private-network"});
* const privateIpAddress = new gcp.compute.GlobalAddress("private_ip_address", {
* name: "private-ip-address",
* purpose: "VPC_PEERING",
* addressType: "INTERNAL",
* prefixLength: 16,
* network: privateNetwork.id,
* });
* const privateVpcConnection = new gcp.servicenetworking.Connection("private_vpc_connection", {
* network: privateNetwork.id,
* service: "servicenetworking.googleapis.com",
* reservedPeeringRanges: [privateIpAddress.name],
* });
* const dbNameSuffix = new random.RandomId("db_name_suffix", {byteLength: 4});
* const instance = new gcp.sql.DatabaseInstance("instance", {
* name: pulumi.interpolate`private-instance-${dbNameSuffix.hex}`,
* region: "us-central1",
* databaseVersion: "MYSQL_5_7",
* settings: {
* tier: "db-f1-micro",
* ipConfiguration: {
* ipv4Enabled: false,
* privateNetwork: privateNetwork.selfLink,
* enablePrivatePathForGoogleCloudServices: true,
* },
* },
* }, {
* dependsOn: [privateVpcConnection],
* });
* ```
*
* ### ENTERPRISE_PLUS Instance with dataCacheConfig
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as gcp from "@pulumi/gcp";
*
* const main = new gcp.sql.DatabaseInstance("main", {
* name: "enterprise-plus-main-instance",
* databaseVersion: "MYSQL_8_0_31",
* settings: {
* tier: "db-perf-optimized-N-2",
* edition: "ENTERPRISE_PLUS",
* dataCacheConfig: {
* dataCacheEnabled: true,
* },
* },
* });
* ```
*
* ### Cloud SQL Instance with PSC connectivity
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as gcp from "@pulumi/gcp";
*
* const main = new gcp.sql.DatabaseInstance("main", {
* name: "psc-enabled-main-instance",
* databaseVersion: "MYSQL_8_0",
* settings: {
* tier: "db-f1-micro",
* ipConfiguration: {
* pscConfigs: [{
* pscEnabled: true,
* allowedConsumerProjects: ["allowed-consumer-project-name"],
* }],
* ipv4Enabled: false,
* },
* backupConfiguration: {
* enabled: true,
* binaryLogEnabled: true,
* },
* availabilityType: "REGIONAL",
* },
* });
* ```
*
* ### Cloud SQL Instance with PSC auto connections
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as gcp from "@pulumi/gcp";
*
* const main = new gcp.sql.DatabaseInstance("main", {
* name: "psc-enabled-main-instance",
* databaseVersion: "MYSQL_8_0",
* settings: {
* tier: "db-f1-micro",
* ipConfiguration: {
* pscConfigs: [{
* pscEnabled: true,
* allowedConsumerProjects: ["allowed-consumer-project-name"],
* pscAutoConnections: [{
* consumerNetwork: "network-name",
* consumerServiceProjectId: "project-id",
* }],
* }],
* ipv4Enabled: false,
* },
* backupConfiguration: {
* enabled: true,
* binaryLogEnabled: true,
* },
* availabilityType: "REGIONAL",
* },
* });
* ```
*
* ## Switchover
*
* Users can perform a switchover on a replica by following the steps below.
*
* ~>**WARNING:** Failure to follow these steps can lead to data loss (You will be warned during plan stage). To prevent data loss during a switchover, please verify your plan with the checklist below.
*
* For a more in-depth walkthrough with example code, see the Switchover Guide
*
* ### Steps to Invoke Switchover
*
* MySQL/PostgreSQL: Create a cross-region, Enterprise Plus edition primary and replica pair, then set the value of primary's `replication_cluster.failover_dr_replica_name` as the replica.
*
* SQL Server: Create a `cascadable` replica in a different region from the primary (`cascadableReplica` is set to true in `replicaConfiguration`)
*
* #### Invoking switchover in the replica resource:
* 1. Change instanceType from `READ_REPLICA_INSTANCE` to `CLOUD_SQL_INSTANCE`
* 2. Remove `masterInstanceName`
* 3. (SQL Server) Remove `replicaConfiguration`
* 4. Add current primary's name to the replica's `replicaNames` list
* 5. (MySQL/PostgreSQL) Add current primary's name to the replica's `replication_cluster.failover_dr_replica_name`.
* 6. (MySQL/PostgreSQL) Adjust `backupConfiguration`. See Switchover Guide for details.
*
* #### Updating the primary resource:
* 1. Change `instanceType` from `CLOUD_SQL_INSTANCE` to `READ_REPLICA_INSTANCE`
* 2. Set `masterInstanceName` to the original replica (which will be primary after switchover)
* 3. (SQL Server) Set `replicaConfiguration` and set `cascadableReplica` to `true`
* 4. Remove original replica from `replicaNames`
* * **NOTE**: Do **not** delete the replicaNames field, even if it has no replicas remaining. Set replicaNames = [ ] to indicate it having no replicas.
* 5. (MySQL/PostgreSQL) Set `replication_cluster.failover_dr_replica_name` as the empty string.
* 6. (MySQL/PostgreSQL) Adjust `backupConfiguration`. See Switchover Guide for details.
* #### Plan and verify that:
* - `pulumi preview` outputs **"0 to add, 0 to destroy"**
* - `pulumi preview` does not say **"must be replaced"** for any resource
* - Every resource **"will be updated in-place"**
* - Only the 2 instances involved in switchover have planned changes
* - (Recommended) Use `deletionProtection` on instances as a safety measure
*
* ## Import
*
* Database instances can be imported using one of any of these accepted formats:
*
* * `projects/{{project}}/instances/{{name}}`
*
* * `{{project}}/{{name}}`
*
* * `{{name}}`
*
* When using the `pulumi import` command, Database instances can be imported using one of the formats above. For example:
*
* ```sh
* $ pulumi import gcp:sql/databaseInstance:DatabaseInstance default projects/{{project}}/instances/{{name}}
* ```
*
* ```sh
* $ pulumi import gcp:sql/databaseInstance:DatabaseInstance default {{project}}/{{name}}
* ```
*
* ```sh
* $ pulumi import gcp:sql/databaseInstance:DatabaseInstance default {{name}}
* ```
*
* config and set on the server.
*
* When importing, double-check that your config has all the fields set that you expect- just seeing
*
* no diff isn't sufficient to know that your config could reproduce the imported resource.
*/
class DatabaseInstance extends pulumi.CustomResource {
/**
* Get an existing DatabaseInstance 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 DatabaseInstance(name, state, Object.assign(Object.assign({}, opts), { id: id }));
}
/**
* Returns true if the given object is an instance of DatabaseInstance. 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'] === DatabaseInstance.__pulumiType;
}
constructor(name, argsOrState, opts) {
let resourceInputs = {};
opts = opts || {};
if (opts.id) {
const state = argsOrState;
resourceInputs["availableMaintenanceVersions"] = state ? state.availableMaintenanceVersions : undefined;
resourceInputs["clone"] = state ? state.clone : undefined;
resourceInputs["connectionName"] = state ? state.connectionName : undefined;
resourceInputs["databaseVersion"] = state ? state.databaseVersion : undefined;
resourceInputs["deletionProtection"] = state ? state.deletionProtection : undefined;
resourceInputs["dnsName"] = state ? state.dnsName : undefined;
resourceInputs["encryptionKeyName"] = state ? state.encryptionKeyName : undefined;
resourceInputs["firstIpAddress"] = state ? state.firstIpAddress : undefined;
resourceInputs["instanceType"] = state ? state.instanceType : undefined;
resourceInputs["ipAddresses"] = state ? state.ipAddresses : undefined;
resourceInputs["maintenanceVersion"] = state ? state.maintenanceVersion : undefined;
resourceInputs["masterInstanceName"] = state ? state.masterInstanceName : undefined;
resourceInputs["name"] = state ? state.name : undefined;
resourceInputs["privateIpAddress"] = state ? state.privateIpAddress : undefined;
resourceInputs["project"] = state ? state.project : undefined;
resourceInputs["pscServiceAttachmentLink"] = state ? state.pscServiceAttachmentLink : undefined;
resourceInputs["publicIpAddress"] = state ? state.publicIpAddress : undefined;
resourceInputs["region"] = state ? state.region : undefined;
resourceInputs["replicaConfiguration"] = state ? state.replicaConfiguration : undefined;
resourceInputs["replicaNames"] = state ? state.replicaNames : undefined;
resourceInputs["replicationCluster"] = state ? state.replicationCluster : undefined;
resourceInputs["restoreBackupContext"] = state ? state.restoreBackupContext : undefined;
resourceInputs["rootPassword"] = state ? state.rootPassword : undefined;
resourceInputs["selfLink"] = state ? state.selfLink : undefined;
resourceInputs["serverCaCerts"] = state ? state.serverCaCerts : undefined;
resourceInputs["serviceAccountEmailAddress"] = state ? state.serviceAccountEmailAddress : undefined;
resourceInputs["settings"] = state ? state.settings : undefined;
}
else {
const args = argsOrState;
if ((!args || args.databaseVersion === undefined) && !opts.urn) {
throw new Error("Missing required property 'databaseVersion'");
}
resourceInputs["clone"] = args ? args.clone : undefined;
resourceInputs["databaseVersion"] = args ? args.databaseVersion : undefined;
resourceInputs["deletionProtection"] = args ? args.deletionProtection : undefined;
resourceInputs["encryptionKeyName"] = args ? args.encryptionKeyName : undefined;
resourceInputs["instanceType"] = args ? args.instanceType : undefined;
resourceInputs["maintenanceVersion"] = args ? args.maintenanceVersion : undefined;
resourceInputs["masterInstanceName"] = args ? args.masterInstanceName : undefined;
resourceInputs["name"] = args ? args.name : undefined;
resourceInputs["project"] = args ? args.project : undefined;
resourceInputs["region"] = args ? args.region : undefined;
resourceInputs["replicaConfiguration"] = (args === null || args === void 0 ? void 0 : args.replicaConfiguration) ? pulumi.secret(args.replicaConfiguration) : undefined;
resourceInputs["replicaNames"] = args ? args.replicaNames : undefined;
resourceInputs["replicationCluster"] = args ? args.replicationCluster : undefined;
resourceInputs["restoreBackupContext"] = args ? args.restoreBackupContext : undefined;
resourceInputs["rootPassword"] = (args === null || args === void 0 ? void 0 : args.rootPassword) ? pulumi.secret(args.rootPassword) : undefined;
resourceInputs["settings"] = args ? args.settings : undefined;
resourceInputs["availableMaintenanceVersions"] = undefined /*out*/;
resourceInputs["connectionName"] = undefined /*out*/;
resourceInputs["dnsName"] = undefined /*out*/;
resourceInputs["firstIpAddress"] = undefined /*out*/;
resourceInputs["ipAddresses"] = undefined /*out*/;
resourceInputs["privateIpAddress"] = undefined /*out*/;
resourceInputs["pscServiceAttachmentLink"] = undefined /*out*/;
resourceInputs["publicIpAddress"] = undefined /*out*/;
resourceInputs["selfLink"] = undefined /*out*/;
resourceInputs["serverCaCerts"] = undefined /*out*/;
resourceInputs["serviceAccountEmailAddress"] = undefined /*out*/;
}
opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts);
const secretOpts = { additionalSecretOutputs: ["replicaConfiguration", "rootPassword", "serverCaCerts"] };
opts = pulumi.mergeOptions(opts, secretOpts);
super(DatabaseInstance.__pulumiType, name, resourceInputs, opts);
}
}
exports.DatabaseInstance = DatabaseInstance;
/** @internal */
DatabaseInstance.__pulumiType = 'gcp:sql/databaseInstance:DatabaseInstance';
//# sourceMappingURL=databaseInstance.js.map