Skip to content

Commit 0b83814

Browse files
Fix for the google_compute_router_route_policy - unable to create route policy with priority 0. (#13697) (#22417)
[upstream:ba320860e112d79aebe8d338a8df51a81af7dfda] Signed-off-by: Modular Magician <[email protected]>
1 parent 6fa7ab3 commit 0b83814

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

.changelog/13697.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
compute: fixed an issue preventing `terms.priority` from being set to priority value 0 in `google_compute_router_route_policy` resource
3+
```

google/services/compute/resource_compute_router_route_policy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ func expandComputeRouterRoutePolicyTerms(v interface{}, d tpgresource.TerraformR
660660
transformedPriority, err := expandComputeRouterRoutePolicyTermsPriority(original["priority"], d, config)
661661
if err != nil {
662662
return nil, err
663-
} else if val := reflect.ValueOf(transformedPriority); val.IsValid() && !tpgresource.IsEmptyValue(val) {
663+
} else if val := reflect.ValueOf(transformedPriority); val.IsValid() {
664664
transformed["priority"] = transformedPriority
665665
}
666666

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
package compute_test
4+
5+
import (
6+
"fmt"
7+
"testing"
8+
9+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
10+
"github.com/hashicorp/terraform-provider-google/google/acctest"
11+
)
12+
13+
func TestAccComputeRouterRoutePolicy_PriorityZero(t *testing.T) {
14+
t.Parallel()
15+
16+
routerName := fmt.Sprintf("tf-test-router-%s", acctest.RandString(t, 10))
17+
routePolicyName := fmt.Sprintf("route-policy-%s", acctest.RandString(t, 5))
18+
resourceName := "google_compute_router_route_policy.route_policy"
19+
20+
acctest.VcrTest(t, resource.TestCase{
21+
PreCheck: func() { acctest.AccTestPreCheck(t) },
22+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
23+
CheckDestroy: testAccCheckComputeRouterRoutePolicyDestroyProducer(t),
24+
Steps: []resource.TestStep{
25+
{
26+
Config: testAccComputeRouterRoutePolicyPriorityZero(routerName, routePolicyName),
27+
Check: resource.ComposeTestCheckFunc(
28+
resource.TestCheckResourceAttr(resourceName, "terms.0.priority", "0"),
29+
),
30+
},
31+
},
32+
})
33+
}
34+
35+
func testAccComputeRouterRoutePolicyPriorityZero(routerName, routePolicyName string) string {
36+
return fmt.Sprintf(`
37+
resource "google_compute_network" "vpc" {
38+
name = "vpc-%[1]s"
39+
auto_create_subnetworks = false
40+
}
41+
42+
resource "google_compute_router" "router" {
43+
name = "%[1]s"
44+
region = "us-central1"
45+
network = google_compute_network.vpc.id
46+
}
47+
48+
resource "google_compute_router_route_policy" "route_policy" {
49+
name = "%[2]s"
50+
router = google_compute_router.router.name
51+
region = "us-central1"
52+
type = "ROUTE_POLICY_TYPE_IMPORT"
53+
54+
terms {
55+
priority = 0
56+
57+
match {
58+
expression = "destination == '192.168.0.0/24'"
59+
title = "match-title"
60+
description = "test match description"
61+
location = "us-central1"
62+
}
63+
64+
actions {
65+
expression = "accept()"
66+
title = "actions-title"
67+
description = "test actions description"
68+
location = "us-central1"
69+
}
70+
}
71+
}
72+
`, routerName, routePolicyName)
73+
}

0 commit comments

Comments
 (0)