Skip to content

Commit

Permalink
adding attribute family for bigtable_table (#2228)
Browse files Browse the repository at this point in the history
Fix #1576
  • Loading branch information
eraac authored and rileykarson committed Oct 12, 2018
1 parent a004e8f commit ea11a8e
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 0 deletions.
28 changes: 28 additions & 0 deletions google/resource_bigtable_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
98 changes: 98 additions & 0 deletions google/resource_bigtable_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
8 changes: 8 additions & 0 deletions website/docs/r/bigtable_table.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit ea11a8e

Please sign in to comment.