Google Cloud (GCP) Classic

v6.44.0 published on Tuesday, Nov 29, 2022 by Pulumi

Database

Represents a SQL database inside the Cloud SQL instance, hosted in Google’s cloud.

Example Usage

Sql Database Basic

using System.Collections.Generic;
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()
    {
        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()
    {
        Instance = instance.Name,
    });

});
package main

import (
	"github.com/pulumi/pulumi-gcp/sdk/v6/go/gcp/sql"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		instance, err := sql.NewDatabaseInstance(ctx, "instance", &sql.DatabaseInstanceArgs{
			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{
			Instance: instance.Name,
		})
		if err != nil {
			return err
		}
		return nil
	})
}
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) {
        var instance = new DatabaseInstance("instance", DatabaseInstanceArgs.builder()        
            .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()        
            .instance(instance.name())
            .build());

    }
}
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",
    region="us-central1",
    database_version="MYSQL_8_0",
    settings=gcp.sql.DatabaseInstanceSettingsArgs(
        tier="db-f1-micro",
    ),
    deletion_protection=True)
database = gcp.sql.Database("database", instance=instance.name)
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", {
    region: "us-central1",
    databaseVersion: "MYSQL_8_0",
    settings: {
        tier: "db-f1-micro",
    },
    deletionProtection: true,
});
const database = new gcp.sql.Database("database", {instance: instance.name});
resources:
  database:
    type: gcp:sql:Database
    properties:
      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:
      region: us-central1
      databaseVersion: MYSQL_8_0
      settings:
        tier: db-f1-micro
      deletionProtection: 'true'

Create Database Resource

new Database(name: string, args: DatabaseArgs, opts?: CustomResourceOptions);
@overload
def Database(resource_name: str,
             opts: Optional[ResourceOptions] = None,
             charset: Optional[str] = None,
             collation: Optional[str] = None,
             instance: Optional[str] = None,
             name: Optional[str] = None,
             project: Optional[str] = None)
@overload
def Database(resource_name: str,
             args: DatabaseArgs,
             opts: Optional[ResourceOptions] = None)
func NewDatabase(ctx *Context, name string, args DatabaseArgs, opts ...ResourceOption) (*Database, error)
public Database(string name, DatabaseArgs args, CustomResourceOptions? opts = null)
public Database(String name, DatabaseArgs args)
public Database(String name, DatabaseArgs args, CustomResourceOptions options)
type: gcp:sql:Database
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

name string
The unique name of the resource.
args DatabaseArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
args DatabaseArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args DatabaseArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args DatabaseArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name String
The unique name of the resource.
args DatabaseArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Database Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

The Database resource accepts the following input properties:

Instance string

The name of the Cloud SQL instance. This does not include the project ID.

Charset string

The charset value. See MySQL's Supported Character Sets and Collations and Postgres' Character Set Support for more details and supported values. Postgres databases only support a value of UTF8 at creation time.

Collation string

The collation value. See MySQL's Supported Character Sets and Collations and Postgres' Collation Support for more details and supported values. Postgres databases only support a value of en_US.UTF8 at creation time.

Name string

The name of the database in the Cloud SQL instance. This does not include the project ID or instance name.

Project string

The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

Instance string

The name of the Cloud SQL instance. This does not include the project ID.

Charset string

The charset value. See MySQL's Supported Character Sets and Collations and Postgres' Character Set Support for more details and supported values. Postgres databases only support a value of UTF8 at creation time.

Collation string

The collation value. See MySQL's Supported Character Sets and Collations and Postgres' Collation Support for more details and supported values. Postgres databases only support a value of en_US.UTF8 at creation time.

Name string

The name of the database in the Cloud SQL instance. This does not include the project ID or instance name.

Project string

The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

instance String

The name of the Cloud SQL instance. This does not include the project ID.

charset String

The charset value. See MySQL's Supported Character Sets and Collations and Postgres' Character Set Support for more details and supported values. Postgres databases only support a value of UTF8 at creation time.

collation String

The collation value. See MySQL's Supported Character Sets and Collations and Postgres' Collation Support for more details and supported values. Postgres databases only support a value of en_US.UTF8 at creation time.

name String

The name of the database in the Cloud SQL instance. This does not include the project ID or instance name.

project String

The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

instance string

The name of the Cloud SQL instance. This does not include the project ID.

charset string

The charset value. See MySQL's Supported Character Sets and Collations and Postgres' Character Set Support for more details and supported values. Postgres databases only support a value of UTF8 at creation time.

collation string

The collation value. See MySQL's Supported Character Sets and Collations and Postgres' Collation Support for more details and supported values. Postgres databases only support a value of en_US.UTF8 at creation time.

name string

The name of the database in the Cloud SQL instance. This does not include the project ID or instance name.

project string

The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

instance str

The name of the Cloud SQL instance. This does not include the project ID.

charset str

The charset value. See MySQL's Supported Character Sets and Collations and Postgres' Character Set Support for more details and supported values. Postgres databases only support a value of UTF8 at creation time.

collation str

The collation value. See MySQL's Supported Character Sets and Collations and Postgres' Collation Support for more details and supported values. Postgres databases only support a value of en_US.UTF8 at creation time.

name str

The name of the database in the Cloud SQL instance. This does not include the project ID or instance name.

project str

The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

instance String

The name of the Cloud SQL instance. This does not include the project ID.

charset String

The charset value. See MySQL's Supported Character Sets and Collations and Postgres' Character Set Support for more details and supported values. Postgres databases only support a value of UTF8 at creation time.

collation String

