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: Add standard_isolation and priority fields for request priorities #16485

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/9442.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
bigtable: added `standard_isolation` and `standard_isolation.priority` fields to `google_bigtable_app_profile` resource
```
77 changes: 77 additions & 0 deletions google/services/bigtable/resource_bigtable_app_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"github.com/hashicorp/terraform-provider-google/google/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
"github.com/hashicorp/terraform-provider-google/google/verify"
)

func ResourceBigtableAppProfile() *schema.Resource {
Expand Down Expand Up @@ -108,6 +109,23 @@ It is unsafe to send these requests to the same table/row/column in multiple clu
},
ExactlyOneOf: []string{"single_cluster_routing", "multi_cluster_routing_use_any"},
},
"standard_isolation": {
Type: schema.TypeList,
Computed: true,
Optional: true,
Description: `The standard options used for isolating this app profile's traffic from other use cases.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"priority": {
Type: schema.TypeString,
Required: true,
ValidateFunc: verify.ValidateEnum([]string{"PRIORITY_LOW", "PRIORITY_MEDIUM", "PRIORITY_HIGH"}),
Description: `The priority of requests sent using this app profile. Possible values: ["PRIORITY_LOW", "PRIORITY_MEDIUM", "PRIORITY_HIGH"]`,
},
},
},
},
"name": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -159,6 +177,12 @@ func resourceBigtableAppProfileCreate(d *schema.ResourceData, meta interface{})
} else if v, ok := d.GetOkExists("single_cluster_routing"); !tpgresource.IsEmptyValue(reflect.ValueOf(singleClusterRoutingProp)) && (ok || !reflect.DeepEqual(v, singleClusterRoutingProp)) {
obj["singleClusterRouting"] = singleClusterRoutingProp
}
standardIsolationProp, err := expandBigtableAppProfileStandardIsolation(d.Get("standard_isolation"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("standard_isolation"); !tpgresource.IsEmptyValue(reflect.ValueOf(standardIsolationProp)) && (ok || !reflect.DeepEqual(v, standardIsolationProp)) {
obj["standardIsolation"] = standardIsolationProp
}

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

return nil
}
Expand Down Expand Up @@ -302,6 +329,12 @@ func resourceBigtableAppProfileUpdate(d *schema.ResourceData, meta interface{})
} else if v, ok := d.GetOkExists("single_cluster_routing"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, singleClusterRoutingProp)) {
obj["singleClusterRouting"] = singleClusterRoutingProp
}
standardIsolationProp, err := expandBigtableAppProfileStandardIsolation(d.Get("standard_isolation"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("standard_isolation"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, standardIsolationProp)) {
obj["standardIsolation"] = standardIsolationProp
}

obj, err = resourceBigtableAppProfileEncoder(d, meta, obj)
if err != nil {
Expand All @@ -327,6 +360,10 @@ func resourceBigtableAppProfileUpdate(d *schema.ResourceData, meta interface{})
if d.HasChange("single_cluster_routing") {
updateMask = append(updateMask, "singleClusterRouting")
}

if d.HasChange("standard_isolation") {
updateMask = append(updateMask, "standardIsolation")
}
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
// won't set it
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
Expand Down Expand Up @@ -502,6 +539,23 @@ func flattenBigtableAppProfileSingleClusterRoutingAllowTransactionalWrites(v int
return v
}

func flattenBigtableAppProfileStandardIsolation(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return nil
}
original := v.(map[string]interface{})
if len(original) == 0 {
return nil
}
transformed := make(map[string]interface{})
transformed["priority"] =
flattenBigtableAppProfileStandardIsolationPriority(original["priority"], d, config)
return []interface{}{transformed}
}
func flattenBigtableAppProfileStandardIsolationPriority(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func expandBigtableAppProfileDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand Down Expand Up @@ -556,6 +610,29 @@ func expandBigtableAppProfileSingleClusterRoutingAllowTransactionalWrites(v inte
return v, nil
}

func expandBigtableAppProfileStandardIsolation(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedPriority, err := expandBigtableAppProfileStandardIsolationPriority(original["priority"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPriority); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["priority"] = transformedPriority
}

return transformed, nil
}

func expandBigtableAppProfileStandardIsolationPriority(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func resourceBigtableAppProfileEncoder(d *schema.ResourceData, meta interface{}, obj map[string]interface{}) (map[string]interface{}, error) {
// Instance is a URL parameter only, so replace self-link/path with resource name only.
if err := d.Set("instance", tpgresource.GetResourceNameFromSelfLink(d.Get("instance").(string))); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ resource "google_bigtable_instance" "instance" {
zone = "us-central1-c"
num_nodes = 3
storage_type = "HDD"
}
}

deletion_protection = "%{deletion_protection}"
}
Expand Down Expand Up @@ -217,6 +217,66 @@ resource "google_bigtable_app_profile" "ap" {
`, context)
}

func TestAccBigtableAppProfile_bigtableAppProfilePriorityExample(t *testing.T) {
acctest.SkipIfVcr(t)
t.Parallel()

context := map[string]interface{}{
"deletion_protection": false,
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckBigtableAppProfileDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccBigtableAppProfile_bigtableAppProfilePriorityExample(context),
},
{
ResourceName: "google_bigtable_app_profile.ap",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"app_profile_id", "instance", "ignore_warnings", "ignore_warnings"},
},
},
})
}

func testAccBigtableAppProfile_bigtableAppProfilePriorityExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_bigtable_instance" "instance" {
name = "tf-test-bt-instance%{random_suffix}"
cluster {
cluster_id = "cluster-1"
zone = "us-central1-b"
num_nodes = 3
storage_type = "HDD"
}

deletion_protection = "%{deletion_protection}"
}

resource "google_bigtable_app_profile" "ap" {
instance = google_bigtable_instance.instance.name
app_profile_id = "tf-test-bt-profile%{random_suffix}"

// Requests will be routed to the following cluster.
single_cluster_routing {
cluster_id = "cluster-1"
allow_transactional_writes = true
}

standard_isolation {
priority = "PRIORITY_LOW"
}

ignore_warnings = true
}
`, context)
}

func testAccCheckBigtableAppProfileDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
56 changes: 56 additions & 0 deletions google/services/bigtable/resource_bigtable_app_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ func TestAccBigtableAppProfile_update(t *testing.T) {
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ignore_warnings"},
},
{
Config: testAccBigtableAppProfile_updatePriority(instanceName),
},
{
ResourceName: "google_bigtable_app_profile.ap",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ignore_warnings"},
},
},
})
}
Expand Down Expand Up @@ -231,6 +240,53 @@ resource "google_bigtable_app_profile" "ap" {
`, instanceName, instanceName, instanceName, instanceName, instanceName)
}

func testAccBigtableAppProfile_updatePriority(instanceName string) string {
return fmt.Sprintf(`
resource "google_bigtable_instance" "instance" {
name = "%s"
cluster {
cluster_id = "%s"
zone = "us-central1-b"
num_nodes = 1
storage_type = "HDD"
}

cluster {
cluster_id = "%s2"
zone = "us-central1-a"
num_nodes = 1
storage_type = "HDD"
}

cluster {
cluster_id = "%s3"
zone = "us-central1-c"
num_nodes = 1
storage_type = "HDD"
}

deletion_protection = false
}

resource "google_bigtable_app_profile" "ap" {
instance = google_bigtable_instance.instance.id
app_profile_id = "test"
description = "add a description"

single_cluster_routing {
cluster_id = %q
allow_transactional_writes = false
}

standard_isolation {
priority = "PRIORITY_MEDIUM"
}

ignore_warnings = true
}
`, instanceName, instanceName, instanceName, instanceName, instanceName)
}

func testAccBigtableAppProfile_warningsProduced(instanceName string) string {
return fmt.Sprintf(`
resource "google_bigtable_instance" "instance" {
Expand Down
52 changes: 51 additions & 1 deletion website/docs/r/bigtable_app_profile.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ resource "google_bigtable_instance" "instance" {
zone = "us-central1-c"
num_nodes = 3
storage_type = "HDD"
}
}

deletion_protection = "true"
}
Expand Down Expand Up @@ -147,6 +147,44 @@ resource "google_bigtable_app_profile" "ap" {
ignore_warnings = true
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgit.luolix.top%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">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Bigtable App Profile Priority


```hcl
resource "google_bigtable_instance" "instance" {
name = "bt-instance"
cluster {
cluster_id = "cluster-1"
zone = "us-central1-b"
num_nodes = 3
storage_type = "HDD"
}

deletion_protection = "true"
}

resource "google_bigtable_app_profile" "ap" {
instance = google_bigtable_instance.instance.name
app_profile_id = "bt-profile"

// Requests will be routed to the following cluster.
single_cluster_routing {
cluster_id = "cluster-1"
allow_transactional_writes = true
}

standard_isolation {
priority = "PRIORITY_LOW"
}

ignore_warnings = true
}
```

## Argument Reference

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

* `standard_isolation` -
(Optional)
The standard options used for isolating this app profile's traffic from other use cases.
Structure is [documented below](#nested_standard_isolation).

* `instance` -
(Optional)
The name of the instance to create the app profile within.
Expand All @@ -199,6 +242,13 @@ The following arguments are supported:
If true, CheckAndMutateRow and ReadModifyWriteRow requests are allowed by this app profile.
It is unsafe to send these requests to the same table/row/column in multiple clusters.

<a name="nested_standard_isolation"></a>The `standard_isolation` block supports:

* `priority` -
(Required)
The priority of requests sent using this app profile.
Possible values are: `PRIORITY_LOW`, `PRIORITY_MEDIUM`, `PRIORITY_HIGH`.

## Attributes Reference

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