Database class
A Cloud Spanner Database which is hosted on a Spanner instance.
To get more information about Database, see:
- API documentation
- How-to Guides
- Official Documentation
> Warning: On newer versions of the provider, you must explicitly set deletion_protection=false
(and run pulumi up 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.
On older versions, it is strongly recommended to set lifecycle { preventDestroy = true }
on databases in order to prevent accidental data loss.
Example Usage
Spanner Database Basic
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
const main = new gcp.spanner.Instance("main", {
name: "my-instance",
config: "regional-europe-west1",
displayName: "main-instance",
numNodes: 1,
});
const database = new gcp.spanner.Database("database", {
instance: main.name,
name: "my-database",
versionRetentionPeriod: "3d",
defaultTimeZone: "UTC",
ddls: [
"CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
"CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)",
],
deletionProtection: false,
});
import pulumi
import pulumi_gcp as gcp
main = gcp.spanner.Instance("main",
name="my-instance",
config="regional-europe-west1",
display_name="main-instance",
num_nodes=1)
database = gcp.spanner.Database("database",
instance=main.name,
name="my-database",
version_retention_period="3d",
default_time_zone="UTC",
ddls=[
"CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
"CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)",
],
deletion_protection=False)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Gcp = Pulumi.Gcp;
return await Deployment.RunAsync(() =>
{
var main = new Gcp.Spanner.Instance("main", new()
{
Name = "my-instance",
Config = "regional-europe-west1",
DisplayName = "main-instance",
NumNodes = 1,
});
var database = new Gcp.Spanner.Database("database", new()
{
Instance = main.Name,
Name = "my-database",
VersionRetentionPeriod = "3d",
DefaultTimeZone = "UTC",
Ddls = new[]
{
"CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
"CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)",
},
DeletionProtection = false,
});
});
package main
import (
"github.com/pulumi/pulumi-gcp/sdk/v9/go/gcp/spanner"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
main, err := spanner.NewInstance(ctx, "main", &spanner.InstanceArgs{
Name: pulumi.String("my-instance"),
Config: pulumi.String("regional-europe-west1"),
DisplayName: pulumi.String("main-instance"),
NumNodes: pulumi.Int(1),
})
if err != nil {
return err
}
_, err = spanner.NewDatabase(ctx, "database", &spanner.DatabaseArgs{
Instance: main.Name,
Name: pulumi.String("my-database"),
VersionRetentionPeriod: pulumi.String("3d"),
DefaultTimeZone: pulumi.String("UTC"),
Ddls: pulumi.StringArray{
pulumi.String("CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)"),
pulumi.String("CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)"),
},
DeletionProtection: pulumi.Bool(false),
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
gcp = {
source = "pulumi/gcp"
}
}
}
resource "gcp_spanner_instance" "main" {
name = "my-instance"
config = "regional-europe-west1"
display_name = "main-instance"
num_nodes = 1
}
resource "gcp_spanner_database" "database" {
instance = gcp_spanner_instance.main.name
name = "my-database"
version_retention_period = "3d"
default_time_zone = "UTC"
ddls = ["CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)", "CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)"]
deletion_protection = false
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gcp.spanner.Instance;
import com.pulumi.gcp.spanner.InstanceArgs;
import com.pulumi.gcp.spanner.Database;
import com.pulumi.gcp.spanner.DatabaseArgs;
import java.util.ArrayList;
import java.util.Arrays;
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 main = new Instance("main", InstanceArgs.builder()
.name("my-instance")
.config("regional-europe-west1")
.displayName("main-instance")
.numNodes(1)
.build());
var database = new Database("database", DatabaseArgs.builder()
.instance(main.name())
.name("my-database")
.versionRetentionPeriod("3d")
.defaultTimeZone("UTC")
.ddls(
"CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)",
"CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)")
.deletionProtection(false)
.build());
}
}
resources:
main:
type: gcp:spanner:Instance
properties:
name: my-instance
config: regional-europe-west1
displayName: main-instance
numNodes: 1
database:
type: gcp:spanner:Database
properties:
instance: ${main.name}
name: my-database
versionRetentionPeriod: 3d
defaultTimeZone: UTC
ddls:
- CREATE TABLE t1 (t1 INT64 NOT NULL,) PRIMARY KEY(t1)
- CREATE TABLE t2 (t2 INT64 NOT NULL,) PRIMARY KEY(t2)
deletionProtection: false
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}}
When using the pulumi import command, Database can be imported using one of the formats above. For example:
$ pulumi import gcp:spanner/database:Database default projects/{{project}}/instances/{{instance}}/databases/{{name}}
$ pulumi import gcp:spanner/database:Database default instances/{{instance}}/databases/{{name}}
$ pulumi import gcp:spanner/database:Database default {{project}}/{{instance}}/{{name}}
$ pulumi import gcp:spanner/database:Database default {{instance}}/{{name}}
Constructors
- Database(String name, {DatabaseArgs? args, CustomResourceOptions? options})
-
Creates a new Database.
nameThe Pulumi resource name.argsArguments used to configure this Database. The set of arguments for Database.optionsResource options controlling this resource's behavior. - Database.reference(String urn)
- Creates a typed reference to an existing Database resource.
Properties
-
childResources
→ Set<
Resource> -
finalinherited
-
completionSources
↔ Map<
String, IOutputCompletionSource> -
latefinalinherited
-
databaseDialect
↔ Output<
String> -
The dialect of the Cloud Spanner Database.
If it is not provided, "GOOGLE_STANDARD_SQL" will be used.
Possible values are:
GOOGLE_STANDARD_SQL,POSTGRESQL.latefinal -
ddls
↔ Output<
List< String> ?> -
An optional list of DDL statements to run inside the database. Statements can create
tables, indexes, etc.
During creation these statements execute atomically with the creation of the database
and if there is an error in any statement, the database is not created.
Terraform does not perform drift detection on this field and assumes that the values
recorded in state are accurate. Limited updates to this field are supported, and
newly appended DDL statements can be executed in an update. However, modifications
to prior statements will create a plan that marks the resource for recreation.
latefinal
-
defaultTimeZone
↔ Output<
String?> -
The default time zone for the database. The default time zone must be a valid name
from the tz database. Default value is "America/Los_angeles".
latefinal
-
deletionPolicy
↔ Output<
String> -
Whether Terraform will be prevented from destroying the resource. Defaults to DELETE.
When a 'terraform destroy' or 'pulumi up' would delete the resource,
the command will fail if this field is set to "PREVENT" in Terraform state.
When set to "ABANDON", the command will remove the resource from Terraform
management without updating or deleting the resource in the API.
When set to "DELETE", deleting the resource is allowed.
latefinal
-
deletionProtection
↔ Output<
bool?> -
Whether or not to allow the provider to destroy the instance. Unless this field is set to false
in state, a
destroyorupdatethat would delete the instance will fail.latefinal -
enableDropProtection
↔ Output<
bool?> -
Whether drop protection is enabled for this database. Defaults to false.
Drop protection is different from
the "deletionProtection" attribute in the following ways:
(1) "deletionProtection" only protects the database from deletions in Terraform.
whereas setting “enableDropProtection” to true protects the database from deletions in all interfaces.
(2) Setting "enableDropProtection" to true also prevents the deletion of the parent instance containing the database.
"deletionProtection" attribute does not provide protection against the deletion of the parent instance.
latefinal
-
encryptionConfig
↔ Output<
DatabaseEncryptionConfig?> -
Encryption configuration for the database
Structure is documented below.
latefinal
- hashCode → int
-
The hash code for this object.
no setterinherited
-
id
↔ Output<
String> -
getter/setter pairinherited
-
instance
↔ Output<
String> -
The instance to create the database on.
latefinal
- isCustom → bool
-
Returns whether this resource is provider-managed.
no setterinherited
- isProtected → bool
-
Returns whether this resource is protected from deletion.
no setterinherited
- isRemote → bool
-
Whether this resource is registered as remote.
no setterinherited
- isResourceReference → bool
-
Whether this instance represents a resource value returned over RPC.
finalinherited
-
name
↔ Output<
String> -
A unique identifier for the database, which cannot be changed after the
instance is created. Values are of the form
[a-z][-_a-z0-9]*[a-z0-9].latefinal -
project
↔ Output<
String> -
The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.
latefinal
-
resourceTransforms
→ List<
ResourceTransform> -
Inherited/explicit async transforms.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
state
↔ Output<
String> -
An explanation of the status of the database.
latefinal
-
transformations
→ List<
ResourceTransformation> -
Inherited/explicit legacy transformations.
no setterinherited
-
urn
↔ Output<
String> -
latefinalinherited
-
versionRetentionPeriod
↔ Output<
String> -
The retention period for the database. The retention period must be between 1 hour
and 7 days, and can be specified in days, hours, minutes, or seconds. For example,
the values 1d, 24h, 1440m, and 86400s are equivalent. Default value is 1h.
If this property is used, you must avoid adding new DDL statements to
ddlthat update the database's version_retention_period.latefinal
Methods
-
failId(
Object error) → void -
Completes this resource ID with an error when registration fails.
inherited
-
failOutputs(
Object error) → void -
Completes all output properties with
error.inherited -
failUrn(
Object error) → void -
Completes this resource URN with an error when registration fails.
inherited
-
getProvider(
String moduleMember) → ProviderResource? -
Returns provider for
moduleMember's package, if configured.inherited -
getResourceName(
) → String -
Returns this resource's logical name.
inherited
-
getResourceType(
) → String -
Returns this resource's Pulumi type token.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerOutput<
T> (String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output< T> -
Registers a dynamic output property for this resource.
inherited
-
resolveId(
String? value, {required bool isKnown}) → void -
Resolves the provider-assigned ID for this resource.
inherited
-
resolveOutputs(
Struct outputs) → void -
Resolves all output properties from a monitor response payload.
inherited
-
resolveUrn(
String value) → void -
Resolves this resource's URN once assigned by the engine.
inherited
-
serializeProperties(
Map< String, dynamic> properties) → Future<Struct> -
Serializes resource properties for RPC transmission.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited