# 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: 10800s
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']
  env:
  - 'TF_VAR_org_id=$_ORG_ID'
  - 'TF_VAR_folder_id=$_FOLDER_ID'
  - 'TF_VAR_billing_account=$_BILLING_ACCOUNT'

- id: cloud-func-init
  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']
  env:
  - 'TF_VAR_org_id=$_ORG_ID'
  - 'TF_VAR_billing_account=$_BILLING_ACCOUNT'
  waitFor:
  - prepare

- id: cloud-func-gcs-source-apply
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGCF2GCSSource --stage apply --verbose']
  waitFor:
  - cloud-func-init
- id: cloud-func-gcs-source-verify
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGCF2GCSSource --stage verify --verbose']
  waitFor:
  - cloud-func-gcs-source-apply
- id: cloud-func-gcs-source-teardown
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGCF2GCSSource --stage teardown --verbose']
  env:
  - 'TF_VAR_org_id=$_ORG_ID'
  - 'TF_VAR_billing_account=$_BILLING_ACCOUNT'
  waitFor:
  - cloud-func-gcs-source-verify

- id: secure-cloud-func-sql-apply
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', './test/install_build_dependencies.sh && cft test run TestGCF2CloudSQL --stage apply --verbose']
  env:
  - 'TF_VAR_org_id=$_ORG_ID'
  - 'TF_VAR_billing_account=$_BILLING_ACCOUNT'
  waitFor:
  - cloud-func-init
- id: secure-cloud-func-sql-verify
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGCF2CloudSQL --stage verify --verbose']
  env:
  - 'TF_VAR_org_id=$_ORG_ID'
  - 'TF_VAR_billing_account=$_BILLING_ACCOUNT'
  waitFor:
  - secure-cloud-func-sql-apply
- id: secure-cloud-func-sql-teardown
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGCF2CloudSQL --stage teardown --verbose']
  env:
  - 'TF_VAR_org_id=$_ORG_ID'
  - 'TF_VAR_billing_account=$_BILLING_ACCOUNT'
  waitFor:
  - secure-cloud-func-sql-verify

- id: secure-cloud-func-internal-server-apply
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', './test/install_build_dependencies.sh && cft test run TestCFInternalServer --stage apply --verbose']
  env:
  - 'TF_VAR_org_id=$_ORG_ID'
  - 'TF_VAR_billing_account=$_BILLING_ACCOUNT'
  waitFor:
  - cloud-func-init
- id: secure-cloud-func-internal-server-verify
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestCFInternalServer --stage verify --verbose']
  env:
  - 'TF_VAR_org_id=$_ORG_ID'
  - 'TF_VAR_billing_account=$_BILLING_ACCOUNT'
  waitFor:
  - secure-cloud-func-internal-server-apply
- id: secure-cloud-func-internal-server-teardown
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestCFInternalServer --stage teardown --verbose']
  env:
  - 'TF_VAR_org_id=$_ORG_ID'
  - 'TF_VAR_billing_account=$_BILLING_ACCOUNT'
  waitFor:
  - secure-cloud-func-internal-server-verify

- id: cloud-func-pubsub-trigger-apply
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGCF2PubSubTrigger --stage apply --verbose']
  waitFor:
  - cloud-func-init
- id: cloud-func-pubsub-trigger-verify
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGCF2PubSubTrigger --stage verify --verbose']
  waitFor:
  - cloud-func-pubsub-trigger-apply
- id: cloud-func-pubsub-trigger-teardown
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGCF2PubSubTrigger --stage teardown --verbose']
  env:
  - 'TF_VAR_org_id=$_ORG_ID'
  - 'TF_VAR_billing_account=$_BILLING_ACCOUNT'
  waitFor:
  - cloud-func-pubsub-trigger-verify

- id: secure-cloud-func-bigquery-apply
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', './test/install_build_dependencies.sh && cft test run TestGCF2BigqueryTrigger --stage apply --verbose']
  env:
  - 'TF_VAR_org_id=$_ORG_ID'
  - 'TF_VAR_billing_account=$_BILLING_ACCOUNT'
  waitFor:
  - cloud-func-init
- id: secure-cloud-func-bigquery-verify
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGCF2BigqueryTrigger --stage verify --verbose']
  env:
  - 'TF_VAR_org_id=$_ORG_ID'
  - 'TF_VAR_billing_account=$_BILLING_ACCOUNT'
  waitFor:
  - secure-cloud-func-bigquery-apply
- id: secure-cloud-func-bigquery-teardown
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestGCF2BigqueryTrigger --stage teardown --verbose']
  env:
  - 'TF_VAR_org_id=$_ORG_ID'
  - 'TF_VAR_billing_account=$_BILLING_ACCOUNT'
  waitFor:
  - secure-cloud-func-bigquery-verify
tags:
  - "ci"
  - "integration"
substitutions:
  _DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
  _DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '1.19'
options:
  machineType: 'N1_HIGHCPU_8'
