Spacelift
PrivacyT&Cs
  • 👋Hello, Spacelift!
  • 🚀Getting Started
  • 🌠Main concepts
    • Stack
      • Creating a stack
      • Stack settings
      • Organizing stacks
      • Stack locking
      • Drift detection
    • Configuration
      • Environment
      • Context
      • Runtime configuration
        • YAML reference
    • Run
      • Task
      • Proposed run (preview)
      • Tracked run (deployment)
      • Module test case
      • User-Provided Metadata
      • Run Promotion
      • Pull Request Comments
    • Policy
      • Login policy
      • Access policy
      • Approval policy
      • Initialization policy
      • Plan policy
      • Push policy
      • Task policy
      • Trigger policy
    • Resources
    • Worker pools
    • VCS Agent Pools
  • 🛰️Platforms
    • Terraform
      • Module registry
      • External modules
      • Provider
      • State management
      • Terragrunt
      • Version management
      • Handling .tfvars
      • CLI Configuration
      • Cost Estimation
      • Resource Sanitization
      • Storing Complex Variables
      • Debugging Guide
    • Pulumi
      • Getting started
        • C#
        • Go
        • JavaScript
        • Python
      • State management
      • Version management
    • CloudFormation
      • Getting Started
      • Reference
      • Integrating with SAM
      • Integrating with the serverless framework
    • Kubernetes
      • Getting Started
      • Authenticating
      • Custom Resources
      • Helm
      • Kustomize
  • ⚙️Integrations
    • Audit trail
    • Cloud Integrations
      • Amazon Web Services (AWS)
      • Microsoft Azure
      • Google Cloud Platform (GCP)
    • Source Control
      • GitHub
      • GitLab
      • Azure DevOps
      • Bitbucket Cloud
      • Bitbucket Datacenter/Server
    • Docker
    • GraphQL API
    • Single sign-on
      • GitLab OIDC Setup Guide
      • Okta OIDC Setup Guide
      • OneLogin OIDC Setup Guide
      • Azure AD OIDC Setup Guide
      • AWS IAM Identity SAML 2.0 Setup Guide
    • Slack
    • Webhooks
  • 📖Product
    • Privacy
    • Security
    • Support
      • Statement of Support
    • Disaster Continuity
    • Billing
      • Stripe
      • AWS Marketplace
    • Terms and conditions
    • Refund Policy
  • Cookie Policy
Powered by GitBook
On this page
  • About the integration
  • Setting up in Spacelift
  • Using Terraform
  • Setting up access in GCP

Was this helpful?

  1. Integrations
  2. Cloud Integrations

Google Cloud Platform (GCP)

PreviousMicrosoft AzureNextSource Control

Last updated 2 years ago

Was this helpful?

About the integration

Spacelift GCP integration allows Spacelift to manage your Google Cloud resources without the need for long-lived static credentials. In order to achieve that Spacelift create a inside our project dedicated for your Stack. We show you the globally unique email of this service account, which you can add to your GCP organizations and/or projects with the right level of access.

With the service account already created, we generate temporary OAuth token for this service account and put it as a GOOGLE_OAUTH_ACCESS_TOKEN variable in the environment of your and . This is for the Google Terraform provider, so you can define it like this:

provider "google" {}

Note that a lot of GCP resources require identifier too, so if you don't specify a default in your provider, you will need to pass it to each individual resource that requires it.

You can customize the list of that the token is granted when it's generated. When you're setting up your GCP integration through the web UI, we suggest the following list of scopes:

  • https://www.googleapis.com/auth/compute

  • https://www.googleapis.com/auth/cloud-platform

  • https://www.googleapis.com/auth/ndev.clouddns.readwrite

  • https://www.googleapis.com/auth/devstorage.full_control

  • https://www.googleapis.com/auth/userinfo.email

This list is consistent with the .

Setting up in Spacelift

If you're setting up the integration through the web UI, please go to the Integrations tab in the stack management view and choose Google Cloud Platform from the list of available integrations:

Using Terraform

If you're using Spacelift Terraform provider to create the integration programmatically, you can do the following:

resource "spacelift_gcp_service_account" "gcp-integration" {
  stack_id = spacelift_stack.your-stack.id

  token_scopes = [
    "https://www.googleapis.com/auth/compute",
    "https://www.googleapis.com/auth/cloud-platform",
    "https://www.googleapis.com/auth/ndev.clouddns.readwrite",
    "https://www.googleapis.com/auth/devstorage.full_control",
    "https://www.googleapis.com/auth/userinfo.email",
  ]
}

If the service account linked to your administrative stack has sufficient privileges on the GCP organization, you can even programmatically create a dedicated GCP project and set up the integration from the Google side of things:

resource "google_project" "k8s-core" {
  name       = "Kubernetes core"
  project_id = "unicorn-k8s-core"
  org_id     = var.gcp_organization_id
}

resource "google_project_iam_member" "k8s-core" {
  project = google_project.k8s-core.id
  role    = "roles/owner"
  member  = "serviceAccount:${spacelift_stack_gcp_service_account.gcp-integration.service_account_email}"
}

Setting up access in GCP

In the above example, we made the service account an owner of the organization, giving it full access to all resources. Depending on your use case, this may or may not be what you want.

We can do the same on the project level, too. In fact, the process looks absolutely identical except that projects are represented by a different icon in the dropdown. Go figure:

It can take up to a minute for the membership data to propagate but once it does, your Spacelift-GCP integration should Just Work™.

Once there, you'll be presented with a form allowing you to customize the list of OAuth scopes for the temporary token we'll generate for each and :

Once you click Save, the account is generated for you and we display its globally unique email. You'll need this email when .

In order to make the integration work, you'll have to make the dedicated service account a member of your organization and/or project, with an appropriate level of access. This is done in the view of GCP's web UI. First, let's show an example of adding a service account as a member on the organization level:

⚙️
Run
Task
setting up access on the GCP end
IAM & Admin
service account
Runs
Tasks
one of the configuration options
project
OAuth scopes
defaults requested by the Terraform provider