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

bigtable_table and bigtable_gc_policy support long form ids #5837

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
3 changes: 3 additions & 0 deletions .changelog/3222.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
bigtable: Added support for full-name/id `instance_name` value in `google_bigtable_table` and `google_bigtable_gc_policy`
```
14 changes: 8 additions & 6 deletions google/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
4 changes: 2 additions & 2 deletions google/resource_bigtable_gc_policy_test.go
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
14 changes: 8 additions & 6 deletions google/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
4 changes: 2 additions & 2 deletions google/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