# Copyright 2019 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.

timeout: 7200s
steps:
- id: swap-module-refs
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['module-swapper']
- id: prepare
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'source /usr/local/bin/task_helper_functions.sh && prepare_environment && sleep 120']
  env:
  - 'TF_VAR_org_id=$_ORG_ID'
  - 'TF_VAR_folder_id=$_FOLDER_ID'
  - 'TF_VAR_billing_account=$_BILLING_ACCOUNT'

- id: init-all
  waitFor:
    - prepare
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run all --stage init --verbose']

- id: global-backend-security-policy-complete-apply
  waitFor:
    - init-all
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGlobalSecurityPolicyComplete --stage apply --verbose']
- id: global-backend-security-policy-complete-verify
  waitFor:
    - global-backend-security-policy-complete-apply
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGlobalSecurityPolicyComplete --stage verify --verbose']
- id: global-backend-security-policy-complete-teardown
  waitFor:
    - global-backend-security-policy-complete-verify
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGlobalSecurityPolicyComplete --stage teardown --verbose']

- id: global-backend-security-policy-example-apply
  waitFor:
    - global-backend-security-policy-complete-teardown
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGlobalSecurityPolicyExample --stage apply --verbose']
- id: global-backend-security-policy-example-verify
  waitFor:
    - global-backend-security-policy-example-apply
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGlobalSecurityPolicyExample --stage verify --verbose']
- id: global-backend-security-policy-example-teardown
  waitFor:
    - global-backend-security-policy-example-verify
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGlobalSecurityPolicyExample --stage teardown --verbose']

- id: global-edge-security-policy-apply
  waitFor:
    - global-backend-security-policy-example-teardown
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGlobalSecurityPolicyEdge --stage apply --verbose']
- id: global-edge-security-policy-verify
  waitFor:
    - global-edge-security-policy-apply
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGlobalSecurityPolicyEdge --stage verify --verbose']
- id: global-edge-security-policy-teardown
  waitFor:
    - global-edge-security-policy-verify
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGlobalSecurityPolicyEdge --stage teardown --verbose']

- id: global-backend-security-policy-recaptcha-apply
  waitFor:
    - global-backend-security-policy-example-teardown
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGlobalSecurityPolicyRecaptcha --stage apply --verbose']
- id: global-backend-security-policy-recaptcha-verify
  waitFor:
    - global-backend-security-policy-recaptcha-apply
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGlobalSecurityPolicyRecaptcha --stage verify --verbose']
- id: global-backend-security-policy-recaptcha-teardown
  waitFor:
    - global-backend-security-policy-recaptcha-verify
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGlobalSecurityPolicyRecaptcha --stage teardown --verbose']
- id: global-backend-security-policy-enterprise-apply
  waitFor:
    - global-backend-security-policy-example-teardown
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGlobalSecurityPolicyEnterprise --stage apply --verbose']
- id: global-backend-security-policy-enterprise-verify
  waitFor:
    - global-backend-security-policy-enterprise-apply
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGlobalSecurityPolicyEnterprise --stage verify --verbose']
- id: global-backend-security-policy-enterprise-teardown
  waitFor:
    - global-backend-security-policy-enterprise-verify
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGlobalSecurityPolicyEnterprise --stage teardown --verbose']
- id: regional-adv-ddos-and-edge-security-policy-complete-apply
  waitFor:
    - global-backend-security-policy-example-teardown
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestRegionalNetworkEdgePolicy --stage apply --verbose']
- id: regional-adv-ddos-and-edge-security-policy-complete-verify
  waitFor:
    - regional-adv-ddos-and-edge-security-policy-complete-apply
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestRegionalNetworkEdgePolicy --stage verify --verbose']
- id: regional-adv-ddos-and-edge-security-policy-complete-teardown
  waitFor:
    - regional-adv-ddos-and-edge-security-policy-complete-verify
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestRegionalNetworkEdgePolicy --stage teardown --verbose']
- id: regional-backend-security-policy-example-apply
  waitFor:
    - global-backend-security-policy-example-teardown
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestRegionalBackendPolicy --stage apply --verbose']
- id: regional-backend-security-policy-example-verify
  waitFor:
    - regional-backend-security-policy-example-apply
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestRegionalBackendPolicy --stage verify --verbose']
- id: regional-backend-security-policy-example-teardown
  waitFor:
    - regional-backend-security-policy-example-verify
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestRegionalBackendPolicy --stage teardown --verbose']

tags:
- 'ci'
- 'integration'
substitutions:
  _DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
  _DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '1.23'
