Skip to content

Commit

Permalink
allow id for bigtable app profile instance (#3174) (#5780)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Feb 27, 2020
1 parent 659a23e commit dcf9cfe
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .changelog/3174.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
bigtable: Added support for full-name/id `instance` value in `google_bigtable_app_profile`
```
25 changes: 21 additions & 4 deletions google/resource_bigtable_app_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions google/resource_bigtable_app_profile_test.go
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 google/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 dcf9cfe

Please sign in to comment.