# Copyright 2022 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
#
#      http://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.

apiVersion: blueprints.cloud.google.com/v1alpha1
kind: BlueprintMetadata
metadata:
  name: terraform-google-cloud-workflow
  annotations:
    config.kubernetes.io/local-config: "true"
spec:
  title: terraform-google-cloud-workflow
  source:
    repo: https://github.com/anaik91/terraform-google-cloud-workflow.git
    sourceType: git
  version: 0.1.0
  actuationTool:
    type: Terraform
    version: '>= 1.3'
  examples:
  - name: gcs_event_arc_trigger_workflow
    location: examples/gcs_event_arc_trigger_workflow
  - name: pubsub_event_arc_trigger_workflow
    location: examples/pubsub_event_arc_trigger_workflow
  - name: schedule_workflow
    location: examples/schedule_workflow
  - name: schedule_workflow_autocreate_sa
    location: examples/schedule_workflow_autocreate_sa
  - name: schedule_workflow_with_arguments
    location: examples/schedule_workflow_with_arguments
  variables:
  - name: project_id
    description: The project ID to deploy to
    type: string
    required: true
  - name: region
    description: The name of the region where workflow will be created
    type: string
    required: true
  - name: service_account_create
    description: Auto-create service account.
    type: bool
    default: false
    required: false
  - name: service_account_email
    description: Service account email. Unused if service account is auto-created.
    type: string
    required: false
  - name: workflow_description
    description: Description for the cloud workflow
    type: string
    default: Sample workflow Description
    required: false
  - name: workflow_labels
    description: A set of key/value label pairs to assign to the workflow
    type: map(string)
    default: {}
    required: false
  - name: workflow_name
    description: The name of the cloud workflow to create
    type: string
    required: true
  - name: workflow_source
    description: Workflow YAML code to be executed. The size limit is 32KB.
    type: string
    required: true
  - name: workflow_trigger
    description: Trigger for the Workflow . Cloud Scheduler OR Event Arc
    type: |-
      object({
          cloud_scheduler = optional(object({
            name                  = string
            cron                  = string
            time_zone             = string
            deadline              = string
            argument              = optional(string)
            service_account_email = string
          }))
          event_arc = optional(object({
            name                  = string
            service_account_email = string
            matching_criteria = set(object({
              attribute = string
              operator  = optional(string)
              value     = string
            }))
            pubsub_topic_id = optional(string)
          }))
        })
    required: true
  outputs:
  - name: event_arc_id
    description: Google Event Arc id
  - name: scheduler_job_id
    description: Google Cloud scheduler job id
  - name: workflow_id
    description: Workflow identifier for the resource with format projects/{{project}}/locations/{{region}}/workflows/{{name}}
  - name: workflow_region
    description: The region of the workflow.
  - name: workflow_revision_id
    description: The revision of the workflow. A new one is generated if the service account or source contents is changed.
  roles:
  - level: Project
    roles:
    - roles/owner
  services:
  - iam.googleapis.com
  - cloudresourcemanager.googleapis.com
  - storage-api.googleapis.com
  - serviceusage.googleapis.com
  - workflows.googleapis.com
  - cloudscheduler.googleapis.com
  - eventarc.googleapis.com
  - pubsub.googleapis.com
  - logging.googleapis.com
  - storage.googleapis.com
