# Copyright 2024 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
name: 'RouterRoutePolicy'
api_resource_type_kind: Router
description: A route policy created in a router
references:
  guides:
    'Google Cloud Router': 'https://cloud.google.com/router/docs/'
  api: 'https://cloud.google.com/compute/docs/reference/rest/v1/routers'
docs:
id_format: '{{project}}/{{region}}/{{router}}/routePolicies/{{name}}'
base_url: 'projects/{{project}}/regions/{{region}}/routers/{{router}}'
self_link: 'projects/{{project}}/regions/{{region}}/routers/{{router}}/getRoutePolicy?policy={{name}}'
create_url: 'projects/{{project}}/regions/{{region}}/routers/{{router}}/updateRoutePolicy'
update_url: 'projects/{{project}}/regions/{{region}}/routers/{{router}}/updateRoutePolicy'
update_verb: 'POST'
update_mask: true
delete_url: 'projects/{{project}}/regions/{{region}}/routers/{{router}}/deleteRoutePolicy?policy={{name}}'
delete_verb: 'POST'
import_format:
  - '{{project}}/{{region}}/{{router}}/routePolicies/{{name}}'
timeouts:
  insert_minutes: 20
  update_minutes: 20
  delete_minutes: 20
async:
  actions: ['create', 'delete', 'update']
  type: 'OpAsync'
  operation:
    base_url: '{{op_id}}'
  result:
    resource_inside_response: false
custom_code:
  decoder: 'templates/terraform/decoders/unwrap_route_policy_resource.go.tmpl'
examples:
  - name: 'router_route_policy_export'
    primary_resource_id: 'rp-export'
    vars:
      router_name: 'my-router'
      network_name: 'my-network'
      subnet_name: 'my-subnetwork'
      route_policy_name: 'my-rp1'
  - name: 'router_route_policy_import'
    primary_resource_id: 'rp-import'
    vars:
      router_name: 'my-router'
      network_name: 'my-network'
      subnet_name: 'my-subnetwork'
      route_policy_name: 'my-rp2'
parameters:
  - name: 'router'
    type: ResourceRef
    description: |
      The name of the Cloud Router in which this route policy will be configured.
    url_param_only: true
    required: true
    immutable: true
    resource: 'Router'
    imports: 'name'
  - name: 'region'
    type: ResourceRef
    description: Region where the router and NAT reside.
    url_param_only: true
    required: false
    immutable: true
    default_from_api: true
    custom_flatten: 'templates/terraform/custom_flatten/name_from_self_link.tmpl'
    resource: 'Region'
    imports: 'name'
  - name: 'name'
    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
    required: true
    immutable: true
properties:
  - name: 'type'
    type: Enum
    description: |
      This is policy's type, which is one of IMPORT or EXPORT
    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).
    required: true
    immutable: true
    item_type:
      type: NestedObject
      properties:
        - name: 'priority'
          type: Integer
          description: |
            The evaluation priority for this term, which must be between 0 (inclusive) and 231 (exclusive), and unique within the list.
          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.
          properties:
            - name: 'expression'
              type: String
              description:
                Textual representation of an expression in Common Expression
                Language syntax.
              required: true
            - name: 'title'
              type: String
              description:
                Title for the expression, i.e. a short string describing its
                purpose.
            - name: 'description'
              type: String
              description: Description of the expression
            - 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
        - name: 'actions'
          type: Array
          description: |
            'CEL expressions to evaluate to modify a route when this term matches.'\
          item_type:
            type: NestedObject
            properties:
              - name: 'expression'
                type: String
                description: |
                  Textual representation of an expression in Common Expression
                  Language syntax.
                required: true
              - name: 'title'
                type: String
                description: |
                  Title for the expression, i.e. a short string describing its
                  purpose.
              - name: 'description'
                type: String
                description: |
                  Description of the expression
              - 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
    custom_expand: 'templates/terraform/custom_expand/expand_route_policy_terms.go.tmpl'
  - name: 'fingerprint'
    type: Fingerprint
    description: |
      The fingerprint used for optimistic locking of this resource.  Used
      internally during updates.
    output: true
