Skip to content

Commit

Permalink
allow id for bigtable app profile instance (#3174)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilymye authored Feb 27, 2020
1 parent e5c60c9 commit 4cc88b3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
5 changes: 5 additions & 0 deletions products/bigtable/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ overrides: !ruby/object:Overrides::ResourceOverrides
ignore_read_extra:
- "ignore_warnings"
properties:
instance: !ruby/object:Overrides::Terraform::PropertyOverride
diff_suppress_func: compareResourceNames
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'
custom_code: !ruby/object:Provider::Terraform::CustomCode
encoder: templates/terraform/encoders/bigtable_app_profile.go.erb


# This is for copying files over
files: !ruby/object:Provider::Config::Files
Expand Down
20 changes: 20 additions & 0 deletions templates/terraform/encoders/bigtable_app_profile.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<%# The license inside this block applies to this file.
# Copyright 2020 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.
-%>
<%# Because instance is a URL param only, it does not get expanded and
# the URL is constructed from ResourceData. Set it in
# state and use a encoder instead of a field expander -%>
// Instance is a URL parameter only, so replace self-link/path with resource name only.
d.Set("instance", GetResourceNameFromSelfLink(d.Get("instance").(string)))
return obj, nil
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ resource "google_bigtable_instance" "instance" {
}
resource "google_bigtable_app_profile" "ap" {
instance = google_bigtable_instance.instance.name
instance = google_bigtable_instance.instance.id
app_profile_id = "test"
multi_cluster_routing_use_any = true
Expand All @@ -75,7 +75,7 @@ resource "google_bigtable_instance" "instance" {
}
resource "google_bigtable_app_profile" "ap" {
instance = google_bigtable_instance.instance.name
instance = google_bigtable_instance.instance.id
app_profile_id = "test"
description = "add a description"
Expand Down
5 changes: 5 additions & 0 deletions third_party/terraform/utils/self_link_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

// Compare only the resource name of two self links/paths.
func compareResourceNames(_, old, new string, _ *schema.ResourceData) bool {
return GetResourceNameFromSelfLink(old) == GetResourceNameFromSelfLink(new)
}

// Compare only the relative path of two self links.
func compareSelfLinkRelativePaths(_, old, new string, _ *schema.ResourceData) bool {
oldStripped, err := getRelativePath(old)
Expand Down

0 comments on commit 4cc88b3

Please sign in to comment.