Skip to content

Commit

Permalink
bigtable_table and bigtable_gc_policy support long form ids (GoogleCl…
Browse files Browse the repository at this point in the history
  • Loading branch information
megan07 authored and Nathan Klish committed May 18, 2020
1 parent 1a68f30 commit 586431f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
14 changes: 8 additions & 6 deletions third_party/terraform/resources/resource_bigtable_gc_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ func resourceBigtableGCPolicy() *schema.Resource {

Schema: map[string]*schema.Schema{
"instance_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: compareResourceNames,
},

"table": {
Expand Down Expand Up @@ -95,11 +96,12 @@ func resourceBigtableGCPolicyCreate(d *schema.ResourceData, meta interface{}) er
return err
}

instanceName := d.Get("instance_name").(string)
instanceName := GetResourceNameFromSelfLink(d.Get("instance_name").(string))
c, err := config.bigtableClientFactory.NewAdminClient(project, instanceName)
if err != nil {
return fmt.Errorf("Error starting admin client. %s", err)
}
d.Set("instance_name", instanceName)

defer c.Close()

Expand Down Expand Up @@ -138,7 +140,7 @@ func resourceBigtableGCPolicyRead(d *schema.ResourceData, meta interface{}) erro
return err
}

instanceName := d.Get("instance_name").(string)
instanceName := GetResourceNameFromSelfLink(d.Get("instance_name").(string))
c, err := config.bigtableClientFactory.NewAdminClient(project, instanceName)
if err != nil {
return fmt.Errorf("Error starting admin client. %s", err)
Expand Down Expand Up @@ -175,7 +177,7 @@ func resourceBigtableGCPolicyDestroy(d *schema.ResourceData, meta interface{}) e
return err
}

instanceName := d.Get("instance_name").(string)
instanceName := GetResourceNameFromSelfLink(d.Get("instance_name").(string))
c, err := config.bigtableClientFactory.NewAdminClient(project, instanceName)
if err != nil {
return fmt.Errorf("Error starting admin client. %s", err)
Expand Down
14 changes: 8 additions & 6 deletions third_party/terraform/resources/resource_bigtable_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ func resourceBigtableTable() *schema.Resource {
},

"instance_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: compareResourceNames,
},

"split_keys": {
Expand Down Expand Up @@ -71,11 +72,12 @@ func resourceBigtableTableCreate(d *schema.ResourceData, meta interface{}) error
return err
}

instanceName := d.Get("instance_name").(string)
instanceName := GetResourceNameFromSelfLink(d.Get("instance_name").(string))
c, err := config.bigtableClientFactory.NewAdminClient(project, instanceName)
if err != nil {
return fmt.Errorf("Error starting admin client. %s", err)
}
d.Set("instance_name", instanceName)

defer c.Close()

Expand Down Expand Up @@ -129,7 +131,7 @@ func resourceBigtableTableRead(d *schema.ResourceData, meta interface{}) error {
return err
}

instanceName := d.Get("instance_name").(string)
instanceName := GetResourceNameFromSelfLink(d.Get("instance_name").(string))
c, err := config.bigtableClientFactory.NewAdminClient(project, instanceName)
if err != nil {
return fmt.Errorf("Error starting admin client. %s", err)
Expand Down Expand Up @@ -160,7 +162,7 @@ func resourceBigtableTableDestroy(d *schema.ResourceData, meta interface{}) erro
return err
}

instanceName := d.Get("instance_name").(string)
instanceName := GetResourceNameFromSelfLink(d.Get("instance_name").(string))
c, err := config.bigtableClientFactory.NewAdminClient(project, instanceName)
if err != nil {
return fmt.Errorf("Error starting admin client. %s", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ resource "google_bigtable_instance" "instance" {
resource "google_bigtable_table" "table" {
name = "%s"
instance_name = google_bigtable_instance.instance.name
instance_name = google_bigtable_instance.instance.id
column_family {
family = "%s"
}
}
resource "google_bigtable_gc_policy" "policy" {
instance_name = google_bigtable_instance.instance.name
instance_name = google_bigtable_instance.instance.id
table = google_bigtable_table.table.name
column_family = "%s"
Expand Down
4 changes: 2 additions & 2 deletions third_party/terraform/tests/resource_bigtable_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ resource "google_bigtable_instance" "instance" {
resource "google_bigtable_table" "table" {
name = "%s"
instance_name = google_bigtable_instance.instance.name
instance_name = google_bigtable_instance.instance.id
}
`, instanceName, instanceName, tableName)
}
Expand All @@ -161,7 +161,7 @@ resource "google_bigtable_instance" "instance" {
resource "google_bigtable_table" "table" {
name = "%s"
instance_name = google_bigtable_instance.instance.name
instance_name = google_bigtable_instance.instance.id
split_keys = ["a", "b", "c"]
}
`, instanceName, instanceName, tableName)
Expand Down

0 comments on commit 586431f

Please sign in to comment.