Skip to content

Commit

Permalink
update bigtable app profile
Browse files Browse the repository at this point in the history
  • Loading branch information
megan07 committed Aug 13, 2019
1 parent 07b6305 commit 40ecf49
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 11 deletions.
19 changes: 14 additions & 5 deletions products/bigtable/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
# limitations under the License.

--- !ruby/object:Api::Product
name: BigTable
name: Bigtable
display_name: BigTable
versions:
- !ruby/object:Api::Product::Version
name: ga
base_url: https://www.googleapis.com/bigtable/v2/
base_url: https://bigtableadmin.googleapis.com/v2/
scopes:
- https://www.googleapis.com/auth/bigtable
apis_required:
Expand All @@ -28,14 +28,23 @@ objects:
- !ruby/object:Api::Resource
name: 'AppProfile'
kind: 'bigtable#appProfile'
base_url: projects/{{project}}/instances/{{instance}}/appProfiles
base_url: projects/{{project}}/instances/{{instance}}/appProfiles/{{app_profile_id}}
create_url: projects/{{project}}/instances/{{instance}}/appProfiles?appProfileId={{app_profile_id}}
update_url: projects/{{project}}/instances/{{instance}}/appProfiles?updateMask=
update_verb: :PATCH
delete_url: projects/{{project}}/instances/{{instance}}/appProfiles/{{app_profile_id}}?ignoreWarnings=true
self_link: 'projects/{{project}}/instances/{{instance}}/appProfiles/{{app_profile_id}}'
description: |
App profile is a configuration object describing how Cloud Bigtable should treat traffic from a particular end user application.
properties:
- !ruby/object:Api::Type::String
name: 'name'
description: 'The unique name of the app profile. Values are of the form `projects/<project>/instances/<instance>/appProfiles/[_a-zA-Z0-9][-_.a-zA-Z0-9]*.`'
description: 'The unique name of the requested app profile. Values are of the form `projects/<project>/instances/<instance>/appProfiles/<appProfileId>`.'
output: true
- !ruby/object:Api::Type::String
name: 'appProfileId'
description: 'The unique name of the app profile in the form `[_a-zA-Z0-9][-_.a-zA-Z0-9]*`.'
required: true
- !ruby/object:Api::Type::String
name: 'instance'
description: 'The name of the instance to create the app profile within.'
Expand Down Expand Up @@ -64,4 +73,4 @@ objects:
name: 'allowTransactionalWrites'
description: |
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.
It is unsafe to send these requests to the same table/row/column in multiple clusters.
9 changes: 5 additions & 4 deletions products/bigtable/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
--- !ruby/object:Provider::Terraform::Config
overrides: !ruby/object:Overrides::ResourceOverrides
AppProfile: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: "{{project}}/{{region}}/{{name}}"
properties:
multiClusterRoutingUseAny: !ruby/object:Overrides::Terraform::PropertyOverride
default_value: true
id_format: "{{project}}/{{instance}}/{{app_profile_id}}"
import_format: ["projects/{{project}}/instances/{{instance}}/appProfiles/{{app_profile_id}}"]
custom_code: !ruby/object:Provider::Terraform::CustomCode
encoder: templates/terraform/encoders/app_profile.erb
decoder: templates/terraform/decoders/app_profile.erb

# This is for copying files over
files: !ruby/object:Provider::Config::Files
Expand Down
11 changes: 11 additions & 0 deletions templates/terraform/decoders/app_profile.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if _, ok := res["multiClusterRoutingUseAny"]; ok {
res["multiClusterRoutingUseAny"] = true
}

if _, ok := res["name"]; ok {
x := strings.Split(res["name"].(string), "/")
res["appProfileId"] = x[len(x)-1]
res["instance"] = x[3]
}

return res, nil
22 changes: 22 additions & 0 deletions templates/terraform/encoders/app_profile.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%# The license inside this block applies to this file.
# Copyright 2017 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-%>
delete(obj, "appProfileId")
delete(obj, "instance")

if mc_routing := d.Get("multi_cluster_routing_use_any").(bool); mc_routing {
obj["multiClusterRoutingUseAny"] = bigtableadmin.MultiClusterRoutingUseAny{}
}

return obj, nil
51 changes: 49 additions & 2 deletions third_party/terraform/tests/resource_bigtable_app_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@ func TestAccBigtableAppProfile_basic(t *testing.T) {
Steps: []resource.TestStep{
{
Config: testAccBigtableAppProfile_multiClusterRouting(instanceName),
},
{
ResourceName: "google_bigtable_app_profile.ap",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccBigtableAppProfile_singleClusterRouting(t *testing.T) {
t.Parallel()

instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckBigtableAppProfileDestroy,
Steps: []resource.TestStep{
{
Config: testAccBigtableAppProfile_singleClusterRouting(instanceName),
Check: resource.ComposeTestCheckFunc(
testAccBigtableAppProfileExists(
"google_bigtable_app_profile.ap"),
Expand Down Expand Up @@ -74,9 +96,9 @@ func testAccBigtableAppProfileExists(n string) resource.TestCheckFunc {

defer c.Close()

_, err = c.GetAppProfile(ctx, rs.Primary.Attributes["instance"], rs.Primary.Attributes["name"])
_, err = c.GetAppProfile(ctx, rs.Primary.Attributes["instance"], rs.Primary.Attributes["app_profile_id"])
if err != nil {
return fmt.Errorf("Error retrieving app profile %s for instance %s.", rs.Primary.Attributes["name"], rs.Primary.Attributes["instance"])
return fmt.Errorf("Error retrieving app profile %s for instance %s.", rs.Primary.Attributes["app_profile_id"], rs.Primary.Attributes["instance"])
}

return nil
Expand All @@ -97,8 +119,33 @@ resource "google_bigtable_instance" "instance" {
resource "google_bigtable_app_profile" "ap" {
instance = google_bigtable_instance.instance.name
app_profile_id = "test"
multi_cluster_routing_use_any = true
}
`, instanceName, instanceName)
}

func testAccBigtableAppProfile_singleClusterRouting(instanceName string) string {
return fmt.Sprintf(`
resource "google_bigtable_instance" "instance" {
name = "%s"
cluster {
cluster_id = "%s"
zone = "us-central1-b"
num_nodes = 3
storage_type = "HDD"
}
}
resource "google_bigtable_app_profile" "ap" {
instance = google_bigtable_instance.instance.name
app_profile_id = "test"
single_cluster_routing {
cluster_id = "%s"
allow_transactional_writes = true
}
}
`, instanceName, instanceName, instanceName)
}

0 comments on commit 40ecf49

Please sign in to comment.