Creating a Service Connection on Azure DevOps to Authenticate Google Cloud

Introduction

Integrating Google Cloud with Azure DevOps allows you to leverage the powerful CI/CD capabilities of Azure DevOps while managing your infrastructure and applications on Google Cloud Platform (GCP). To enable this integration, you need to create a service connection in Azure DevOps that authenticates with GCP. This blog post will guide you through the steps to set up this service connection.

Prerequisites

  • Azure DevOps Account: Ensure you have an active Azure DevOps organization and project.
  • Google Cloud Platform (GCP) Account: Ensure you have an active GCP account.
  • Service Account in GCP: Create a service account in GCP with the necessary permissions.

Step-by-Step Guide

1. Create a Service Account in GCP

  • Go to the Google Cloud Console.
  • Navigate to IAM & Admin > Service Accounts.
  • Click Create Service Account.
  • Provide a name and description for the service account.
  • Click Create and Continue.
  • Assign the necessary roles (e.g., Editor, Kubernetes Engine Admin).
  • Click Done.

2. Generate a JSON Key for the Service Account

  • In the Service Accounts page, find the service account you created.
  • Click the Actions menu (three dots) and select Manage keys.
  • Click Add Key > Create New Key.
  • Select JSON and click Create.
  • A JSON file containing the service account key will be downloaded. Keep this file secure.

3. Create a Service Connection in Azure DevOps

  • Go to your Azure DevOps project.
  • Navigate to Project Settings > Service connections.
  • Click New service connection.
  • Select Google Cloud from the list of service connection types.
  • Click Next.

4. Configure the Service Connection

  • In the New Google Cloud service connection window, provide the following details:
    • Connection name: A name for your service connection.
    • Project ID: The GCP project ID.
    • Authentication method: Select Service account key.
    • Service account key: Upload the JSON key file you downloaded earlier.
  • Click Verify and save to test the connection and save it.

5. Use the Service Connection in Pipelines

  • In your Azure DevOps pipeline YAML file, reference the service connection to authenticate with GCP.
  • Example:
pool:
  vmImage: 'ubuntu-latest'

steps:
- task: gcloud@0
  inputs:
    gcpServiceConnection: '<Your Service Connection>'
    scriptType: 'bash'
    scriptLocation: 'inlineScript'
    inlineScript: |
      gcloud auth activate-service-account --key-file=$(GCP_SERVICE_ACCOUNT_KEY)
      gcloud config set project $(GCP_PROJECT_ID)
      # Add your GCP commands here

Conclusion

By following these steps, you can create a service connection in Azure DevOps to authenticate with Google Cloud. This setup allows you to seamlessly integrate GCP with your Azure DevOps pipelines, enabling efficient CI/CD processes for your applications and infrastructure.

Feel free to reach out if you have any questions or need further assistance! Happy deploying! 

I hope this helps! Let me know if you need any more details or have other questions.

Comments

Popular posts from this blog

How to update build number in Azure DevOps pipeline?

How to get latest build ID from Azure DevOps pipeline?

How to install AWS System Manager (SSM) Agent on windows using PowerShell?