Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding attribute family for bigtable_table #2228

Merged
merged 6 commits into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
eraac marked this conversation as resolved.
Show resolved Hide resolved
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.