# Copyright 2021 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: 12600s
steps:
- 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: create anthos_attached_cluster_kind
  waitFor:
    - prepare
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestAACKind --stage create --verbose --test-dir test/integration']
- id: apply anthos_attached_cluster_kind
  waitFor:
    - create anthos_attached_cluster_kind
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestAACKind --stage apply --verbose --test-dir test/integration']
- id: verify anthos_attached_cluster_kind
  waitFor:
    - apply anthos_attached_cluster_kind
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestAACKind --stage verify --verbose --test-dir test/integration']
- id: destroy anthos_attached_cluster_kind
  waitFor:
    - verify anthos_attached_cluster_kind
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cft test run TestAACKind --stage destroy --verbose --test-dir test/integration']
- id: create abm-gce-defaults-on-editor-project-local
  waitFor:
    - destroy anthos_attached_cluster_kind
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cd test/integration && RUN_STAGE=init go test -v -run TestABMEditor ./... -p 1']
- id: converge abm-gce-defaults-on-editor-project-local
  waitFor:
    - create abm-gce-defaults-on-editor-project-local
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cd test/integration && RUN_STAGE=apply go test -v -run TestABMEditor ./... -p 1']
- id: verify abm-gce-defaults-on-editor-project-local
  waitFor:
    - converge abm-gce-defaults-on-editor-project-local
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cd test/integration && sleep 60 &&  RUN_STAGE=verify go test -v -run TestABMEditor ./... -p 1 -timeout 60m']
- id: destroy abm-gce-defaults-on-editor-project-local
  waitFor:
    - verify abm-gce-defaults-on-editor-project-local
  name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
  args: ['/bin/bash', '-c', 'cd test/integration && RUN_STAGE=teardown go test -v -run TestABMEditor ./... -p 1']
- id: create abm-gce-gpu
  waitFor:
    - destroy abm-gce-defaults-on-editor-project-local
  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 && kitchen_do create abm-gce-gpu']
- id: converge abm-gce-gpu
  waitFor:
    - create abm-gce-gpu
  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 && kitchen_do converge abm-gce-gpu']
- id: verify abm-gce-gpu
  waitFor:
    - converge abm-gce-gpu
  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 && kitchen_do verify abm-gce-gpu']
- id: destroy abm-gce-gpu
  waitFor:
    - verify abm-gce-gpu
  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 && kitchen_do destroy abm-gce-gpu']
tags:
- 'ci'
- 'integration'
substitutions:
  _DOCKER_IMAGE_DEVELOPER_TOOLS: 'cft/developer-tools-krm'
  _DOCKER_TAG_VERSION_DEVELOPER_TOOLS: '1.23.7'
options:
  machineType: 'N1_HIGHCPU_8'