The collation value. See MySQL's Supported Character Sets and Collations and Postgres' Collation Support for more details and supported values. Postgres databases only support a value of en_US.UTF8 at creation time.

name String

The name of the database in the Cloud SQL instance. This does not include the project ID or instance name.

project String

The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

Outputs

All input properties are implicitly available as output properties. Additionally, the Database resource produces the following output properties:

Id string

The provider-assigned unique ID for this managed resource.

SelfLink string

The URI of the created resource.

Id string

The provider-assigned unique ID for this managed resource.

SelfLink string

The URI of the created resource.

id String

The provider-assigned unique ID for this managed resource.

selfLink String

The URI of the created resource.

id string

The provider-assigned unique ID for this managed resource.

selfLink string

The URI of the created resource.

id str

The provider-assigned unique ID for this managed resource.

self_link str

The URI of the created resource.

id String

The provider-assigned unique ID for this managed resource.

selfLink String

The URI of the created resource.

Look up Existing Database Resource

Get an existing Database resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: DatabaseState, opts?: CustomResourceOptions): Database
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        charset: Optional[str] = None,
        collation: Optional[str] = None,
        instance: Optional[str] = None,
        name: Optional[str] = None,
        project: Optional[str] = None,
        self_link: Optional[str] = None) -> Database
func GetDatabase(ctx *Context, name string, id IDInput, state *DatabaseState, opts ...ResourceOption) (*Database, error)
public static Database Get(string name, Input<string> id, DatabaseState? state, CustomResourceOptions? opts = null)
public static Database get(String name, Output<String> id, DatabaseState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
Charset string

The charset value. See MySQL's Supported Character Sets and Collations and Postgres' Character Set Support for more details and supported values. Postgres databases only support a value of UTF8 at creation time.

Collation string

The collation value. See MySQL's Supported Character Sets and Collations and Postgres' Collation Support for more details and supported values. Postgres databases only support a value of en_US.UTF8 at creation time.

Instance string

The name of the Cloud SQL instance. This does not include the project ID.

Name string

The name of the database in the Cloud SQL instance. This does not include the project ID or instance name.

Project string

The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

SelfLink string

The URI of the created resource.

Charset string

The charset value. See MySQL's Supported Character Sets and Collations and Postgres' Character Set Support for more details and supported values. Postgres databases only support a value of UTF8 at creation time.

Collation string

The collation value. See MySQL's Supported Character Sets and Collations and Postgres' Collation Support for more details and supported values. Postgres databases only support a value of en_US.UTF8 at creation time.

Instance string

The name of the Cloud SQL instance. This does not include the project ID.

Name string

The name of the database in the Cloud SQL instance. This does not include the project ID or instance name.

Project string

The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

SelfLink string

The URI of the created resource.

charset String

The charset value. See MySQL's Supported Character Sets and Collations and Postgres' Character Set Support for more details and supported values. Postgres databases only support a value of UTF8 at creation time.

collation String

The collation value. See MySQL's Supported Character Sets and Collations and Postgres' Collation Support for more details and supported values. Postgres databases only support a value of en_US.UTF8 at creation time.

instance String

The name of the Cloud SQL instance. This does not include the project ID.

name String

The name of the database in the Cloud SQL instance. This does not include the project ID or instance name.

project String

The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

selfLink String

The URI of the created resource.

charset string

The charset value. See MySQL's Supported Character Sets and Collations and Postgres' Character Set Support for more details and supported values. Postgres databases only support a value of UTF8 at creation time.

collation string

The collation value. See MySQL's Supported Character Sets and Collations and Postgres' Collation Support for more details and supported values. Postgres databases only support a value of en_US.UTF8 at creation time.

instance string

The name of the Cloud SQL instance. This does not include the project ID.

name string

The name of the database in the Cloud SQL instance. This does not include the project ID or instance name.

project string

The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

selfLink string

The URI of the created resource.

charset str

The charset value. See MySQL's Supported Character Sets and Collations and Postgres' Character Set Support for more details and supported values. Postgres databases only support a value of UTF8 at creation time.

collation str

The collation value. See MySQL's Supported Character Sets and Collations and Postgres' Collation Support for more details and supported values. Postgres databases only support a value of en_US.UTF8 at creation time.

instance str

The name of the Cloud SQL instance. This does not include the project ID.

name str

The name of the database in the Cloud SQL instance. This does not include the project ID or instance name.

project str

The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

self_link str

The URI of the created resource.

charset String

The charset value. See MySQL's Supported Character Sets and Collations and Postgres' Character Set Support for more details and supported values. Postgres databases only support a value of UTF8 at creation time.

collation String

The collation value. See MySQL's Supported Character Sets and Collations and Postgres' Collation Support for more details and supported values. Postgres databases only support a value of en_US.UTF8 at creation time.

instance String

The name of the Cloud SQL instance. This does not include the project ID.

name String

The name of the database in the Cloud SQL instance. This does not include the project ID or instance name.

project String

The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

selfLink String

The URI of the created resource.

Import

Database can be imported using any of these accepted formats

 $ pulumi import gcp:sql/database:Database default projects/{{project}}/instances/{{instance}}/databases/{{name}}
 $ pulumi import gcp:sql/database:Database default instances/{{instance}}/databases/{{name}}
 $ pulumi import gcp:sql/database:Database default {{project}}/{{instance}}/{{name}}
 $ pulumi import gcp:sql/database:Database default {{instance}}/{{name}}
 $ pulumi import gcp:sql/database:Database default {{name}}

Package Details

Repository
https://github.com/pulumi/pulumi-gcp
License
Apache-2.0
Notes

This Pulumi package is based on the google-beta Terraform Provider.