From 4e3465db04a5372c0a1fcc55e96b46be994e2480 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Thu, 27 Feb 2020 01:36:22 +0000 Subject: [PATCH] allow id for bigtable app profile instance (#3174) Signed-off-by: Modular Magician --- .changelog/3174.txt | 3 +++ google/resource_bigtable_app_profile.go | 25 ++++++++++++++++---- google/resource_bigtable_app_profile_test.go | 4 ++-- google/self_link_helpers.go | 5 ++++ 4 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 .changelog/3174.txt diff --git a/.changelog/3174.txt b/.changelog/3174.txt new file mode 100644 index 00000000000..f98450c2156 --- /dev/null +++ b/.changelog/3174.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +bigtable: Added support for full-name/id `instance` value in `google_bigtable_app_profile` +``` diff --git a/google/resource_bigtable_app_profile.go b/google/resource_bigtable_app_profile.go index f70c838561e..9d484159475 100644 --- a/google/resource_bigtable_app_profile.go +++ b/google/resource_bigtable_app_profile.go @@ -61,10 +61,11 @@ func resourceBigtableAppProfile() *schema.Resource { Default: false, }, "instance": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Description: `The name of the instance to create the app profile within.`, + Type: schema.TypeString, + Optional: true, + ForceNew: true, + DiffSuppressFunc: compareResourceNames, + Description: `The name of the instance to create the app profile within.`, }, "multi_cluster_routing_use_any": { Type: schema.TypeBool, @@ -136,6 +137,11 @@ func resourceBigtableAppProfileCreate(d *schema.ResourceData, meta interface{}) obj["singleClusterRouting"] = singleClusterRoutingProp } + obj, err = resourceBigtableAppProfileEncoder(d, meta, obj) + if err != nil { + return err + } + url, err := replaceVars(d, config, "{{BigtableBasePath}}projects/{{project}}/instances/{{instance}}/appProfiles?appProfileId={{app_profile_id}}") if err != nil { return err @@ -216,6 +222,11 @@ func resourceBigtableAppProfileUpdate(d *schema.ResourceData, meta interface{}) obj["description"] = descriptionProp } + obj, err = resourceBigtableAppProfileEncoder(d, meta, obj) + if err != nil { + return err + } + url, err := replaceVars(d, config, "{{BigtableBasePath}}projects/{{project}}/instances/{{instance}}/appProfiles/{{app_profile_id}}?ignoreWarnings={{ignore_warnings}}") if err != nil { return err @@ -367,3 +378,9 @@ func expandBigtableAppProfileSingleClusterRoutingClusterId(v interface{}, d Terr func expandBigtableAppProfileSingleClusterRoutingAllowTransactionalWrites(v interface{}, d TerraformResourceData, config *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. + d.Set("instance", GetResourceNameFromSelfLink(d.Get("instance").(string))) + return obj, nil +} diff --git a/google/resource_bigtable_app_profile_test.go b/google/resource_bigtable_app_profile_test.go index bae6f3149c3..3347235b309 100644 --- a/google/resource_bigtable_app_profile_test.go +++ b/google/resource_bigtable_app_profile_test.go @@ -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 @@ -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" diff --git a/google/self_link_helpers.go b/google/self_link_helpers.go index f5cb0893e11..df239b7c99c 100644 --- a/google/self_link_helpers.go +++ b/google/self_link_helpers.go @@ -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)