adding attribute family for bigtable_table (#2228)

Fix #1576
This commit is contained in:
Labesse Kévin 2018-10-12 16:49:48 +02:00 committed by Nathan McKinley
parent 0008f6d840
commit 293a63e74a
3 changed files with 134 additions and 0 deletions

View File

@ -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)

View File

@ -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)
}

View File

@ -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.