Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow id for bigtable appprofile instance #5780

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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