Skip to content

googleBigtableGcPolicy

Creates a Google Cloud Bigtable GC Policy inside a family. For more information see the official documentation and API.

-> Warning: We don't recommend having multiple GC policies for the same column family as it may result in unexpected behavior.

-> Note: GC policies associated with a replicated table cannot be destroyed directly. Destroying a GC policy is translated into never perform garbage collection, this is considered relaxing from pure age-based or version-based GC policy, hence not allowed. The workaround is unreplicating the instance first by updating the instance to have one cluster.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleBigtableInstanceInstance =
  new google.bigtableInstance.BigtableInstance(this, "instance", {
    cluster: [
      {
        cluster_id: "tf-instance-cluster",
        num_nodes: 3,
        storage_type: "HDD",
      },
    ],
    name: "tf-instance",
  });
const googleBigtableTableTable = new google.bigtableTable.BigtableTable(
  this,
  "table",
  {
    column_family: [
      {
        family: "name",
      },
    ],
    instance_name: googleBigtableInstanceInstance.name,
    name: "tf-table",
  }
);
new google.bigtableGcPolicy.BigtableGcPolicy(this, "policy", {
  column_family: "name",
  deletion_policy: "ABANDON",
  gc_rules:
    '  {\n    "rules": [\n      {\n        "max_age": "168h"\n      }\n    ]\n  }\n',
  instance_name: googleBigtableInstanceInstance.name,
  table: googleBigtableTableTable.name,
});

Multiple conditions is also supported. union when any of its sub-policies apply (OR). intersection when all its sub-policies apply (AND)

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.bigtableGcPolicy.BigtableGcPolicy(this, "policy", {
  column_family: "name",
  deletion_policy: "ABANDON",
  gc_rules:
    '  {\n    "mode": "union",\n    "rules": [\n      {\n        "max_age": "168h"\n      },\n      {\n        "max_version": 10\n      }\n    ]\n  }\n',
  instance_name: "${google_bigtable_instance.instance.name}",
  table: "${google_bigtable_table.table.name}",
});

An example of more complex GC policy:

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleBigtableInstanceInstance =
  new google.bigtableInstance.BigtableInstance(this, "instance", {
    cluster: [
      {
        cluster_id: "cid",
        zone: "us-central1-b",
      },
    ],
    deletion_protection: false,
    instance_type: "DEVELOPMENT",
    name: "instance_name",
  });
const googleBigtableTableTable = new google.bigtableTable.BigtableTable(
  this,
  "table",
  {
    column_family: [
      {
        family: "cf1",
      },
    ],
    instance_name: googleBigtableInstanceInstance.id,
    name: "your-table",
  }
);
new google.bigtableGcPolicy.BigtableGcPolicy(this, "policy", {
  column_family: "cf1",
  deletion_policy: "ABANDON",
  gc_rules:
    '  {\n    "mode": "union",\n    "rules": [\n      {\n        "max_age": "10h"\n      },\n      {\n        "mode": "intersection",\n        "rules": [\n          {\n            "max_age": "2h"\n          },\n          {\n            "max_version": 2\n          }\n        ]\n      }\n    ]\n  }\n',
  instance_name: googleBigtableInstanceInstance.id,
  table: googleBigtableTableTable.name,
});

This is equivalent to running the following cbt command:

cbt setgcpolicy your-table cf1 "(maxage=2d and maxversions=2) or maxage=10h"

Argument Reference

The following arguments are supported:

  • table - (Required) The name of the table.

  • instanceName - (Required) The name of the Bigtable instance.

  • columnFamily - (Required) The name of the column family.

  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

  • mode - (Optional) If multiple policies are set, you should choose between union OR intersection.

  • maxAge - (Optional) GC policy that applies to all cells older than the given age.

  • maxVersion - (Optional) GC policy that applies to all versions of a cell except for the most recent.

  • gcRules - (Optional) Serialized JSON object to represent a more complex GC policy. Conflicts with mode, maxAge and maxVersion. Conflicts with mode, maxAge and maxVersion.

  • deletionPolicy - (Optional) The deletion policy for the GC policy. Setting ABANDON allows the resource to be abandoned rather than deleted. This is useful for GC policy as it cannot be deleted in a replicated instance.

    Possible values are: abandon.


maxAge supports the following arguments:

  • days - (Optional, Deprecated in favor of duration) Number of days before applying GC policy.

  • duration - (Optional) Duration before applying GC policy (ex. "8h"). This is required when days isn't set


maxVersion supports the following arguments:

  • number - (Required) Number of version before applying the GC policy.

gcRules include 2 fields:

  • mode: optional, either intersection or union.
  • rules: an array of GC policy rule, can be specified as JSON object: {"maxAge": "16H"} or {"maxVersion":2}
  • If mode is not specified, rules can only contains one GC policy. If mode is specified, rules must have at least 2 policies.

Attributes Reference

Only the arguments listed above are exposed as attributes.

Import

This resource does not support import.