# Installing a GCP connector on GKE using Terraform

Connectors are secure on-premises components that link Apono to your resources:

* No secrets are read, cached, or stored
* No account admin privileges need to be granted to Apono
* The connector contacts your secret store or key vault to sync data or provision access

Once set up, this connector will enable you to sync data from cloud applications and grant and revoke access permissions through Google Kubernetes Engine (GKE).

***

### Prerequisites

<table><thead><tr><th width="236">Item</th><th>Description</th></tr></thead><tbody><tr><td><strong>Apono Token</strong></td><td><p>Account-specific Apono authentication value<br><br>Use the following steps to obtain your token:</p><ol><li>On the <a href="https://app.apono.io/connectors"><strong>Connectors</strong></a> page, click <strong>Install Connector</strong>. The <strong>Install Connector</strong> page appears.</li><li>Click <strong>Cloud installation</strong>.</li><li>Click <strong>Cloud installation > GCP > Install and Connect GCP Project > CLI (GKE)</strong>.</li><li>Copy the token listed on the page in step <strong>1</strong>.</li></ol></td></tr><tr><td><strong>Google Cloud Command Line Interface (Google Cloud CLI)</strong></td><td><a href="https://cloud.google.com/sdk/gcloud">Command-line interface</a> used to manage Google Cloud resources</td></tr><tr><td><strong>Google Cloud Information</strong></td><td><p>Information for your Google Cloud instance:</p><ul><li>(Organization) <a href="https://cloud.google.com/resource-manager/docs/creating-managing-organization#retrieving_your_organization_id">Organization ID</a></li><li><a href="https://cloud.google.com/resource-manager/docs/creating-managing-projects#identifying_projects">Project ID</a></li><li>Google Cloud Region</li><li>GKE Cluster Name</li><li>GKE Cluster Region</li><li>Tag Key-Value Pairs (if used)</li></ul><p><strong>Optional</strong>:</p><ul><li>Apono Connector ID</li><li>Service Account Name</li><li>Namespace</li></ul></td></tr><tr><td><strong>Owner Role</strong></td><td><a href="https://cloud.google.com/iam/docs/roles-overview?sjid=2603002525407015039-NC#basic">Google Cloud role</a> that provides <strong>Owner</strong> permissions for the project or organization</td></tr></tbody></table>

***

### Install a connector

