From ec4ebaec1c05429a75906564dce1d063cfe4ba13 Mon Sep 17 00:00:00 2001 From: Eraac Date: Thu, 11 Oct 2018 11:59:32 +0200 Subject: [PATCH 1/6] adding family attribute --- google/resource_bigtable_table.go | 12 +++++++ google/resource_bigtable_table_test.go | 44 ++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/google/resource_bigtable_table.go b/google/resource_bigtable_table.go index 7728e0e96c5..75d89c1ba29 100644 --- a/google/resource_bigtable_table.go +++ b/google/resource_bigtable_table.go @@ -21,6 +21,12 @@ func resourceBigtableTable() *schema.Resource { ForceNew: true, }, + "family": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "instance_name": { Type: schema.TypeString, Required: true, @@ -79,6 +85,12 @@ func resourceBigtableTableCreate(d *schema.ResourceData, meta interface{}) error } } + if v, ok := d.GetOk("family"); ok { + if err := c.CreateColumnFamily(ctx, name, v.(string)); err != nil { + return fmt.Errorf("Error creating column family. %s", 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 04ab9ab8d97..7d64f5c7b57 100644 --- a/google/resource_bigtable_table_test.go +++ b/google/resource_bigtable_table_test.go @@ -54,6 +54,29 @@ 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 testAccCheckBigtableTableDestroy(s *terraform.State) error { var ctx = context.Background() for _, rs := range s.RootModule().Resources { @@ -139,3 +162,24 @@ 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}" + family = "%s" +} +`, instanceName, instanceName, tableName, family) +} From d60dd9c13fed060dffaf5ef6c26b65a8ca2a1ade Mon Sep 17 00:00:00 2001 From: Eraac Date: Thu, 11 Oct 2018 12:00:25 +0200 Subject: [PATCH 2/6] update documentation for attribute family --- website/docs/r/bigtable_table.html.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/website/docs/r/bigtable_table.html.markdown b/website/docs/r/bigtable_table.html.markdown index 2c9d69bd867..909d400a063 100644 --- a/website/docs/r/bigtable_table.html.markdown +++ b/website/docs/r/bigtable_table.html.markdown @@ -41,6 +41,8 @@ The following arguments are supported: * `split_keys` - (Optional) A list of predefined keys to split the table on. +* `family` - (Optional) Creates a new column family in a table. + * `project` - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used. From 6af5a443e9200519eafc8ed793db4e5a25d12132 Mon Sep 17 00:00:00 2001 From: Eraac Date: Thu, 11 Oct 2018 12:02:14 +0200 Subject: [PATCH 3/6] change tab to space --- google/resource_bigtable_table_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/resource_bigtable_table_test.go b/google/resource_bigtable_table_test.go index 7d64f5c7b57..ab44613eb7d 100644 --- a/google/resource_bigtable_table_test.go +++ b/google/resource_bigtable_table_test.go @@ -169,7 +169,7 @@ resource "google_bigtable_instance" "instance" { name = "%s" cluster { - cluster_id = "%s" + cluster_id = "%s" zone = "us-central1-b" } From e22b98a8d9b95ecc63940387c5fa02921d2ce877 Mon Sep 17 00:00:00 2001 From: Eraac Date: Thu, 11 Oct 2018 19:15:44 +0200 Subject: [PATCH 4/6] using block instead of one attribute --- google/resource_bigtable_table.go | 26 ++++++++-- google/resource_bigtable_table_test.go | 56 ++++++++++++++++++++- website/docs/r/bigtable_table.html.markdown | 8 ++- 3 files changed, 83 insertions(+), 7 deletions(-) diff --git a/google/resource_bigtable_table.go b/google/resource_bigtable_table.go index 75d89c1ba29..05deb18b9cf 100644 --- a/google/resource_bigtable_table.go +++ b/google/resource_bigtable_table.go @@ -21,10 +21,18 @@ func resourceBigtableTable() *schema.Resource { ForceNew: true, }, - "family": { - Type: schema.TypeString, + "column_family": { + Type: schema.TypeSet, Optional: true, ForceNew: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "family": { + Type: schema.TypeString, + Optional: true, + }, + }, + }, }, "instance_name": { @@ -85,9 +93,17 @@ func resourceBigtableTableCreate(d *schema.ResourceData, meta interface{}) error } } - if v, ok := d.GetOk("family"); ok { - if err := c.CreateColumnFamily(ctx, name, v.(string)); err != nil { - return fmt.Errorf("Error creating column family. %s", err) + 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) + } + } } } diff --git a/google/resource_bigtable_table_test.go b/google/resource_bigtable_table_test.go index ab44613eb7d..5fce5ac0325 100644 --- a/google/resource_bigtable_table_test.go +++ b/google/resource_bigtable_table_test.go @@ -77,6 +77,29 @@ func TestAccBigtableTable_family(t *testing.T) { }) } +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 { @@ -179,7 +202,38 @@ resource "google_bigtable_instance" "instance" { resource "google_bigtable_table" "table" { name = "%s" instance_name = "${google_bigtable_instance.instance.name}" - family = "%s" + + 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 909d400a063..a12946d566a 100644 --- a/website/docs/r/bigtable_table.html.markdown +++ b/website/docs/r/bigtable_table.html.markdown @@ -41,11 +41,17 @@ The following arguments are supported: * `split_keys` - (Optional) A list of predefined keys to split the table on. -* `family` - (Optional) Creates a new column family in a table. +* `column_family` - (Optional) A block of column family configuration options. * `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. From 0081132e4309177535bdd016eb3ccf8850a70674 Mon Sep 17 00:00:00 2001 From: Eraac Date: Fri, 12 Oct 2018 10:13:41 +0200 Subject: [PATCH 5/6] family is now required --- google/resource_bigtable_table.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/resource_bigtable_table.go b/google/resource_bigtable_table.go index 05deb18b9cf..4afeefddae3 100644 --- a/google/resource_bigtable_table.go +++ b/google/resource_bigtable_table.go @@ -29,7 +29,7 @@ func resourceBigtableTable() *schema.Resource { Schema: map[string]*schema.Schema{ "family": { Type: schema.TypeString, - Optional: true, + Required: true, }, }, }, From c27488d150f6f8c6a1522aac87dba85c8dc7b6cf Mon Sep 17 00:00:00 2001 From: Eraac Date: Fri, 12 Oct 2018 10:13:58 +0200 Subject: [PATCH 6/6] improve documentation --- website/docs/r/bigtable_table.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/bigtable_table.html.markdown b/website/docs/r/bigtable_table.html.markdown index a12946d566a..e73dceaaaf9 100644 --- a/website/docs/r/bigtable_table.html.markdown +++ b/website/docs/r/bigtable_table.html.markdown @@ -41,7 +41,7 @@ The following arguments are supported: * `split_keys` - (Optional) A list of predefined keys to split the table on. -* `column_family` - (Optional) A block of column family configuration options. +* `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.