mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-05 17:52:38 +00:00
parent
0008f6d840
commit
293a63e74a
|
@ -21,6 +21,20 @@ func resourceBigtableTable() *schema.Resource {
|
||||||
ForceNew: true,
|
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": {
|
"instance_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
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)
|
d.SetId(name)
|
||||||
|
|
||||||
return resourceBigtableTableRead(d, meta)
|
return resourceBigtableTableRead(d, meta)
|
||||||
|
|
|
@ -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 {
|
func testAccCheckBigtableTableDestroy(s *terraform.State) error {
|
||||||
var ctx = context.Background()
|
var ctx = context.Background()
|
||||||
for _, rs := range s.RootModule().Resources {
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
@ -139,3 +185,55 @@ resource "google_bigtable_table" "table" {
|
||||||
}
|
}
|
||||||
`, instanceName, instanceName, tableName)
|
`, 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)
|
||||||
|
}
|
||||||
|
|
|
@ -41,9 +41,17 @@ The following arguments are supported:
|
||||||
|
|
||||||
* `split_keys` - (Optional) A list of predefined keys to split the table on.
|
* `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
|
* `project` - (Optional) The ID of the project in which the resource belongs. If it
|
||||||
is not provided, the provider project is used.
|
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
|
## Attributes Reference
|
||||||
|
|
||||||
Only the arguments listed above are exposed as attributes.
|
Only the arguments listed above are exposed as attributes.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user