### Navigate to Example Directory Source: https://github.com/googlecloudplatform/terraform-google-examples/blob/master/example-custom-machine-types/README.md Change the current directory to the example's directory. This command ensures you are in the correct location before proceeding with the setup. ```bash [[ `basename $PWD` != example-custom-machine-types ]] && cd example-custom-machine-types ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/googlecloudplatform/terraform-google-examples/blob/master/README.md Change to the specific example directory you want to work with. ```bash cd EXAMPLE_NAME ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/googlecloudplatform/terraform-google-examples/blob/master/example-gke-k8s-helm/README.md Ensures you are in the correct example directory. If not, it changes to 'example-gke-k8s-helm'. ```bash [[ `basename $PWD` != example-gke-k8s-helm ]] && cd example-gke-k8s-helm ``` -------------------------------- ### Change to Example Directory Source: https://github.com/googlecloudplatform/terraform-google-examples/blob/master/example-gke-k8s-multi-region/README.md Navigate to the specific example directory. This command ensures you are in the correct working directory for the example. ```bash [[ `basename $PWD` != example-gke-k8s-multi-region ]] && cd example-gke-k8s-multi-region ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/googlecloudplatform/terraform-google-examples/blob/master/example-gke-k8s-service-lb/README.md Change to the example directory to begin. This command ensures you are in the correct working directory. ```bash [[ `basename $PWD` != example-gke-k8s-service-lb ]] && cd example-gke-k8s-service-lb ``` -------------------------------- ### Install Terraform Source: https://github.com/googlecloudplatform/terraform-google-examples/blob/master/example-gke-k8s-multi-region/README.md Installs Terraform using a provided script. Refer to terraform.io for alternative installation methods. ```bash ../terraform-install.sh ``` -------------------------------- ### Install Terraform Helm Provider Source: https://github.com/googlecloudplatform/terraform-google-examples/blob/master/example-gke-k8s-helm/README.md Downloads and installs the Terraform Helm provider. This is a one-time setup for Terraform to manage Helm resources. ```bash ( set -x; cd "$(mktemp -d)" && \ curl -fsSLO "https://github.com/mcuadros/terraform-provider-helm/releases/download/v0.5.1/terraform-provider-helm_v0.5.1_$(uname | tr '[:upper:]' '[:lower:]')_amd64.tar.gz" && \ tar -xvf terraform-provider-helm*.tar.gz && \ mkdir -p ~/.terraform.d/plugins/ && \ mv terraform-provider-helm*/terraform-provider-helm ~/.terraform.d/plugins/ ) ``` -------------------------------- ### Install Helm Source: https://github.com/googlecloudplatform/terraform-google-examples/blob/master/example-gke-k8s-helm/README.md Installs the latest version of Helm and initializes the client. This involves downloading a script, making it executable, running it, and then initializing Helm. ```bash curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get > get_helm.sh chmod 700 get_helm.sh ./get_helm.sh helm init --client-only ``` -------------------------------- ### Clone Terraform Examples Repository Source: https://github.com/googlecloudplatform/terraform-google-examples/blob/master/README.md Use this command to clone the repository and initialize submodules. ```bash git clone https://github.com/GoogleCloudPlatform/terraform-google-examples.git cd terraform-google-examples git submodule init && git submodule update ``` -------------------------------- ### Check HCL Formatting Differences Source: https://github.com/googlecloudplatform/terraform-google-examples/blob/master/CONTRIBUTING.md Use this command to compare your Terraform files with the output of `hclfmt` to ensure adherence to the project's style guide. It highlights any formatting discrepancies. ```bash diff -B <( cat *.tf ) <( hclfmt *.tf ) ``` -------------------------------- ### Get GKE Cluster Credentials Source: https://github.com/googlecloudplatform/terraform-google-examples/blob/master/example-gke-k8s-service-lb/README.md Retrieve the credentials for your GKE cluster and configure kubectl to interact with it. ```bash gcloud container clusters get-credentials $(terraform output cluster_name) --zone $(terraform output cluster_zone) ``` -------------------------------- ### Get Application Endpoint URL Source: https://github.com/googlecloudplatform/terraform-google-examples/blob/master/example-gke-k8s-helm/README.md Outputs the endpoint URL for the deployed application, which can be used to access it via a web browser. ```bash echo $(terraform output endpoint) ``` -------------------------------- ### Undelete Cloud Endpoints Service Source: https://github.com/googlecloudplatform/terraform-google-examples/blob/master/example-gke-k8s-helm/README.md Undeletes a previously deleted Cloud Endpoints service named 'drupal'. This is necessary if the example was run recently and the service was removed. ```bash gcloud endpoints services undelete drupal.endpoints.$(gcloud config get-value project).cloud.goog ``` -------------------------------- ### Test Load Balancer Provisioning Source: https://github.com/googlecloudplatform/terraform-google-examples/blob/master/example-gke-k8s-multi-region/README.md Executes a script to verify that the load balancer has been successfully provisioned. ```bash ./test.sh ``` -------------------------------- ### Configure Terraform Environment Source: https://github.com/googlecloudplatform/terraform-google-examples/blob/master/example-gke-k8s-multi-region/README.md Sets up the environment for Terraform by logging in to Google Cloud if not already authenticated and exporting the Google Cloud project ID. ```bash [[ $CLOUD_SHELL ]] || gcloud auth application-default login export GOOGLE_PROJECT=$(gcloud config get-value project) ``` -------------------------------- ### Initialize and Apply Terraform Configuration Source: https://github.com/googlecloudplatform/terraform-google-examples/blob/master/example-gke-k8s-multi-region/README.md Initializes the Terraform working directory and applies the defined infrastructure configuration. ```bash terraform init terraform apply ``` -------------------------------- ### Display Login Credentials Source: https://github.com/googlecloudplatform/terraform-google-examples/blob/master/example-gke-k8s-helm/README.md Outputs the username and password for logging into the deployed application's interface. ```bash echo User: $(terraform output drupal_user) echo Password: $(terraform output drupal_password) ``` -------------------------------- ### Verify Kubectl Connectivity Source: https://github.com/googlecloudplatform/terraform-google-examples/blob/master/example-gke-k8s-service-lb/README.md Check kubectl connectivity by listing pods in the staging namespace. ```bash kubectl get pods -n staging ``` -------------------------------- ### Configure GCS Remote Backend Source: https://github.com/googlecloudplatform/terraform-google-examples/blob/master/example-custom-machine-types/README.md Sets up a Google Cloud Storage bucket for Terraform state file storage and defines the prefix for the state file. This ensures state is stored remotely and securely. ```bash BUCKET=${GOOGLE_PROJECT}-terraform ``` ```bash gsutil mb gs://${BUCKET} ``` ```bash PREFIX=tf-es-custom-machine/state ``` ```hcl cat > backend.tf < terraform.tfvars <