blob: b7253bb12eeafd475f82ec00f4d565bbada3a3ef [file] [log] [blame]
---
subcategory: "Cloud Bigtable"
description: |-
Creates a Google Cloud Bigtable table inside an instance.
---
# google_bigtable_table
Creates a Google Cloud Bigtable table inside an instance. For more information see
[the official documentation](https://cloud.google.com/bigtable/) and
[API](https://cloud.google.com/bigtable/docs/go/reference).
-> **Note:** It is strongly recommended to set `lifecycle { prevent_destroy = true }`
on tables in order to prevent accidental data loss. See
[Terraform docs](https://www.terraform.io/docs/configuration/resources.html#prevent_destroy)
for more information on lifecycle parameters.
## Example Usage
```hcl
resource "google_bigtable_instance" "instance" {
name = "tf-instance"
cluster {
cluster_id = "tf-instance-cluster"
zone = "us-central1-b"
num_nodes = 3
storage_type = "HDD"
}
lifecycle {
prevent_destroy = true
}
}
resource "google_bigtable_table" "table" {
name = "tf-table"
instance_name = google_bigtable_instance.instance.name
split_keys = ["a", "b", "c"]
lifecycle {
prevent_destroy = true
}
column_family {
family = "family-first"
}
column_family {
family = "family-second"
}
change_stream_retention = "24h0m0s"
}
```
## Argument Reference
The following arguments are supported:
* `name` - (Required) The name of the table. Must be 1-50 characters and must only contain hyphens, underscores, periods, letters and numbers.
* `instance_name` - (Required) The name of the Bigtable instance.
* `split_keys` - (Optional) A list of predefined keys to split the table on.
!> **Warning:** Modifying the `split_keys` of an existing table will cause Terraform
to delete/recreate the entire `google_bigtable_table` resource.
* `column_family` - (Optional) A group of columns within a table which share a common configuration. This can be specified multiple times. Structure is documented below.
* `project` - (Optional) The ID of the project in which the resource belongs. If it
is not provided, the provider project is used.
* `deletion_protection` - (Optional) A field to make the table protected against data loss i.e. when set to PROTECTED, deleting the table, the column families in the table, and the instance containing the table would be prohibited. If not provided, deletion protection will be set to UNPROTECTED.
* `change_stream_retention` - (Optional) Duration to retain change stream data for the table. Set to 0 to disable. Must be between 1 and 7 days.
-----
`column_family` supports the following arguments:
* `family` - (Optional) The name of the column family.
## Attributes Reference
In addition to the arguments listed above, the following computed attributes are
exported:
* `id` - an identifier for the resource with format `projects/{{project}}/instances/{{instance_name}}/tables/{{name}}`
## Timeouts
This resource provides the following
[Timeouts](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-timeouts) configuration options:
- `create` - Default is 45 minutes.
- `update` - Default is 20 minutes.
## Import
-> **Fields affected by import** The following fields can't be read and will show diffs if set in config when imported: `split_keys`
Bigtable Tables can be imported using any of these accepted formats:
* `projects/{{project}}/instances/{{instance_name}}/tables/{{name}}`
* `{{project}}/{{instance_name}}/{{name}}`
* `{{instance_name}}/{{name}}`
In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import Bigtable Tables using one of the formats above. For example:
```tf
import {
id = "projects/{{project}}/instances/{{instance_name}}/tables/{{name}}"
to = google_bigtable_table.default
}
```
When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), Bigtable Tables can be imported using one of the formats above. For example:
```
$ terraform import google_bigtable_table.default projects/{{project}}/instances/{{instance_name}}/tables/{{name}}
$ terraform import google_bigtable_table.default {{project}}/{{instance_name}}/{{name}}
$ terraform import google_bigtable_table.default {{instance_name}}/{{name}}
```