All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pulumi.gcp.sql.kotlin.Database.kt Maven / Gradle / Ivy

Go to download

Build cloud applications and infrastructure by combining the safety and reliability of infrastructure as code with the power of the Kotlin programming language.

There is a newer version: 8.12.0.0
Show newest version
@file:Suppress("NAME_SHADOWING", "DEPRECATION")

package com.pulumi.gcp.sql.kotlin

import com.pulumi.core.Output
import com.pulumi.kotlin.KotlinCustomResource
import com.pulumi.kotlin.PulumiTagMarker
import com.pulumi.kotlin.ResourceMapper
import com.pulumi.kotlin.options.CustomResourceOptions
import com.pulumi.kotlin.options.CustomResourceOptionsBuilder
import com.pulumi.resources.Resource
import kotlin.Boolean
import kotlin.String
import kotlin.Suppress
import kotlin.Unit

/**
 * Builder for [Database].
 */
@PulumiTagMarker
public class DatabaseResourceBuilder internal constructor() {
    public var name: String? = null

    public var args: DatabaseArgs = DatabaseArgs()

    public var opts: CustomResourceOptions = CustomResourceOptions()

    /**
     * @param name The _unique_ name of the resulting resource.
     */
    public fun name(`value`: String) {
        this.name = value
    }

    /**
     * @param block The arguments to use to populate this resource's properties.
     */
    public suspend fun args(block: suspend DatabaseArgsBuilder.() -> Unit) {
        val builder = DatabaseArgsBuilder()
        block(builder)
        this.args = builder.build()
    }

    /**
     * @param block A bag of options that control this resource's behavior.
     */
    public suspend fun opts(block: suspend CustomResourceOptionsBuilder.() -> Unit) {
        this.opts = com.pulumi.kotlin.options.CustomResourceOptions.opts(block)
    }

    internal fun build(): Database {
        val builtJavaResource = com.pulumi.gcp.sql.Database(
            this.name,
            this.args.toJava(),
            this.opts.toJava(),
        )
        return Database(builtJavaResource)
    }
}

/**
 * Represents a SQL database inside the Cloud SQL instance, hosted in
 * Google's cloud.
 * ## Example Usage
 * ### Sql Database Basic
 * 
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as gcp from "@pulumi/gcp";
 * // See versions at https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance#database_version
 * const instance = new gcp.sql.DatabaseInstance("instance", {
 *     name: "my-database-instance",
 *     region: "us-central1",
 *     databaseVersion: "MYSQL_8_0",
 *     settings: {
 *         tier: "db-f1-micro",
 *     },
 *     deletionProtection: true,
 * });
 * const database = new gcp.sql.Database("database", {
 *     name: "my-database",
 *     instance: instance.name,
 * });
 * ```
 * ```python
 * import pulumi
 * import pulumi_gcp as gcp
 * # See versions at https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance#database_version
 * instance = gcp.sql.DatabaseInstance("instance",
 *     name="my-database-instance",
 *     region="us-central1",
 *     database_version="MYSQL_8_0",
 *     settings=gcp.sql.DatabaseInstanceSettingsArgs(
 *         tier="db-f1-micro",
 *     ),
 *     deletion_protection=True)
 * database = gcp.sql.Database("database",
 *     name="my-database",
 *     instance=instance.name)
 * ```
 * ```csharp
 * using System.Collections.Generic;
 * using System.Linq;
 * using Pulumi;
 * using Gcp = Pulumi.Gcp;
 * return await Deployment.RunAsync(() =>
 * {
 *     // See versions at https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance#database_version
 *     var instance = new Gcp.Sql.DatabaseInstance("instance", new()
 *     {
 *         Name = "my-database-instance",
 *         Region = "us-central1",
 *         DatabaseVersion = "MYSQL_8_0",
 *         Settings = new Gcp.Sql.Inputs.DatabaseInstanceSettingsArgs
 *         {
 *             Tier = "db-f1-micro",
 *         },
 *         DeletionProtection = true,
 *     });
 *     var database = new Gcp.Sql.Database("database", new()
 *     {
 *         Name = "my-database",
 *         Instance = instance.Name,
 *     });
 * });
 * ```
 * ```go
 * package main
 * import (
 * 	"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/sql"
 * 	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
 * )
 * func main() {
 * 	pulumi.Run(func(ctx *pulumi.Context) error {
 * 		// See versions at https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance#database_version
 * 		instance, err := sql.NewDatabaseInstance(ctx, "instance", &sql.DatabaseInstanceArgs{
 * 			Name:            pulumi.String("my-database-instance"),
 * 			Region:          pulumi.String("us-central1"),
 * 			DatabaseVersion: pulumi.String("MYSQL_8_0"),
 * 			Settings: &sql.DatabaseInstanceSettingsArgs{
 * 				Tier: pulumi.String("db-f1-micro"),
 * 			},
 * 			DeletionProtection: pulumi.Bool(true),
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		_, err = sql.NewDatabase(ctx, "database", &sql.DatabaseArgs{
 * 			Name:     pulumi.String("my-database"),
 * 			Instance: instance.Name,
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		return nil
 * 	})
 * }
 * ```
 * ```java
 * package generated_program;
 * import com.pulumi.Context;
 * import com.pulumi.Pulumi;
 * import com.pulumi.core.Output;
 * import com.pulumi.gcp.sql.DatabaseInstance;
 * import com.pulumi.gcp.sql.DatabaseInstanceArgs;
 * import com.pulumi.gcp.sql.inputs.DatabaseInstanceSettingsArgs;
 * import com.pulumi.gcp.sql.Database;
 * import com.pulumi.gcp.sql.DatabaseArgs;
 * import java.util.List;
 * import java.util.ArrayList;
 * import java.util.Map;
 * import java.io.File;
 * import java.nio.file.Files;
 * import java.nio.file.Paths;
 * public class App {
 *     public static void main(String[] args) {
 *         Pulumi.run(App::stack);
 *     }
 *     public static void stack(Context ctx) {
 *         // See versions at https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance#database_version
 *         var instance = new DatabaseInstance("instance", DatabaseInstanceArgs.builder()
 *             .name("my-database-instance")
 *             .region("us-central1")
 *             .databaseVersion("MYSQL_8_0")
 *             .settings(DatabaseInstanceSettingsArgs.builder()
 *                 .tier("db-f1-micro")
 *                 .build())
 *             .deletionProtection("true")
 *             .build());
 *         var database = new Database("database", DatabaseArgs.builder()
 *             .name("my-database")
 *             .instance(instance.name())
 *             .build());
 *     }
 * }
 * ```
 * ```yaml
 * resources:
 *   database:
 *     type: gcp:sql:Database
 *     properties:
 *       name: my-database
 *       instance: ${instance.name}
 *   # See versions at https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance#database_version
 *   instance:
 *     type: gcp:sql:DatabaseInstance
 *     properties:
 *       name: my-database-instance
 *       region: us-central1
 *       databaseVersion: MYSQL_8_0
 *       settings:
 *         tier: db-f1-micro
 *       deletionProtection: 'true'
 * ```
 * 
 * ### Sql Database Deletion Policy
 * 
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as gcp from "@pulumi/gcp";
 * // See versions at https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance#database_version
 * const instance = new gcp.sql.DatabaseInstance("instance", {
 *     name: "my-database-instance",
 *     region: "us-central1",
 *     databaseVersion: "POSTGRES_14",
 *     settings: {
 *         tier: "db-g1-small",
 *     },
 *     deletionProtection: true,
 * });
 * const databaseDeletionPolicy = new gcp.sql.Database("database_deletion_policy", {
 *     name: "my-database",
 *     instance: instance.name,
 *     deletionPolicy: "ABANDON",
 * });
 * ```
 * ```python
 * import pulumi
 * import pulumi_gcp as gcp
 * # See versions at https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance#database_version
 * instance = gcp.sql.DatabaseInstance("instance",
 *     name="my-database-instance",
 *     region="us-central1",
 *     database_version="POSTGRES_14",
 *     settings=gcp.sql.DatabaseInstanceSettingsArgs(
 *         tier="db-g1-small",
 *     ),
 *     deletion_protection=True)
 * database_deletion_policy = gcp.sql.Database("database_deletion_policy",
 *     name="my-database",
 *     instance=instance.name,
 *     deletion_policy="ABANDON")
 * ```
 * ```csharp
 * using System.Collections.Generic;
 * using System.Linq;
 * using Pulumi;
 * using Gcp = Pulumi.Gcp;
 * return await Deployment.RunAsync(() =>
 * {
 *     // See versions at https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance#database_version
 *     var instance = new Gcp.Sql.DatabaseInstance("instance", new()
 *     {
 *         Name = "my-database-instance",
 *         Region = "us-central1",
 *         DatabaseVersion = "POSTGRES_14",
 *         Settings = new Gcp.Sql.Inputs.DatabaseInstanceSettingsArgs
 *         {
 *             Tier = "db-g1-small",
 *         },
 *         DeletionProtection = true,
 *     });
 *     var databaseDeletionPolicy = new Gcp.Sql.Database("database_deletion_policy", new()
 *     {
 *         Name = "my-database",
 *         Instance = instance.Name,
 *         DeletionPolicy = "ABANDON",
 *     });
 * });
 * ```
 * ```go
 * package main
 * import (
 * 	"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/sql"
 * 	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
 * )
 * func main() {
 * 	pulumi.Run(func(ctx *pulumi.Context) error {
 * 		// See versions at https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance#database_version
 * 		instance, err := sql.NewDatabaseInstance(ctx, "instance", &sql.DatabaseInstanceArgs{
 * 			Name:            pulumi.String("my-database-instance"),
 * 			Region:          pulumi.String("us-central1"),
 * 			DatabaseVersion: pulumi.String("POSTGRES_14"),
 * 			Settings: &sql.DatabaseInstanceSettingsArgs{
 * 				Tier: pulumi.String("db-g1-small"),
 * 			},
 * 			DeletionProtection: pulumi.Bool(true),
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		_, err = sql.NewDatabase(ctx, "database_deletion_policy", &sql.DatabaseArgs{
 * 			Name:           pulumi.String("my-database"),
 * 			Instance:       instance.Name,
 * 			DeletionPolicy: pulumi.String("ABANDON"),
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		return nil
 * 	})
 * }
 * ```
 * ```java
 * package generated_program;
 * import com.pulumi.Context;
 * import com.pulumi.Pulumi;
 * import com.pulumi.core.Output;
 * import com.pulumi.gcp.sql.DatabaseInstance;
 * import com.pulumi.gcp.sql.DatabaseInstanceArgs;
 * import com.pulumi.gcp.sql.inputs.DatabaseInstanceSettingsArgs;
 * import com.pulumi.gcp.sql.Database;
 * import com.pulumi.gcp.sql.DatabaseArgs;
 * import java.util.List;
 * import java.util.ArrayList;
 * import java.util.Map;
 * import java.io.File;
 * import java.nio.file.Files;
 * import java.nio.file.Paths;
 * public class App {
 *     public static void main(String[] args) {
 *         Pulumi.run(App::stack);
 *     }
 *     public static void stack(Context ctx) {
 *         // See versions at https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance#database_version
 *         var instance = new DatabaseInstance("instance", DatabaseInstanceArgs.builder()
 *             .name("my-database-instance")
 *             .region("us-central1")
 *             .databaseVersion("POSTGRES_14")
 *             .settings(DatabaseInstanceSettingsArgs.builder()
 *                 .tier("db-g1-small")
 *                 .build())
 *             .deletionProtection("true")
 *             .build());
 *         var databaseDeletionPolicy = new Database("databaseDeletionPolicy", DatabaseArgs.builder()
 *             .name("my-database")
 *             .instance(instance.name())
 *             .deletionPolicy("ABANDON")
 *             .build());
 *     }
 * }
 * ```
 * ```yaml
 * resources:
 *   databaseDeletionPolicy:
 *     type: gcp:sql:Database
 *     name: database_deletion_policy
 *     properties:
 *       name: my-database
 *       instance: ${instance.name}
 *       deletionPolicy: ABANDON
 *   # See versions at https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance#database_version
 *   instance:
 *     type: gcp:sql:DatabaseInstance
 *     properties:
 *       name: my-database-instance
 *       region: us-central1
 *       databaseVersion: POSTGRES_14
 *       settings:
 *         tier: db-g1-small
 *       deletionProtection: 'true'
 * ```
 * 
 * ## Import
 * Database can be imported using any of these accepted formats:
 * * `projects/{{project}}/instances/{{instance}}/databases/{{name}}`
 * * `instances/{{instance}}/databases/{{name}}`
 * * `{{project}}/{{instance}}/{{name}}`
 * * `{{instance}}/{{name}}`
 * * `{{name}}`
 * When using the `pulumi import` command, Database can be imported using one of the formats above. For example:
 * ```sh
 * $ pulumi import gcp:sql/database:Database default projects/{{project}}/instances/{{instance}}/databases/{{name}}
 * ```
 * ```sh
 * $ pulumi import gcp:sql/database:Database default instances/{{instance}}/databases/{{name}}
 * ```
 * ```sh
 * $ pulumi import gcp:sql/database:Database default {{project}}/{{instance}}/{{name}}
 * ```
 * ```sh
 * $ pulumi import gcp:sql/database:Database default {{instance}}/{{name}}
 * ```
 * ```sh
 * $ pulumi import gcp:sql/database:Database default {{name}}
 * ```
 */
