Installing a GCP connector on GKE using Terraform

Create a connector on Google Kubernetes Engine

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

Item
Description

Apono Token

Account-specific Apono authentication value Use the following steps to obtain your token:

  1. On the Connectors page, click Install Connector. The Install Connector page appears.

  2. Click Cloud installation.

  3. Click Cloud installation > GCP > Install and Connect GCP Project > CLI (GKE).

  4. Copy the token listed on the page in step 1.

Google Cloud Command Line Interface (Google Cloud CLI)

Command-line interface used to manage Google Cloud resources

Google Cloud Information

Information for your Google Cloud instance:

Optional:

  • Apono Connector ID

  • Service Account Name

  • Namespace

Owner Role

Google Cloud role that provides Owner permissions for the project or organization


Install a connector

Use the following sections to install a connector for either your Google Project or Google Organization.

Project

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

  1. In your shell environment, log in to Google Cloud with an account possessing Owner permissions.

gcloud auth application-default login
  1. At the shell prompt, set the environment variables.

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"}>"
  1. (Optional) Set the following optional environment variables.

export TF_VAR_CONNECTOR_ID="<APONO_CONNECTOR_NAME>"
export TF_VAR_SERVICE_ACCOUNT_NAME="<GCP_SERVICE_ACCOUNT_NAME>"
export TF_VAR_NAMESPACE="<NAMESPACE>"
  1. In a new or existing Terraform (.tf) file, add the following provider and module information to create a connector.

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}"
}
  1. At the Terraform CLI, download and install the provider plugin and module.

terraform init
  1. Apply the Terraform changes. The proposed changes and a confirmation prompt will be listed.

terraform apply
  1. Enter yes to confirm deploying the changes to your Google Project instance.

  2. On the 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 with an account possessing Organization Administrator permissions.

gcloud alpha auth application-default login
  1. At the shell prompt, set the environment variables.

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"}>"
  1. (Optional) Set the following optional environment variables.

export TF_VAR_CONNECTOR_ID="<APONO_CONNECTOR_NAME>"
export TF_VAR_SERVICE_ACCOUNT_NAME="<GCP_SERVICE_ACCOUNT_NAME>"
export TF_VAR_NAMESPACE="<NAMESPACE>"
  1. In a new or existing Terraform (.tf) file, add the following provider and module information to create a connector.

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}"
}
  1. At the Terraform CLI, download and install the provider plugin and module.

terraform init
  1. Apply the Terraform changes. The proposed changes and a confirmation prompt will be listed.

terraform apply
  1. Enter yes to confirm deploying the changes to your Google Organization instance.

  2. On the Connectors page, verify that the connector has been deployed.


FAQ

Can the Apono Terraform module be pinned to a version?

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.

Pinned Version (Project)
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}"
}
Pinned Version (Organization)
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}"
}

Last updated