diff --git a/google/resource_bigtable_table.go b/google/resource_bigtable_table.go index 7728e0e9..4afeefdd 100644 --- a/google/resource_bigtable_table.go +++ b/google/resource_bigtable_table.go @@ -21,6 +21,20 @@ func resourceBigtableTable() *schema.Resource { ForceNew: true, }, + "column_family": { + Type: schema.TypeSet, + Optional: true, + ForceNew: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "family": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + }, + "instance_name": { Type: schema.TypeString, Required: true, @@ -79,6 +93,20 @@ func resourceBigtableTableCreate(d *schema.ResourceData, meta interface{}) error } } + if d.Get("column_family.#").(int) > 0 { + columns := d.Get("column_family").(*schema.Set).List() + + for _, co := range columns { + column := co.(map[string]interface{}) + + if v, ok := column["family"]; ok { + if err := c.CreateColumnFamily(ctx, name, v.(string)); err != nil { + return fmt.Errorf("Error creating column family %s. %s", v, err) + } + } + } + } + d.SetId(name) return resourceBigtableTableRead(d, meta) diff --git a/google/resource_bigtable_table_test.go b/google/resource_bigtable_table_test.go index 04ab9ab8..5fce5ac0 100644 --- a/google/resource_bigtable_table_test.go +++ b/google/resource_bigtable_table_test.go @@ -54,6 +54,52 @@ func TestAccBigtableTable_splitKeys(t *testing.T) { }) } +func TestAccBigtableTable_family(t *testing.T) { + t.Parallel() + + instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) + tableName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) + family := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckBigtableTableDestroy, + Steps: []resource.TestStep{ + { + Config: testAccBigtableTable_family(instanceName, tableName, family), + Check: resource.ComposeTestCheckFunc( + testAccBigtableTableExists( + "google_bigtable_table.table"), + ), + }, + }, + }) +} + +func TestAccBigtableTable_familyMany(t *testing.T) { + t.Parallel() + + instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) + tableName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) + family := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckBigtableTableDestroy, + Steps: []resource.TestStep{ + { + Config: testAccBigtableTable_familyMany(instanceName, tableName, family), + Check: resource.ComposeTestCheckFunc( + testAccBigtableTableExists( + "google_bigtable_table.table"), + ), + }, + }, + }) +} + func testAccCheckBigtableTableDestroy(s *terraform.State) error { var ctx = context.Background() for _, rs := range s.RootModule().Resources { @@ -139,3 +185,55 @@ resource "google_bigtable_table" "table" { } `, instanceName, instanceName, tableName) } + +func testAccBigtableTable_family(instanceName, tableName, family string) string { + return fmt.Sprintf(` +resource "google_bigtable_instance" "instance" { + name = "%s" + + cluster { + cluster_id = "%s" + zone = "us-central1-b" + } + + instance_type = "DEVELOPMENT" +} + +resource "google_bigtable_table" "table" { + name = "%s" + instance_name = "${google_bigtable_instance.instance.name}" + + column_family { + family = "%s" + } +} +`, instanceName, instanceName, tableName, family) +} + +func testAccBigtableTable_familyMany(instanceName, tableName, family string) string { + return fmt.Sprintf(` +resource "google_bigtable_instance" "instance" { + name = "%s" + + cluster { + cluster_id = "%s" + zone = "us-central1-b" + } + + instance_type = "DEVELOPMENT" +} + +resource "google_bigtable_table" "table" { + name = "%s" + instance_name = "${google_bigtable_instance.instance.name}" + + column_family { + family = "%s-first" + } + + column_family { + family = "%s-second" + } +} +`, instanceName, instanceName, tableName, family, family) +} diff --git a/website/docs/r/bigtable_table.html.markdown b/website/docs/r/bigtable_table.html.markdown index 2c9d69bd..e73dceaa 100644 --- a/website/docs/r/bigtable_table.html.markdown +++ b/website/docs/r/bigtable_table.html.markdown @@ -41,9 +41,17 @@ The following arguments are supported: * `split_keys` - (Optional) A list of predefined keys to split the table on. +* `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. +----- + +`column_family` supports the following arguments: + +* `family` - (Optional) Creates a new column family in a table. + ## Attributes Reference Only the arguments listed above are exposed as attributes.