Skip to content

Commit 5a9ccc5

Browse files
Bigtable: Add standard_isolation and priority fields for request priorities (#9442) (#16485)
* Add standard_isolation and priority fields for request priorities. * Add required property to priority field. [upstream:9ce5b3608114571176692dbc9e88bca28c16b1fa] Signed-off-by: Modular Magician <[email protected]>
1 parent baf6942 commit 5a9ccc5

5 files changed

+248
-2
lines changed

.changelog/9442.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
bigtable: added `standard_isolation` and `standard_isolation.priority` fields to `google_bigtable_app_profile` resource
3+
```

google/services/bigtable/resource_bigtable_app_profile.go

+77
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030

3131
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
3232
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
33+
"github.com/hashicorp/terraform-provider-google/google/verify"
3334
)
3435

3536
func ResourceBigtableAppProfile() *schema.Resource {
@@ -108,6 +109,23 @@ It is unsafe to send these requests to the same table/row/column in multiple clu
108109
},
109110
ExactlyOneOf: []string{"single_cluster_routing", "multi_cluster_routing_use_any"},
110111
},
112+
"standard_isolation": {
113+
Type: schema.TypeList,
114+
Computed: true,
115+
Optional: true,
116+
Description: `The standard options used for isolating this app profile's traffic from other use cases.`,
117+
MaxItems: 1,
118+
Elem: &schema.Resource{
119+
Schema: map[string]*schema.Schema{
120+
"priority": {
121+
Type: schema.TypeString,
122+
Required: true,
123+
ValidateFunc: verify.ValidateEnum([]string{"PRIORITY_LOW", "PRIORITY_MEDIUM", "PRIORITY_HIGH"}),
124+
Description: `The priority of requests sent using this app profile. Possible values: ["PRIORITY_LOW", "PRIORITY_MEDIUM", "PRIORITY_HIGH"]`,
125+
},
126+
},
127+
},
128+
},
111129
"name": {
112130
Type: schema.TypeString,
113131
Computed: true,
@@ -159,6 +177,12 @@ func resourceBigtableAppProfileCreate(d *schema.ResourceData, meta interface{})
159177
} else if v, ok := d.GetOkExists("single_cluster_routing"); !tpgresource.IsEmptyValue(reflect.ValueOf(singleClusterRoutingProp)) && (ok || !reflect.DeepEqual(v, singleClusterRoutingProp)) {
160178
obj["singleClusterRouting"] = singleClusterRoutingProp
161179
}
180+
standardIsolationProp, err := expandBigtableAppProfileStandardIsolation(d.Get("standard_isolation"), d, config)
181+
if err != nil {
182+
return err
183+
} else if v, ok := d.GetOkExists("standard_isolation"); !tpgresource.IsEmptyValue(reflect.ValueOf(standardIsolationProp)) && (ok || !reflect.DeepEqual(v, standardIsolationProp)) {
184+
obj["standardIsolation"] = standardIsolationProp
185+
}
162186

163187
obj, err = resourceBigtableAppProfileEncoder(d, meta, obj)
164188
if err != nil {
@@ -264,6 +288,9 @@ func resourceBigtableAppProfileRead(d *schema.ResourceData, meta interface{}) er
264288
if err := d.Set("single_cluster_routing", flattenBigtableAppProfileSingleClusterRouting(res["singleClusterRouting"], d, config)); err != nil {
265289
return fmt.Errorf("Error reading AppProfile: %s", err)
266290
}
291+
if err := d.Set("standard_isolation", flattenBigtableAppProfileStandardIsolation(res["standardIsolation"], d, config)); err != nil {
292+
return fmt.Errorf("Error reading AppProfile: %s", err)
293+
}
267294

268295
return nil
269296
}
@@ -302,6 +329,12 @@ func resourceBigtableAppProfileUpdate(d *schema.ResourceData, meta interface{})
302329
} else if v, ok := d.GetOkExists("single_cluster_routing"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, singleClusterRoutingProp)) {
303330
obj["singleClusterRouting"] = singleClusterRoutingProp
304331
}
332+
standardIsolationProp, err := expandBigtableAppProfileStandardIsolation(d.Get("standard_isolation"), d, config)
333+
if err != nil {
334+
return err
335+
} else if v, ok := d.GetOkExists("standard_isolation"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, standardIsolationProp)) {
336+
obj["standardIsolation"] = standardIsolationProp
337+
}
305338

