When I try to create a release for a Google Cloud Deploy pipeline with multiple target types, I get the following error:
ERROR: (gcloud.deploy.releases.create) FAILED_PRECONDITION:
[cloud-run] are Cloud Run target(s), [terraform-workspace] are Custom target(s):
failed precondition
I'd like to do this because it's simple to have a single pipeline manage deployment of infrastructure required by the Cloud Run service (one target) and then deployment of the service itself (second target). It's possible to use a pre-deploy hook instead but there are several advantages (and it makes more sense to me) to make it its own target.
I'm curious why Cloud Deploy doesn't support this; is it because it is an inferior way to model such a desire, or is it some technical restriction that may be removed at some point?
clouddeploy.yaml:
apiVersion: deploy.cloud.google.com/v1
kind: DeliveryPipeline
metadata:
name: service-with-infra
description: deploy infra required by the service, then the service itself
serialPipeline:
stages:
- targetId: terraform-workspace
- targetId: cloud-run
---
apiVersion: deploy.cloud.google.com/v1
kind: Target
metadata:
name: cloud-run
run: {location: projects/YOUR_PROJECT_NAME/locations/us-central1}
---
apiVersion: deploy.cloud.google.com/v1
kind: Target
metadata:
name: terraform-workspace
customTarget: {customTargetType: terraform-workspace}
---
apiVersion: deploy.cloud.google.com/v1
kind: CustomTargetType
metadata:
name: terraform-workspace
customActions: {renderAction: terraform-workspace-render, deployAction: terraform-workspace-deploy}
Then run:
gcloud deploy apply --file clouddeploy.yaml --region us-central1 --project YOUR_PROJECT
gcloud deploy releases create release1 --delivery-pipeline service-with-infra --region us-central1 --project YOUR_PROJECT
This last command results in the error:
ERROR: (gcloud.deploy.releases.create) FAILED_PRECONDITION:
[cloud-run] are Cloud Run target(s), [terraform-workspace] are Custom target(s):
failed precondition
Note, I also get similar error if I try to release with a pipeline containing two different custom target types.
Due to the architectural design in Cloud Deploy, a single pipeline is designed to deploy only one type of target. While you can have multiple targets within one pipeline, but they must all be the same type (like GKE, all Cloud Run, etc.).
Currently, Cloud Deploy does not support different target types within a single pipeline because each type has unique configuration and requirements, such as different deployment processes, tooling and API. Combining multiple target types in one pipeline would make it more complex to understand, maintain, and debug, leading to more complicated setups. The recommended approach in Cloud Deploy is to create separate pipelines for each target environment. For further reference you can check this documentation.
You can also make a feature request to Google Cloud for this functionality and you can explain the challenges you’re encountering with the current approach would be helpful.