Skip to content

Commit

Permalink
Allow updating single_cluster_routing in google_bigtable_app_profile (#…
Browse files Browse the repository at this point in the history
…3967) (#7266)

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Sep 14, 2020
1 parent bf3ff3a commit b0bcd0f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .changelog/3967.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
bigtable: fixed the update behaviour of the `single_cluster_routing` sub-fields in `google_bigtable_app_profile`
```
11 changes: 10 additions & 1 deletion google/resource_bigtable_app_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ consistency to improve availability.`,
"single_cluster_routing": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `Use a single-cluster routing policy.`,
MaxItems: 1,
Elem: &schema.Resource{
Expand Down Expand Up @@ -245,6 +244,12 @@ func resourceBigtableAppProfileUpdate(d *schema.ResourceData, meta interface{})
} else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
obj["description"] = descriptionProp
}
singleClusterRoutingProp, err := expandBigtableAppProfileSingleClusterRouting(d.Get("single_cluster_routing"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("single_cluster_routing"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, singleClusterRoutingProp)) {
obj["singleClusterRouting"] = singleClusterRoutingProp
}

obj, err = resourceBigtableAppProfileEncoder(d, meta, obj)
if err != nil {
Expand All @@ -262,6 +267,10 @@ func resourceBigtableAppProfileUpdate(d *schema.ResourceData, meta interface{})
if d.HasChange("description") {
updateMask = append(updateMask, "description")
}

if d.HasChange("single_cluster_routing") {
updateMask = append(updateMask, "singleClusterRouting")
}
// updateMask is a URL parameter but not present in the schema, so replaceVars
// won't set it
url, err = addQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
Expand Down
24 changes: 16 additions & 8 deletions google/resource_bigtable_app_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestAccBigtableAppProfile_update(t *testing.T) {
CheckDestroy: testAccCheckBigtableAppProfileDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccBigtableAppProfile_multiClusterRouting(instanceName),
Config: testAccBigtableAppProfile_update1(instanceName),
},
{
ResourceName: "google_bigtable_app_profile.ap",
Expand All @@ -29,7 +29,7 @@ func TestAccBigtableAppProfile_update(t *testing.T) {
ImportStateVerifyIgnore: []string{"ignore_warnings"},
},
{
Config: testAccBigtableAppProfile_update(instanceName),
Config: testAccBigtableAppProfile_update2(instanceName),
},
{
ResourceName: "google_bigtable_app_profile.ap",
Expand All @@ -41,7 +41,7 @@ func TestAccBigtableAppProfile_update(t *testing.T) {
})
}

func testAccBigtableAppProfile_multiClusterRouting(instanceName string) string {
func testAccBigtableAppProfile_update1(instanceName string) string {
return fmt.Sprintf(`
resource "google_bigtable_instance" "instance" {
name = "%s"
Expand All @@ -59,13 +59,17 @@ resource "google_bigtable_app_profile" "ap" {
instance = google_bigtable_instance.instance.id
app_profile_id = "test"
multi_cluster_routing_use_any = true
single_cluster_routing {
cluster_id = %q
allow_transactional_writes = true
}
ignore_warnings = true
}
`, instanceName, instanceName)
`, instanceName, instanceName, instanceName)
}

func testAccBigtableAppProfile_update(instanceName string) string {
func testAccBigtableAppProfile_update2(instanceName string) string {
return fmt.Sprintf(`
resource "google_bigtable_instance" "instance" {
name = "%s"
Expand All @@ -84,8 +88,12 @@ resource "google_bigtable_app_profile" "ap" {
app_profile_id = "test"
description = "add a description"
multi_cluster_routing_use_any = true
single_cluster_routing {
cluster_id = %q
allow_transactional_writes = false
}
ignore_warnings = true
}
`, instanceName, instanceName)
`, instanceName, instanceName, instanceName)
}

0 comments on commit b0bcd0f

Please sign in to comment.