Clone or navigate to the indexer repository.
Navigate to the ./terraform
directory, this is where all commands should be executed.
cd terraform
Authenticate with Google Cloud and create a new project.
gcloud auth login
project=<PROJECT_NAME>
gcloud projects create --enable-cloud-apis $project
Use the Google Cloud Console's billing page to enable billing for the new project.
Create a Google Cloud configuration.
proj_id=$(gcloud projects list --format='get(project_id)' --filter="name=$project")
gcloud config configurations create $project
gcloud config set project "$proj_id"
gcloud config set compute/region us-central1
gcloud config set compute/zone us-central1-a
Enable required Google Cloud APIs.
gcloud services enable compute.googleapis.com
gcloud services enable container.googleapis.com
gcloud services enable servicenetworking.googleapis.com
gcloud services enable sqladmin.googleapis.com
Create a service account.
svc_name=<SERVICE_ACCOUNT_NAME>
gcloud iam service-accounts create $svc_name \\
--description="Service account for Terraform" \\
--display-name="$svc_name"
gcloud iam service-accounts list
# Get the email of the service account from the list
svc=$(gcloud iam service-accounts list --format='get(email)' --filter="displayName=$svc_name")
gcloud iam service-accounts keys create .gcloud-credentials.json \\
--iam-account="$svc"
gcloud projects add-iam-policy-binding $proj_id \\
--member serviceAccount:$svc \\
--role roles/editor
Enable peering between database and Kubernetes cluster that will be created in the next step.
gcloud compute addresses create google-managed-services-default \\
--prefix-length=20 \\
--purpose=VPC_PEERING \\
--network default \\
--global \\
--description 'IP Range for peer networks.'
gcloud services vpc-peerings connect \\
--network=default \\
--ranges=google-managed-services-default
Create minimal terraform configuration file (update as needed).
indexer=<INDEXER_NAME>
cat > terraform.tfvars <<EOF
project = "$proj_id"
indexer = "$indexer"
database_password = "<database passowrd>"
EOF
Before running any commands, read through variables.tf and create a file terraform.tfvars
in this directory (or modify the one we created in the last step). For each variable where you want to override the default, or where you need to set a value, enter a setting into terraform.tfvars
.
Run the following commands to create the infrastructure.
# Install required plugins
terraform init
# View plan for resources to be created
terraform plan
# Create the resources (expect it to take up to 30 minutes)
terraform apply
Download credentials for the new cluster into ~/.kube/config
and set it as your default context.
gcloud container clusters get-credentials $indexer
kubectl config use-context $(kubectl config get-contexts --output='name' | grep $indexer)