306339
obj, err = resourceBigtableAppProfileEncoder(d, meta, obj)
307340
if err != nil {
@@ -327,6 +360,10 @@ func resourceBigtableAppProfileUpdate(d *schema.ResourceData, meta interface{})
327360
if d.HasChange("single_cluster_routing") {
328361
updateMask = append(updateMask, "singleClusterRouting")
329362
}
363+
364+
if d.HasChange("standard_isolation") {
365+
updateMask = append(updateMask, "standardIsolation")
366+
}
330367
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
331368
// won't set it
332369
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
@@ -502,6 +539,23 @@ func flattenBigtableAppProfileSingleClusterRoutingAllowTransactionalWrites(v int
502539
return v
503540
}
504541

542+
func flattenBigtableAppProfileStandardIsolation(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
543+
if v == nil {
544+
return nil
545+
}
546+
original := v.(map[string]interface{})
547+
if len(original) == 0 {
548+
return nil
549+
}
550+
transformed := make(map[string]interface{})
551+
transformed["priority"] =
552+
flattenBigtableAppProfileStandardIsolationPriority(original["priority"], d, config)
553+
return []interface{}{transformed}
554+
}
555+
func flattenBigtableAppProfileStandardIsolationPriority(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
556+
return v
557+
}
558+
505559
func expandBigtableAppProfileDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
506560
return v, nil
507561
}
@@ -556,6 +610,29 @@ func expandBigtableAppProfileSingleClusterRoutingAllowTransactionalWrites(v inte
556610
return v, nil
557611
}
558612

613+
func expandBigtableAppProfileStandardIsolation(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
614+
l := v.([]interface{})
615+
if len(l) == 0 || l[0] == nil {
616+
return nil, nil
617+
}
618+
raw := l[0]
619+
original := raw.(map[string]interface{})
620+
transformed := make(map[string]interface{})
621+
622+
transformedPriority, err := expandBigtableAppProfileStandardIsolationPriority(original["priority"], d, config)
623+
if err != nil {
624+
return nil, err
625+
} else if val := reflect.ValueOf(transformedPriority); val.IsValid() && !tpgresource.IsEmptyValue(val) {
626+
transformed["priority"] = transformedPriority
627+
}
628+
629+
return transformed, nil
630+
}
631+
632+
func expandBigtableAppProfileStandardIsolationPriority(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
633+
return v, nil
634+
}
635+
559636
func resourceBigtableAppProfileEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
560637
// Instance is a URL parameter only, so replace self-link/path with resource name only.
561638
if err := d.Set("instance", tpgresource.GetResourceNameFromSelfLink(d.Get("instance").(string))); err != nil {

google/services/bigtable/resource_bigtable_app_profile_generated_test.go

+61-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ resource "google_bigtable_instance" "instance" {
7878
zone = "us-central1-c"
7979
num_nodes = 3
8080
storage_type = "HDD"
81-
}
81+
}
8282
8383
deletion_protection = "%{deletion_protection}"
8484
}
@@ -217,6 +217,66 @@ resource "google_bigtable_app_profile" "ap" {
217217
`, context)
218218
}
219219

220+
func TestAccBigtableAppProfile_bigtableAppProfilePriorityExample(t *testing.T) {
221+
acctest.SkipIfVcr(t)
222+
t.Parallel()
223+
224+
context := map[string]interface{}{
225+
"deletion_protection": false,
226+
"random_suffix": acctest.RandString(t, 10),
227+
}
228+
229+
acctest.VcrTest(t, resource.TestCase{
230+
PreCheck: func() { acctest.AccTestPreCheck(t) },
231+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
232+
CheckDestroy: testAccCheckBigtableAppProfileDestroyProducer(t),
233+
Steps: []resource.TestStep{
234+
{
235+
Config: testAccBigtableAppProfile_bigtableAppProfilePriorityExample(context),
236+
},
237+
{
238+
ResourceName: "google_bigtable_app_profile.ap",
239+
ImportState: true,
240+
ImportStateVerify: true,
241+
ImportStateVerifyIgnore: []string{"app_profile_id", "instance", "ignore_warnings", "ignore_warnings"},
242+
},
243+
},
244+
})
245+
}
246+
247+
func testAccBigtableAppProfile_bigtableAppProfilePriorityExample(context map[string]interface{}) string {
248+
return acctest.Nprintf(`
249+
resource "google_bigtable_instance" "instance" {
250+
name = "tf-test-bt-instance%{random_suffix}"
251+
cluster {
252+
cluster_id = "cluster-1"
253+
zone = "us-central1-b"
254+
num_nodes = 3
255+
storage_type = "HDD"
256+
}
257+
258+
deletion_protection = "%{deletion_protection}"
259+
}
260+
261+
resource "google_bigtable_app_profile" "ap" {
262+
instance = google_bigtable_instance.instance.name
263+
app_profile_id = "tf-test-bt-profile%{random_suffix}"
264+
265+
// Requests will be routed to the following cluster.
266+
single_cluster_routing {
267+
cluster_id = "cluster-1"
268+
allow_transactional_writes = true
269+
}
270+
271+
standard_isolation {
272+
priority = "PRIORITY_LOW"
273+
}
274+
275+
ignore_warnings = true
276+
}
277+
`, context)
278+
}
279+
220280
func testAccCheckBigtableAppProfileDestroyProducer(t *testing.T) func(s *terraform.State) error {
221281
return func(s *terraform.State) error {
222282
for name, rs := range s.RootModule().Resources {

google/services/bigtable/resource_bigtable_app_profile_test.go

+56
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ func TestAccBigtableAppProfile_update(t *testing.T) {
4040
ImportStateVerify: true,
4141
ImportStateVerifyIgnore: []string{"ignore_warnings"},
4242
},
43+
{
44+
Config: testAccBigtableAppProfile_updatePriority(instanceName),
45+
},
46+
{
47+
ResourceName: "google_bigtable_app_profile.ap",
48+
ImportState: true,
49+
ImportStateVerify: true,
50+
ImportStateVerifyIgnore: []string{"ignore_warnings"},
51+
},
4352
},
4453
})
4554
}
@@ -231,6 +240,53 @@ resource "google_bigtable_app_profile" "ap" {
231240
`, instanceName, instanceName, instanceName, instanceName, instanceName)
232241
}
233242

