|
| 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