Skip to content

Commit

Permalink
add update test
Browse files Browse the repository at this point in the history
  • Loading branch information
amanMahendroo committed Mar 1, 2025
1 parent fed2c98 commit 5a80ffe
Show file tree
Hide file tree
Showing 5 changed files with 252 additions and 47 deletions.
18 changes: 0 additions & 18 deletions mmv1/products/compute/RouterRoutePolicy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
name: 'RouterRoutePolicy'
api_resource_type_kind: Router
description: A route policy created in a router
min_version: 'beta'
references:
guides:
'Google Cloud Router': 'https://cloud.google.com/router/docs/'
Expand Down Expand Up @@ -65,7 +64,6 @@ parameters:
type: ResourceRef
description: |
The name of the Cloud Router in which this route policy will be configured.
min_version: 'beta'
url_param_only: true
required: true
immutable: true
Expand All @@ -74,7 +72,6 @@ parameters:
- name: 'region'
type: ResourceRef
description: Region where the router and NAT reside.
min_version: 'beta'
url_param_only: true
required: false
immutable: true
Expand All @@ -86,23 +83,20 @@ parameters:
type: String
description: |
Name of the route policy. This policy's name, which must be a resource ID segment and unique within all policies owned by the Router
min_version: 'beta'
required: true
immutable: true
properties:
- name: 'type'
type: Enum
description: |
This is policy's type, which is one of IMPORT or EXPORT
min_version: 'beta'
enum_values:
- 'ROUTE_POLICY_TYPE_IMPORT'
- 'ROUTE_POLICY_TYPE_EXPORT'
- name: 'terms'
type: Array
description: |
List of terms (the order in the list is not important, they are evaluated in order of priority).
min_version: 'beta'
required: true
immutable: true
item_type:
Expand All @@ -112,42 +106,35 @@ properties:
type: Integer
description: |
The evaluation priority for this term, which must be between 0 (inclusive) and 231 (exclusive), and unique within the list.
min_version: 'beta'
required: true
- name: 'match'
type: NestedObject
description: |
CEL expression evaluated against a route to determine if this term applies (see Policy Language). When not set, the term applies to all routes.
min_version: 'beta'
properties:
- name: 'expression'
type: String
description:
Textual representation of an expression in Common Expression
Language syntax.
min_version: 'beta'
required: true
- name: 'title'
type: String
description:
Title for the expression, i.e. a short string describing its
purpose.
min_version: 'beta'
- name: 'description'
type: String
description: Description of the expression
min_version: 'beta'
- name: 'location'
type: String
description:
String indicating the location of the expression for error
reporting, e.g. a file name and a position in the file
min_version: 'beta'
- name: 'actions'
type: Array
description: |
'CEL expressions to evaluate to modify a route when this term matches.'\
min_version: 'beta'
item_type:
type: NestedObject
properties:
Expand All @@ -156,29 +143,24 @@ properties:
description: |
Textual representation of an expression in Common Expression
Language syntax.
min_version: 'beta'
required: true
- name: 'title'
type: String
description: |
Title for the expression, i.e. a short string describing its
purpose.
min_version: 'beta'
- name: 'description'
type: String
description: |
Description of the expression
min_version: 'beta'
- name: 'location'
type: String
description: |
String indicating the location of the expression for error
reporting, e.g. a file name and a position in the file
min_version: 'beta'
- name: 'fingerprint'
type: Fingerprint
description: |
The fingerprint used for optimistic locking of this resource. Used
internally during updates.
min_version: 'beta'
output: true
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
resource "google_compute_network" "net" {
provider = google-beta
name = "{{index $.Vars "network_name"}}"
auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "subnet" {
provider = google-beta
name = "{{index $.Vars "subnet_name"}}"
network = google_compute_network.net.id
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
}

resource "google_compute_router" "router" {
provider = google-beta
name = "{{index $.Vars "router_name"}}"
region = google_compute_subnetwork.subnet.region
network = google_compute_network.net.id
}

resource "google_compute_router_route_policy" "{{$.PrimaryResourceId}}" {
provider = google-beta
router = google_compute_router.router.name
region = google_compute_router.router.region
name = "{{index $.Vars "route_policy_name"}}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
resource "google_compute_network" "net" {
provider = google-beta
name = "{{index $.Vars "network_name"}}"
auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "subnet" {
provider = google-beta
name = "{{index $.Vars "subnet_name"}}"
network = google_compute_network.net.id
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
}

resource "google_compute_router" "router" {
provider = google-beta
name = "{{index $.Vars "router_name"}}"
region = google_compute_subnetwork.subnet.region
network = google_compute_network.net.id
}

resource "google_compute_router_route_policy" "{{$.PrimaryResourceId}}" {
provider = google-beta
name = "{{index $.Vars "route_policy_name"}}"
name = "{{index $.Vars "route_policy_name"}}"
router = google_compute_router.router.name
region = google_compute_router.router.region
type = "ROUTE_POLICY_TYPE_IMPORT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,11 @@ assigns unused addresses from the 2600:2d00:0:2::/64 or 2600:2d00:0:3::/64 range
ValidateFunc: verify.ValidateIpAddress,
Description: `IPv4 address of the BGP interface outside Google Cloud Platform.`,
},
{{- if ne $.TargetVersionName "ga" }}
"export_policies": {
Type: schema.TypeList,
Optional: true,
Description: `routers.list of export policies applied to this peer, in the order they must be evaluated.
The name must correspond to an existing policy that has ROUTE_POLICY_TYPE_EXPORT type.

Note that Route Policies are currently available in preview.
Please use Beta API to use Route Policies.`,
The name must correspond to an existing policy that has ROUTE_POLICY_TYPE_EXPORT type.`,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Expand All @@ -323,15 +319,11 @@ Please use Beta API to use Route Policies.`,
Type: schema.TypeList,
Optional: true,
Description: `routers.list of import policies applied to this peer, in the order they must be evaluated.
The name must correspond to an existing policy that has ROUTE_POLICY_TYPE_IMPORT type.

Note that Route Policies are currently available in preview.
Please use Beta API to use Route Policies.`,
The name must correspond to an existing policy that has ROUTE_POLICY_TYPE_IMPORT type.`,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
{{- end }}
"region": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -538,7 +530,6 @@ func resourceComputeRouterBgpPeerCreate(d *schema.ResourceData, meta interface{}
} else if v, ok := d.GetOkExists("peer_ipv6_nexthop_address"); !tpgresource.IsEmptyValue(reflect.ValueOf(peerIpv4NexthopAddressProp)) && (ok || !reflect.DeepEqual(v, peerIpv4NexthopAddressProp)) {
obj["peerIpv4NexthopAddress"] = peerIpv4NexthopAddressProp
}
{{- if ne $.TargetVersionName "ga" }}
exportPoliciesProp, err := expandNestedComputeRouterBgpPeerExportPolicies(d.Get("export_policies"), d, config)
if err != nil {
return err
Expand All @@ -551,7 +542,6 @@ func resourceComputeRouterBgpPeerCreate(d *schema.ResourceData, meta interface{}
} else if v, ok := d.GetOkExists("import_policies"); ok || !reflect.DeepEqual(v, importPoliciesProp) {
obj["importPolicies"] = importPoliciesProp
}
{{- end }}
ipv6NexthopAddressProp, err := expandNestedComputeRouterBgpPeerIpv6NexthopAddress(d.Get("ipv6_nexthop_address"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -758,14 +748,12 @@ func resourceComputeRouterBgpPeerRead(d *schema.ResourceData, meta interface{})
if err := d.Set("peer_ipv4_nexthop_address", flattenNestedComputeRouterBgpPeerPeerIpv4NexthopAddress(res["peerIpv4NexthopAddress"], d, config)); err != nil {
return fmt.Errorf("Error reading RouterBgpPeer: %s", err)
}
{{- if ne $.TargetVersionName "ga" }}
if err := d.Set("export_policies", flattenNestedComputeRouterBgpPeerExportPolicies(res["exportPolicies"], d, config)); err != nil {
return fmt.Errorf("Error reading RouterBgpPeer: %s", err)
}
if err := d.Set("import_policies", flattenNestedComputeRouterBgpPeerImportPolicies(res["importPolicies"], d, config)); err != nil {
return fmt.Errorf("Error reading RouterBgpPeer: %s", err)
}
{{- end }}
if err := d.Set("ipv6_nexthop_address", flattenNestedComputeRouterBgpPeerIpv6NexthopAddress(res["ipv6NexthopAddress"], d, config)); err != nil {
return fmt.Errorf("Error reading RouterBgpPeer: %s", err)
}
Expand Down Expand Up @@ -915,7 +903,6 @@ func resourceComputeRouterBgpPeerUpdate(d *schema.ResourceData, meta interface{}
} else if v, ok := d.GetOkExists("peer_ipv4_nexthop_address"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, peerIpv4NexthopAddressProp)) {
obj["peerIpv4NexthopAddress"] = peerIpv4NexthopAddressProp
}
{{- if ne $.TargetVersionName "ga" }}
exportPoliciesProp, err := expandNestedComputeRouterBgpPeerExportPolicies(d.Get("export_policies"), d, config)
if err != nil {
return err
Expand All @@ -928,7 +915,6 @@ func resourceComputeRouterBgpPeerUpdate(d *schema.ResourceData, meta interface{}
} else if v, ok := d.GetOkExists("import_policies"); ok || !reflect.DeepEqual(v, importPoliciesProp) {
obj["importPolicies"] = importPoliciesProp
}
{{- end }}
ipv6NexthopAddressProp, err := expandNestedComputeRouterBgpPeerIpv6NexthopAddress(d.Get("ipv6_nexthop_address"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -1353,15 +1339,13 @@ func flattenNestedComputeRouterBgpPeerPeerIpv4NexthopAddress(v interface{}, d *s
return v
}

{{- if ne $.TargetVersionName `ga` }}
func flattenNestedComputeRouterBgpPeerExportPolicies(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenNestedComputeRouterBgpPeerImportPolicies(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
{{- end }}

func flattenNestedComputeRouterBgpPeerIpv6NexthopAddress(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
Expand Down Expand Up @@ -1592,15 +1576,13 @@ func expandNestedComputeRouterBgpPeerPeerIpv4NexthopAddress(v interface{}, d tpg
return v, nil
}

{{- if ne $.TargetVersionName `ga` }}
func expandNestedComputeRouterBgpPeerExportPolicies(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandNestedComputeRouterBgpPeerImportPolicies(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
{{- end }}

func expandNestedComputeRouterBgpPeerIpv6NexthopAddress(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
Expand Down
Loading

0 comments on commit 5a80ffe

Please sign in to comment.