243+
func testAccBigtableAppProfile_updatePriority(instanceName string) string {
244+
return fmt.Sprintf(`
245+
resource "google_bigtable_instance" "instance" {
246+
name = "%s"
247+
cluster {
248+
cluster_id = "%s"
249+
zone = "us-central1-b"
250+
num_nodes = 1
251+
storage_type = "HDD"
252+
}
253+
254+
cluster {
255+
cluster_id = "%s2"
256+
zone = "us-central1-a"
257+
num_nodes = 1
258+
storage_type = "HDD"
259+
}
260+
261+
cluster {
262+
cluster_id = "%s3"
263+
zone = "us-central1-c"
264+
num_nodes = 1
265+
storage_type = "HDD"
266+
}
267+
268+
deletion_protection = false
269+
}
270+
271+
resource "google_bigtable_app_profile" "ap" {
272+
instance = google_bigtable_instance.instance.id
273+
app_profile_id = "test"
274+
description = "add a description"
275+
276+
single_cluster_routing {
277+
cluster_id = %q
278+
allow_transactional_writes = false
279+
}
280+
281+
standard_isolation {
282+
priority = "PRIORITY_MEDIUM"
283+
}
284+
285+
ignore_warnings = true
286+
}
287+
`, instanceName, instanceName, instanceName, instanceName, instanceName)
288+
}
289+
234290
func testAccBigtableAppProfile_warningsProduced(instanceName string) string {
235291
return fmt.Sprintf(`
236292
resource "google_bigtable_instance" "instance" {

website/docs/r/bigtable_app_profile.html.markdown

+51-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ resource "google_bigtable_instance" "instance" {
5454
zone = "us-central1-c"
5555
num_nodes = 3
5656
storage_type = "HDD"
57-
}
57+
}
5858
5959
deletion_protection = "true"
6060
}
@@ -147,6 +147,44 @@ resource "google_bigtable_app_profile" "ap" {
147147
ignore_warnings = true
148148
}
149149
```
150+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
151+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=bigtable_app_profile_priority&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
152+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
153+
</a>
154+
</div>
155+
## Example Usage - Bigtable App Profile Priority
156+
157+
158+
```hcl
159+
resource "google_bigtable_instance" "instance" {
160+
name = "bt-instance"
161+
cluster {
162+
cluster_id = "cluster-1"
163+
zone = "us-central1-b"
164+
num_nodes = 3
165+
storage_type = "HDD"
166+
}
167+
168+
deletion_protection = "true"
169+
}
170+
171+
resource "google_bigtable_app_profile" "ap" {
172+
instance = google_bigtable_instance.instance.name
173+
app_profile_id = "bt-profile"
174+
175+
// Requests will be routed to the following cluster.
176+
single_cluster_routing {
177+
cluster_id = "cluster-1"
178+
allow_transactional_writes = true
179+
}
180+
181+
standard_isolation {
182+
priority = "PRIORITY_LOW"
183+
}
184+
185+
ignore_warnings = true
186+
}
187+
```
150188

151189
## Argument Reference
152190

@@ -176,6 +214,11 @@ The following arguments are supported:
176214
Use a single-cluster routing policy.
177215
Structure is [documented below](#nested_single_cluster_routing).
178216

217+
* `standard_isolation` -
218+
(Optional)
219+
The standard options used for isolating this app profile's traffic from other use cases.
220+
Structure is [documented below](#nested_standard_isolation).
221+
179222
* `instance` -
180223
(Optional)
181224
The name of the instance to create the app profile within.
@@ -199,6 +242,13 @@ The following arguments are supported:
199242
If true, CheckAndMutateRow and ReadModifyWriteRow requests are allowed by this app profile.
200243
It is unsafe to send these requests to the same table/row/column in multiple clusters.
201244

245+
<a name="nested_standard_isolation"></a>The `standard_isolation` block supports:
246+
247+
* `priority` -
248+
(Required)
249+
The priority of requests sent using this app profile.
250+
Possible values are: `PRIORITY_LOW`, `PRIORITY_MEDIUM`, `PRIORITY_HIGH`.
251+
202252
## Attributes Reference
203253

204254
In addition to the arguments listed above, the following computed attributes are exported:

0 commit comments

Comments
 (0)