Use the following sections to install a connector for either your [Google Project](#project) or [Google Organization](#organization).

#### Project

Follow these steps to install an Apono connector for a Google Project:

1. Set the environment variables.

```shell
export TF_VAR_PROJECT_ID="<GCP_PROJECT_ID>"
export TF_VAR_REGION="<GCP_REGION>"
export TF_VAR_NAME="<GKE_CLUSTER_NAME>"
export TF_VAR_LOCATION="<GCP_CLUSTER_REGION>"
export TF_VAR_APONO_TOKEN="<APONO_TOKEN>"
export TF_VAR_TAGS="<{tag1="value1"}>"
```

2. (Optional) Set the following optional environment variables.

```shell
export TF_VAR_CONNECTOR_ID="<APONO_CONNECTOR_NAME>"
export TF_VAR_SERVICE_ACCOUNT_NAME="<GCP_SERVICE_ACCOUNT_NAME>"
export TF_VAR_NAMESPACE="<NAMESPACE>"
```

3. In your shell environment, log in to Google Cloud and enable the API.

{% code overflow="wrap" %}

```shell
gcloud auth login 
gcloud services enable cloudresourcemanager.googleapis.com --project $GCP_PROJECT_ID
gcloud services enable cloudasset.googleapis.com --project $GCP_PROJECT_ID
gcloud services enable cloudidentity.googleapis.com --project $GCP_PROJECT_ID
gcloud services enable admin.googleapis.com --project $GCP_PROJECT_ID
```

{% endcode %}

4. In a new or existing Terraform (.tf) file, add the following provider and module information to create a connector.

{% code overflow="wrap" %}

```
provider "google" {
  project     = "{var.PROJECT_ID}"
  region      = "{var.REGION}"
}

data "google_client_config" "provider" {}

data "google_container_cluster" "gke" {
  name     = "{var.NAME}"
  location = "{var.LOCATION}"
}

provider "helm" {
  kubernetes{
    host  = "https://${data.google_container_cluster.gke.endpoint}"
    token = data.google_client_config.provider.access_token
    cluster_ca_certificate = base64decode(
      data.google_container_cluster.gke.master_auth[0].cluster_ca_certificate,)
    exec {
      api_version = "client.authentication.k8s.io/v1beta1"
      command     = "gke-gcloud-auth-plugin"
    }
  }
}

module "apono-connector" {
  source = "github.com/apono-io/terraform-modules//gcp/organization-wide-connector/gke/stacks/apono-connector"
  connectorId = "{var.CONNECTOR_ID}" //OPTIONAL
  aponoToken = "{var.APONO_TOKEN}"
  projectId = "{var.PROJECT_ID}"
  serviceAccountName = "{var.SERVICE_ACCOUNT_NAME}" //OPTIONAL
  namespace = "{var.NAMESPACE}" //OPTIONAL
  tags = "{var.TAGS}"
}
```

{% endcode %}

5. At the Terraform CLI, download and install the provider plugin and module.

```shell
terraform init
```

6. Apply the Terraform changes. The proposed changes and a confirmation prompt will be listed.

```shell
terraform apply
```

7. Enter *yes* to confirm deploying the changes to your Google Project instance.
8. On the [**Connectors**](https://app.apono.io/connectors) page, verify that the connector has been deployed.

#### Organization

Follow these steps to install an Apono connector for a Google Organization:

1. In your shell environment, log in to Google Cloud and enable the API.

```shell
gcloud alpha auth login
gcloud services enable cloudresourcemanager.googleapis.com
gcloud services enable cloudasset.googleapis.com
gcloud services enable cloudidentity.googleapis.com
gcloud services enable admin.googleapis.com
```

2. Set the environment variables.

```shell
export TF_VAR_PROJECT_ID="<GCP_PROJECT_ID>"
export TF_VAR_REGION="<GCP_REGION>"
export TF_VAR_NAME="<GKE_CLUSTER_NAME>"
export TF_VAR_LOCATION="<GCP_CLUSTER_REGION>"
export TF_VAR_APONO_TOKEN="<APONO_TOKEN>"
export TF_VAR_ORGANIZATION_ID="<GCP_ORGANIZATION_ID>"
export TF_VAR_TAGS="<{tag1="value1"}>"
```

3. (Optional) Set the following optional environment variables.

```shell
export TF_VAR_CONNECTOR_ID="<APONO_CONNECTOR_NAME>"
export TF_VAR_SERVICE_ACCOUNT_NAME="<GCP_SERVICE_ACCOUNT_NAME>"
export TF_VAR_NAMESPACE="<NAMESPACE>"
```

4. In a new or existing Terraform (.tf) file, add the following provider and module information to create a connector.

{% code overflow="wrap" %}

```
provider "google" {
  project     = "{var.PROJECT_ID}"
  region      = "{var.REGION}"
}

data "google_client_config" "provider" {}

data "google_container_cluster" "gke" {
  name     = "{var.NAME}"
  location = "{var.LOCATION}"
}

provider "helm" {
  kubernetes{
    host  = "https://${data.google_container_cluster.gke.endpoint}"
    token = data.google_client_config.provider.access_token
    cluster_ca_certificate = base64decode(
      data.google_container_cluster.gke.master_auth[0].cluster_ca_certificate,)
    exec {
      api_version = "client.authentication.k8s.io/v1beta1"
      command     = "gke-gcloud-auth-plugin"
    }
  }
}

module "apono-connector" {
  source = "github.com/apono-io/terraform-modules//gcp/organization-wide-connector/gke/stacks/apono-connector"
  connectorId = "{var.CONNECTOR_ID}" //OPTIONAL
  aponoToken = "{var.APONO_TOKEN}"
  projectId = "{var.PROJECT_ID}"
  organizationId = "{var.ORGANIZATION_ID}"
  serviceAccountName = "{var.SERVICE_ACCOUNT_NAME}" //OPTIONAL
  namespace = "{var.NAMESPACE}" //OPTIONAL
  tags = "{var.TAGS}"
}
```

{% endcode %}

5. At the Terraform CLI, download and install the provider plugin and module.

```shell
terraform init
```

6. Apply the Terraform changes. The proposed changes and a confirmation prompt will be listed.

```shell
terraform apply
```

7. Enter *yes* to confirm deploying the changes to your Google Organization instance.
8. On the [**Connectors**](https://app.apono.io/connectors) page, verify that the connector has been deployed.

***

### FAQ

<details>

<summary><strong>Can the Apono Terraform module be pinned to a version?</strong></summary>

Yes. You can append the version number to the `source` location with the `?ref=vX.X.X` query string.

The following examples pin the version to **1.0.0** for a connector without permissions.

{% code title="Pinned Version (Project)" overflow="wrap" %}

```
provider "google" {
  project     = "{var.PROJECT_ID}"
  region      = "{var.REGION}"
}

data "google_client_config" "provider" {}

data "google_container_cluster" "gke" {
  name     = "{var.NAME}"
  location = "{var.LOCATION}"
}

provider "helm" {
  kubernetes{
    host  = "https://${data.google_container_cluster.gke.endpoint}"
    token = data.google_client_config.provider.access_token
    cluster_ca_certificate = base64decode(
      data.google_container_cluster.gke.master_auth[0].cluster_ca_certificate,)
    exec {
      api_version = "client.authentication.k8s.io/v1beta1"
      command     = "gke-gcloud-auth-plugin"
    }
  }
}

module "apono-connector" {
  source = "github.com/apono-io/terraform-modules//gcp/organization-wide-connector/gke/stacks/apono-connector?ref=v1.0.0"
  connectorId = "{var.CONNECTOR_ID}" //OPTIONAL
  aponoToken = "{var.APONO_TOKEN}"
  projectId = "{var.PROJECT_ID}"
  serviceAccountName = "{var.SERVICE_ACCOUNT_NAME}" //OPTIONAL
  namespace = "{var.NAMESPACE}" //OPTIONAL
  tags = "{var.TAGS}"
}
```

{% endcode %}

{% code title="Pinned Version (Organization)" overflow="wrap" %}

```
provider "google" {
  project     = "{var.PROJECT_ID}"
  region      = "{var.REGION}"
}

data "google_client_config" "provider" {}

data "google_container_cluster" "gke" {
  name     = "{var.NAME}"
  location = "{var.LOCATION}"
}

provider "helm" {
  kubernetes{
    host  = "https://${data.google_container_cluster.gke.endpoint}"
    token = data.google_client_config.provider.access_token
    cluster_ca_certificate = base64decode(
      data.google_container_cluster.gke.master_auth[0].cluster_ca_certificate,)
    exec {
      api_version = "client.authentication.k8s.io/v1beta1"
      command     = "gke-gcloud-auth-plugin"
    }
  }
}

module "apono-connector" {
  source = "github.com/apono-io/terraform-modules//gcp/organization-wide-connector/gke/stacks/apono-connector?ref=v1.0.0"
  connectorId = "{var.CONNECTOR_ID}" //OPTIONAL
  aponoToken = "{var.APONO_TOKEN}"
  projectId = "{var.PROJECT_ID}"
  organizationId = "{var.ORGANIZATION_ID}"
  serviceAccountName = "{var.SERVICE_ACCOUNT_NAME}" //OPTIONAL
  namespace = "{var.NAMESPACE}" //OPTIONAL
  tags = "{var.TAGS}"
}
```

{% endcode %}

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.apono.io/docs/gcp-environment/apono-connector-for-gcp/installing-a-gcp-connector-on-gke-using-terraform.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
