Skip to content

Commit 105df44

Browse files
bigtable_table and bigtable_gc_policy support long form ids (#3222) (#5837)
Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent c64eb90 commit 105df44

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

.changelog/3222.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
bigtable: Added support for full-name/id `instance_name` value in `google_bigtable_table` and `google_bigtable_gc_policy`
3+
```

google/resource_bigtable_gc_policy.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ func resourceBigtableGCPolicy() *schema.Resource {
2424

2525
Schema: map[string]*schema.Schema{
2626
"instance_name": {
27-
Type: schema.TypeString,
28-
Required: true,
29-
ForceNew: true,
27+
Type: schema.TypeString,
28+
Required: true,
29+
ForceNew: true,
30+
DiffSuppressFunc: compareResourceNames,
3031
},
3132

3233
"table": {
@@ -95,11 +96,12 @@ func resourceBigtableGCPolicyCreate(d *schema.ResourceData, meta interface{}) er
9596
return err
9697
}
9798

98-
instanceName := d.Get("instance_name").(string)
99+
instanceName := GetResourceNameFromSelfLink(d.Get("instance_name").(string))
99100
c, err := config.bigtableClientFactory.NewAdminClient(project, instanceName)
100101
if err != nil {
101102
return fmt.Errorf("Error starting admin client. %s", err)
102103
}
104+
d.Set("instance_name", instanceName)
103105

104106
defer c.Close()
105107

@@ -138,7 +140,7 @@ func resourceBigtableGCPolicyRead(d *schema.ResourceData, meta interface{}) erro
138140
return err
139141
}
140142

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

178-
instanceName := d.Get("instance_name").(string)
180+
instanceName := GetResourceNameFromSelfLink(d.Get("instance_name").(string))
179181
c, err := config.bigtableClientFactory.NewAdminClient(project, instanceName)
180182
if err != nil {
181183
return fmt.Errorf("Error starting admin client. %s", err)

google/resource_bigtable_gc_policy_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,15 @@ resource "google_bigtable_instance" "instance" {
139139
140140
resource "google_bigtable_table" "table" {
141141
name = "%s"
142-
instance_name = google_bigtable_instance.instance.name
142+
instance_name = google_bigtable_instance.instance.id
143143
144144
column_family {
145145
family = "%s"
146146
}
147147
}
148148
149149
resource "google_bigtable_gc_policy" "policy" {
150-
instance_name = google_bigtable_instance.instance.name
150+
instance_name = google_bigtable_instance.instance.id
151151
table = google_bigtable_table.table.name
152152
column_family = "%s"
153153

google/resource_bigtable_table.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ func resourceBigtableTable() *schema.Resource {
4040
},
4141

4242
"instance_name": {
43-
Type: schema.TypeString,
44-
Required: true,
45-
ForceNew: true,
43+
Type: schema.TypeString,
44+
Required: true,
45+
ForceNew: true,
46+
DiffSuppressFunc: compareResourceNames,
4647
},
4748

4849
"split_keys": {
@@ -71,11 +72,12 @@ func resourceBigtableTableCreate(d *schema.ResourceData, meta interface{}) error
7172
return err
7273
}
7374

74-
instanceName := d.Get("instance_name").(string)
75+
instanceName := GetResourceNameFromSelfLink(d.Get("instance_name").(string))
7576
c, err := config.bigtableClientFactory.NewAdminClient(project, instanceName)
7677
if err != nil {
7778
return fmt.Errorf("Error starting admin client. %s", err)
7879
}
80+
d.Set("instance_name", instanceName)
7981

8082
defer c.Close()
8183

@@ -129,7 +131,7 @@ func resourceBigtableTableRead(d *schema.ResourceData, meta interface{}) error {
129131
return err
130132
}
131133

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

163-
instanceName := d.Get("instance_name").(string)
165+
instanceName := GetResourceNameFromSelfLink(d.Get("instance_name").(string))
164166
c, err := config.bigtableClientFactory.NewAdminClient(project, instanceName)
165167
if err != nil {
166168
return fmt.Errorf("Error starting admin client. %s", err)

google/resource_bigtable_table_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ resource "google_bigtable_instance" "instance" {
143143
144144
resource "google_bigtable_table" "table" {
145145
name = "%s"
146-
instance_name = google_bigtable_instance.instance.name
146+
instance_name = google_bigtable_instance.instance.id
147147
}
148148
`, instanceName, instanceName, tableName)
149149
}
@@ -161,7 +161,7 @@ resource "google_bigtable_instance" "instance" {
161161
162162
resource "google_bigtable_table" "table" {
163163
name = "%s"
164-
instance_name = google_bigtable_instance.instance.name
164+
instance_name = google_bigtable_instance.instance.id
165165
split_keys = ["a", "b", "c"]
166166
}
167167
`, instanceName, instanceName, tableName)

0 commit comments

Comments
 (0)