# 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_folder_id=$_FOLDER_ID'
  - 'TF_VAR_billing_account=$_BILLING_ACCOUNT'
  - 'TF_VAR_build_project_number=$PROJECT_NUMBER'

- id: create-standalone
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', './test/prepare-providers.sh && sleep 90  && cft test run TestStandalone --stage init --verbose']

- id: converge-standalone
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', './test/setup/tinkey-mock/prepare.sh && cft test run TestStandalone --stage apply --verbose']

- id: verify-standalone
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestStandalone --stage verify --verbose']

- id: destroy-standalone
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestStandalone --stage teardown --verbose']

tags:
- 'ci'
- 'integration'

substitutions:
  _DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools'
  _DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '1'

options:
  env:
  - 'TF_VAR_org_id=$_ORG_ID'

