# Copyright 2024 Google LLC
#
# 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
#
#    https://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: nested_rule
rule:
  variables:
    - name: "permitted_regions"
      expression: "['us', 'uk', 'es']"
  match:
    - rule:
        id: "banned regions"
        description: >
          determine whether the resource origin is in the banned
          list. If the region is also in the permitted list, the
          ban has no effect.
        variables:
          - name: "banned_regions"
            expression: "{'us': false, 'ru': false, 'ir': false}"
        match:
          - condition: |
              resource.origin in variables.banned_regions &&
              !(resource.origin in variables.permitted_regions)
            output: "{'banned': true}"
            explanation: "'resource is in the banned region ' + resource.origin"
    - condition: resource.origin in variables.permitted_regions
      output: "{'banned': false}"
    - output: "{'banned': true}"