public class Database internal constructor(
    override val javaResource: com.pulumi.gcp.sql.Database,
) : KotlinCustomResource(javaResource, DatabaseMapper) {
    /**
     * The charset value. See MySQL's
     * [Supported Character Sets and Collations](https://dev.mysql.com/doc/refman/5.7/en/charset-charsets.html)
     * and Postgres' [Character Set Support](https://www.postgresql.org/docs/9.6/static/multibyte.html)
     * for more details and supported values. Postgres databases only support
     * a value of `UTF8` at creation time.
     */
    public val charset: Output
        get() = javaResource.charset().applyValue({ args0 -> args0 })

    /**
     * The collation value. See MySQL's
     * [Supported Character Sets and Collations](https://dev.mysql.com/doc/refman/5.7/en/charset-charsets.html)
     * and Postgres' [Collation Support](https://www.postgresql.org/docs/9.6/static/collation.html)
     * for more details and supported values. Postgres databases only support
     * a value of `en_US.UTF8` at creation time.
     */
    public val collation: Output
        get() = javaResource.collation().applyValue({ args0 -> args0 })

    /**
     * The deletion policy for the database. Setting ABANDON allows the resource
     * to be abandoned rather than deleted. This is useful for Postgres, where databases cannot be
     * deleted from the API if there are users other than cloudsqlsuperuser with access. Possible
     * values are: "ABANDON", "DELETE". Defaults to "DELETE".
     */
    public val deletionPolicy: Output?
        get() = javaResource.deletionPolicy().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * The name of the Cloud SQL instance. This does not include the project
     * ID.
     * - - -
     */
    public val instance: Output
        get() = javaResource.instance().applyValue({ args0 -> args0 })

    /**
     * The name of the database in the Cloud SQL instance.
     * This does not include the project ID or instance name.
     */
    public val name: Output
        get() = javaResource.name().applyValue({ args0 -> args0 })

    /**
     * The ID of the project in which the resource belongs.
     * If it is not provided, the provider project is used.
     */
    public val project: Output
        get() = javaResource.project().applyValue({ args0 -> args0 })

    /**
     * The URI of the created resource.
     */
    public val selfLink: Output
        get() = javaResource.selfLink().applyValue({ args0 -> args0 })
}

public object DatabaseMapper : ResourceMapper {
    override fun supportsMappingOfType(javaResource: Resource): Boolean =
        com.pulumi.gcp.sql.Database::class == javaResource::class

    override fun map(javaResource: Resource): Database = Database(
        javaResource as
            com.pulumi.gcp.sql.Database,
    )
}

/**
 * @see [Database].
 * @param name The _unique_ name of the resulting resource.
 * @param block Builder for [Database].
 */
public suspend fun database(name: String, block: suspend DatabaseResourceBuilder.() -> Unit): Database {
    val builder = DatabaseResourceBuilder()
    builder.name(name)
    block(builder)
    return builder.build()
}

/**
 * @see [Database].
 * @param name The _unique_ name of the resulting resource.
 */
public fun database(name: String): Database {
    val builder = DatabaseResourceBuilder()
    builder.name(name)
    return builder.build()
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy