google-github-actions / deploy-cloud-functions

A GitHub Action that deploys source code to Google Cloud Functions.

Home Page:https://cloud.google.com/functions

Repository from Github https://github.comgoogle-github-actions/deploy-cloud-functionsRepository from Github https://github.comgoogle-github-actions/deploy-cloud-functions

Can't update existing function

selfagency opened this issue · comments

TL;DR

It says in the directions:

This GitHub Action is declarative, meaning it will overwrite any values on an existing Cloud Function deployment. If you manually deployed a Cloud Function, you must specify all parameters in this action.

I take this to mean I can deploy to an existing function. However, I get an error when attempting to do so:

Failed to create function, function csp-reports already exists under Gen 2 environment. Please delete conflicting function first or deploy the function with a different name.

Expected behavior

To be able to overwrite an existing function

Observed behavior

Being forced to delete the existing function

Action YAML

name: Deploy CSP Reports cloud function
on:
  workflow_dispatch:
    inputs:
      environment:
        description: The environment to deploy to
        type: choice
        options:
          - staging
          - production
        default: staging
  push:
    branches:
      - main
      - staging
    paths:
      - './cloud_functions/csp_reports/*'
concurrency:
  group: deploy-csp
  cancel-in-progress: true
jobs:
  deploy-csp-reports:
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: read
    steps:
      - name: Checkout repo
        uses: actions/checkout@v2

      - name: Authenticate to GCP Staging
        id: auth-staging
        uses: 'google-github-actions/auth@v0.7.0'
        if: ${{ github.event.inputs.environment == 'staging' || endsWith(github.event.push.base_ref, 'staging') }}
        with:
          workload_identity_provider: ${{ secrets.WORKLOAD_ID_PROVIDER_STAGING }}
          service_account: ${{ secrets.SERVICE_ACCOUNT_STAGING }}

      - name: Authenticate to GCP Production
        id: auth-production
        uses: 'google-github-actions/auth@v0.7.0'
        if: ${{ github.event.inputs.environment == 'production' || endsWith(github.event.push.base_ref, 'main') }}
        with:
          workload_identity_provider: ${{ secrets.WORKLOAD_ID_PROVIDER_PRODUCTION }}
          service_account: ${{ secrets.SERVICE_ACCOUNT_PRODUCTION }}

      - name: Deploy CSP Reports cloud function
        id: 'deploy'
        uses: 'google-github-actions/deploy-cloud-functions@v0.9.0'
        with:
          name: 'csp-reports'
          runtime: 'nodejs16'
          source_dir: 'cloud_functions/csp_reports'
          memory_mb: 128
          env_vars: BUGSNAG_API_KEY=${{secrets.CSP_BUGSNAG}},DD_API_KEY=${{secrets.CSP_DATADOG}}
          ingress_settings: 'Allow all traffic'
          service_account_email: ${{ secrets.CSP_SVC_ACCT }}

Log output

google-github-actions/deploy-cloud-functions failed with: failed to POST https://cloudfunctions.googleapis.com/v1/projects/unstoppable-domains-staging/locations/us-central1/functions: unuccessful HTTP response: 400, body: {
  "error": {
    "code": 400,
    "message": "Failed to create function, function csp-reports already exists under Gen 2 environment. Please delete conflicting function first or deploy the function with a different name.",
    "status": "FAILED_PRECONDITION"
  }
}

Additional information

No response

Hi @selfagency

Did you create this function outside of GitHub Actions? It looks like this is a gen2 Cloud Function, and we do not currently support gen2 (#304). Cloud Functions gen2 is an entirely different API and set of fields.

Ah well that explains it then.