"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! ***
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 Managed Connection Pooling
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as gcp from "@pulumi/gcp";
 *
 * const instance = new gcp.sql.DatabaseInstance("instance", {
 *     name: "mcp-enabled-main-instance",
 *     region: "us-central1",
 *     databaseVersion: "POSTGRES_16",
 *     settings: {
 *         tier: "db-perf-optimized-N-2",
 *         edition: "ENTERPRISE_PLUS",
 *         connectionPoolConfigs: [{
 *             connectionPoolingEnabled: true,
 *             flags: [{
 *                 name: "max_client_connections",
 *                 value: "1980",
 *             }],
 *         }],
 *     },
 * });
 * ```
 *
 * ### 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",
 *     },
 * });
 * ```
 *
 * ### Cloud SQL Instance with PSC outbound
 *
 * ```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"],
 *                 networkAttachmentUri: "network-attachment-uri",
 *             }],
 *             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, { ...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?.availableMaintenanceVersions;
            resourceInputs["backupdrBackup"] = state?.backupdrBackup;
            resourceInputs["clone"] = state?.clone;
            resourceInputs["connectionName"] = state?.connectionName;
            resourceInputs["databaseVersion"] = state?.databaseVersion;
            resourceInputs["deletionProtection"] = state?.deletionProtection;
            resourceInputs["dnsName"] = state?.dnsName;
            resourceInputs["dnsNames"] = state?.dnsNames;
            resourceInputs["encryptionKeyName"] = state?.encryptionKeyName;
            resourceInputs["finalBackupDescription"] = state?.finalBackupDescription;
            resourceInputs["firstIpAddress"] = state?.firstIpAddress;
            resourceInputs["instanceType"] = state?.instanceType;
            resourceInputs["ipAddresses"] = state?.ipAddresses;
            resourceInputs["maintenanceVersion"] = state?.maintenanceVersion;
            resourceInputs["masterInstanceName"] = state?.masterInstanceName;
            resourceInputs["name"] = state?.name;
            resourceInputs["nodeCount"] = state?.nodeCount;
            resourceInputs["pointInTimeRestoreContext"] = state?.pointInTimeRestoreContext;
            resourceInputs["privateIpAddress"] = state?.privateIpAddress;
            resourceInputs["project"] = state?.project;
            resourceInputs["pscServiceAttachmentLink"] = state?.pscServiceAttachmentLink;
            resourceInputs["publicIpAddress"] = state?.publicIpAddress;
            resourceInputs["region"] = state?.region;
            resourceInputs["replicaConfiguration"] = state?.replicaConfiguration;
            resourceInputs["replicaNames"] = state?.replicaNames;
            resourceInputs["replicationCluster"] = state?.replicationCluster;
            resourceInputs["restoreBackupContext"] = state?.restoreBackupContext;
            resourceInputs["rootPassword"] = state?.rootPassword;
            resourceInputs["selfLink"] = state?.selfLink;
            resourceInputs["serverCaCerts"] = state?.serverCaCerts;
            resourceInputs["serviceAccountEmailAddress"] = state?.serviceAccountEmailAddress;
            resourceInputs["settings"] = state?.settings;
        }
        else {
            const args = argsOrState;
            if (args?.databaseVersion === undefined && !opts.urn) {
                throw new Error("Missing required property 'databaseVersion'");
            }
            resourceInputs["backupdrBackup"] = args?.backupdrBackup;
            resourceInputs["clone"] = args?.clone;
            resourceInputs["databaseVersion"] = args?.databaseVersion;
            resourceInputs["deletionProtection"] = args?.deletionProtection;
            resourceInputs["encryptionKeyName"] = args?.encryptionKeyName;
            resourceInputs["finalBackupDescription"] = args?.finalBackupDescription;
            resourceInputs["instanceType"] = args?.instanceType;
            resourceInputs["maintenanceVersion"] = args?.maintenanceVersion;
            resourceInputs["masterInstanceName"] = args?.masterInstanceName;
            resourceInputs["name"] = args?.name;
            resourceInputs["nodeCount"] = args?.nodeCount;
            resourceInputs["pointInTimeRestoreContext"] = args?.pointInTimeRestoreContext;
            resourceInputs["project"] = args?.project;
            resourceInputs["region"] = args?.region;
            resourceInputs["replicaConfiguration"] = args?.replicaConfiguration ? pulumi.secret(args.replicaConfiguration) : undefined;
            resourceInputs["replicaNames"] = args?.replicaNames;
            resourceInputs["replicationCluster"] = args?.replicationCluster;
            resourceInputs["restoreBackupContext"] = args?.restoreBackupContext;
            resourceInputs["rootPassword"] = args?.rootPassword ? pulumi.secret(args.rootPassword) : undefined;
            resourceInputs["settings"] = args?.settings;
            resourceInputs["availableMaintenanceVersions"] = undefined /*out*/;
            resourceInputs["connectionName"] = undefined /*out*/;
            resourceInputs["dnsName"] = undefined /*out*/;
            resourceInputs["dnsNames"] = 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