---
title: Deploy on Google Cloud Engine
description: "Installing Agenta on GCP Compute Engine using terraform"
---

import Image from "@theme/IdealImage";

:::tip
This guide is for provisioning and deploying agenta on GCP Compute Engine **using Terraform**. If you prefer to provision the instance manually, you can use the [guide for deploying on a remote machine](/self-host/deploy_remotly/host-remotely).
:::

## GCP

We provide a Terraform module to deploy Agenta on GCP. You can find it [here](https://github.com/Agenta-AI/agenta/tree/main/self-host/gcp).
The terraform module will in the in us-central1 region create;

- An e2-medium Compute instance
- VPC Network
- Firewall configured to allow ports 22 (ssh), 80 (http), and 443 (https)

You can customize the module according to your needs.

### Prerequisites

1. **Install Terraform**: First, install [Terraform](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli).

:::tip
Step 2 until 6 can be skipped if you already have a project with billing enabled and a service account with the compute admin role.
:::

2. **Setup Project**; In the [Google cloud Console](https://console.cloud.google.com), on the project selector page, select or [create a Google Cloud project](https://cloud.google.com/resource-manager/docs/creating-managing-projects), then copy and save the Project ID for later.
3. **Confirm Billing**; [Make sure that billing is enabled for your Google Cloud project.](https://cloud.google.com/billing/docs/how-to/verify-billing-enabled#console)
4. **Create a Service account**; Click [here to Create a Service account](https://cloud.google.com/iam/docs/service-accounts-create) and specify the compute admin role.

   <Image img={require("/images/agenta_service_account.png")} height="600" />

5. **Get Service account key**; Click [here to obtain the keys for the service account](https://console.cloud.google.com/iam-admin/serviceaccounts?walkthrough_id=iam--create-service-account-keys&start_index=1#step_index=1) you created.
6. Enable Google Compute Engine API: Navigate to [Compute Engine API](https://console.cloud.google.com/apis/library/compute.googleapis.com) and make sure to select the correct project at the top, then enable Compute Engine API.

7. Copy the content of the downloaded key file and replace the content of [credentials.json](https://github.com/Agenta-AI/agenta/blob/main/self-host/gcp/credentials.json) with it.
8. **Initialize and Apply Terraform**: Navigate to the correct directory and run:
   ```bash
   cd self-host/gcp
   terraform init
   terraform apply
   ```

#### SSH into the instance:

In order to ssh into the instance you need to:

1. Uncomment these lines in the [Terraform instance file](https://github.com/Agenta-AI/agenta/blob/main/self-host/gcp/agenta-instance.tf)

```bash
metadata = {
 ssh-keys = "YOUR_USERNAME:${file("~/.ssh/id_rsa.pub")}"
}
```

2. [Create an SSH key pair.](https://cloud.google.com/compute/docs/connect/create-ssh-keys)

3. [Add the SSH Key to the VM Metadata](https://cloud.google.com/compute/docs/connect/add-ssh-keys)

4. Rerun
   ```bash
   terraform apply.
   ```

Remember that while allowing SSH access from any source (0.0.0.0/0) is convenient for testing, it's not recommended for production environments due to security concerns. In production, you would restrict SSH access to specific trusted IP addresses.

#### Removing All Resources:

To delete all the resources created by Terraform, simply run

```bash
cd self-host/gcp
terraform destroy
```
