Skip to content

Commit

Permalink
Add bigtable app profile resource (#2113)
Browse files Browse the repository at this point in the history
Merged PR #2113.
  • Loading branch information
megan07 authored and modular-magician committed Aug 16, 2019
1 parent 7e83d64 commit 7d2161c
Show file tree
Hide file tree
Showing 10 changed files with 303 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
2 changes: 1 addition & 1 deletion build/terraform-mapper
90 changes: 90 additions & 0 deletions products/bigtable/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# 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.

--- !ruby/object:Api::Product
name: Bigtable
display_name: BigTable
versions:
- !ruby/object:Api::Product::Version
name: ga
base_url: https://bigtableadmin.googleapis.com/v2/
scopes:
- https://www.googleapis.com/auth/bigtable
apis_required:
- !ruby/object:Api::Product::ApiReference
name: BigTable API
url: https://console.cloud.google.com/apis/library/bigtable.googleapis.com/
objects:
- !ruby/object:Api::Resource
name: 'AppProfile'
kind: 'bigtable#appProfile'
base_url: projects/{{project}}/instances/{{instance}}/appProfiles?appProfileId={{app_profile_id}}
update_url: projects/{{project}}/instances/{{instance}}/appProfiles/{{app_profile_id}}?ignoreWarnings={{ignore_warnings}}
delete_url: projects/{{project}}/instances/{{instance}}/appProfiles/{{app_profile_id}}?ignoreWarnings={{ignore_warnings}}
update_verb: :PATCH
update_mask: 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.
parameters:
- !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
input: true
url_param_only: true
- !ruby/object:Api::Type::String
name: 'instance'
description: 'The name of the instance to create the app profile within.'
input: true
url_param_only: true
- !ruby/object:Api::Type::Boolean
name: 'ignoreWarnings'
description: 'If true, ignore safety checks when deleting/updating the app profile.'
default_value: false
url_param_only: true
properties:
- !ruby/object:Api::Type::String
name: 'name'
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: 'description'
description: |
Long form description of the use case for this app profile.
- !ruby/object:Api::Type::Boolean
name: 'multiClusterRoutingUseAny'
conflicts:
- singleClusterRouting
description: |
If true, read/write requests are routed to the nearest cluster in the instance, and will fail over to the nearest cluster that is available
in the event of transient errors or delays. Clusters in a region are considered equidistant. Choosing this option sacrifices read-your-writes
consistency to improve availability.
input: true
- !ruby/object:Api::Type::NestedObject
name: 'singleClusterRouting'
conflicts:
- multiClusterRoutingUseAny
description: |
Use a single-cluster routing policy.
input: true
properties:
- !ruby/object:Api::Type::String
name: 'clusterId'
description: |
The cluster to which read/write requests should be routed.
- !ruby/object:Api::Type::Boolean
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.
46 changes: 46 additions & 0 deletions products/bigtable/terraform.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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.

--- !ruby/object:Provider::Terraform::Config
overrides: !ruby/object:Overrides::ResourceOverrides
AppProfile: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: "{{project}}/{{instance}}/{{app_profile_id}}"
import_format: ["projects/{{project}}/instances/{{instance}}/appProfiles/{{app_profile_id}}"]
examples:
- !ruby/object:Provider::Terraform::Examples
name: "bigtable_app_profile_multicluster"
primary_resource_id: "ap"
vars:
instance_name: "tf-test-instance-"
app_profile_name: "tf-test-profile-"
ignore_read_extra:
- "ignore_warnings"
- !ruby/object:Provider::Terraform::Examples
name: "bigtable_app_profile_singlecluster"
primary_resource_id: "ap"
vars:
instance_name: "tf-test-instance-"
app_profile_name: "tf-test-profile-"
ignore_read_extra:
- "ignore_warnings"
properties:
multiClusterRoutingUseAny: !ruby/object:Overrides::Terraform::PropertyOverride
custom_expand: 'templates/terraform/custom_expand/bigtable_app_profile_routing.erb'
custom_flatten: 'templates/terraform/custom_flatten/bigtable_app_profile_routing.erb'

# This is for copying files over
files: !ruby/object:Provider::Config::Files
# These files have templating (ERB) code that will be run.
# This is usually to add licensing info, autogeneration notices, etc.
compile:
<%= lines(indent(compile('provider/terraform/product~compile.yaml'), 4)) -%>
21 changes: 21 additions & 0 deletions templates/terraform/custom_expand/bigtable_app_profile_routing.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<%- # the license inside this block applies to this file
# Copyright 2018 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.
-%>
func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
if v == nil || !v.(bool) {
return nil, nil
}

return bigtableadmin.MultiClusterRoutingUseAny{}, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<%# 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.
-%>
func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData) interface{} {
if v == nil {
return false
}

return true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
resource "google_bigtable_instance" "instance" {
name = "<%= ctx[:vars]['instance_name'] %>"
cluster {
cluster_id = "<%= ctx[:vars]['instance_name'] %>"
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 = "<%= ctx[:vars]['app_profile_name'] %>"

multi_cluster_routing_use_any = true
ignore_warnings = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
resource "google_bigtable_instance" "instance" {
name = "<%= ctx[:vars]['instance_name'] %>"
cluster {
cluster_id = "<%= ctx[:vars]['instance_name'] %>"
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 = "<%= ctx[:vars]['app_profile_name'] %>"

single_cluster_routing {
cluster_id = "<%= ctx[:vars]['instance_name'] %>"
allow_transactional_writes = true
}

ignore_warnings = true
}
84 changes: 84 additions & 0 deletions third_party/terraform/tests/resource_bigtable_app_profile_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package google

import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccBigtableAppProfile_update(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_multiClusterRouting(instanceName),
},
{
ResourceName: "google_bigtable_app_profile.ap",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ignore_warnings"},
},
{
Config: testAccBigtableAppProfile_update(instanceName),
},
{
ResourceName: "google_bigtable_app_profile.ap",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"ignore_warnings"},
},
},
})
}

func testAccBigtableAppProfile_multiClusterRouting(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"
multi_cluster_routing_use_any = true
ignore_warnings = true
}`, instanceName, instanceName)
}

func testAccBigtableAppProfile_update(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"
description = "add a description"
multi_cluster_routing_use_any = true
ignore_warnings = true
}`, instanceName, instanceName)
}

0 comments on commit 7d2161c

Please sign in to comment.