Coder Social home page Coder Social logo

vjkri / terraform-gcp-gke Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 2.0 39 KB

This module handles Google Cloud Platform Kubernetes Engine cluster creation and configuration and verifies through kitchen terraform

Ruby 24.20% HCL 75.80%
gcp gke gke-cluster gke-terraform kitchen-terraform kitchen terraform-module ruby-gem

terraform-gcp-gke's Introduction

GKE terraform

This module handles Google Cloud Platform Kubernetes Engine cluster creation and configuration with Node Pools, IP MASQ, Network Policy, etc. The resources/services/activations/deletions that this module will create/trigger are:

Create a GKE cluster with the provided addons Create GKE Node Pool(s) with provided configuration and attach to cluster Verify through kitchen-terraform

Prerequisites

Check that Terraform is installed and up to date on your machine with terraform version. At the time of writing the version of binary distributed by HashiCorp is v0.11.13. Installation instructions can be found here.

This guide uses the Google Cloud Platform (GCP) utility gcloud, which is part of the Cloud SDK. Installation instructions for this can be found here. The Google Cloud Storage (GCS) command line utility gsutil is also used to create and delete Buckets. It is installed as part of the Cloud SDK. Much of what these commands go can be achieved using the GCP Console, but using the commands allows the guide to be concise and precise about what to do.

Setup

The following guide assumes commands are run from the example directory.

Provide the input variables with a terraform.tfvars file provided under test/fixtures/tf_module:

terraform.tfvars

Update the below to reflect your public ip, so that you can connect to master


master_authorized_networks_cidr_blocks = [
  {
    cidr_block = "90.221.77.132/32"
    display_name = "default"
  },  
]

The values set in this file should be edited according to your environment and requirements.

Once the Cloud SDK is installed you can authenticating, set the project, and choose a compute zone with the interactive command:

gcloud init

Ensure the required APIs are enabled:

gcloud services enable storage-api.googleapis.com
gcloud services enable cloudresourcemanager.googleapis.com
gcloud services enable compute.googleapis.com
gcloud services enable container.googleapis.com
gcloud services enable iam.googleapis.com

Now create a service account for Terraform to use, generate a key file for it, and save the key location as an environment variable:

gcloud iam service-accounts create terraform
gcloud projects add-iam-policy-binding [PROJECT_ID] --member "serviceAccount:terraform@[PROJECT_ID].iam.gserviceaccount.com" --role "roles/owner"
gcloud iam service-accounts keys create key.json --iam-account terraform@[PROJECT_ID].iam.gserviceaccount.com
export GOOGLE_APPLICATION_CREDENTIALS="$PWD/key.json"

NOTE: Keep the key file in a safe place, and do not share or publicise it.

Next create a GCS Bucket that will be used to hold Terraform state information. The Bucket name must be globally unique, a suggested name is [PROJECT_ID]-terraform-state:

gsutil mb gs://[BUCKET_NAME]

Next, initialise Terraform with the name of the GCS Bucket just created:

terraform init -backend-config=bucket=[BUCKET_NAME] -backend-config=project=[GOOGLE_PROJECT]

Install Kitchen-terraform

bundle install

List

bundle exec kitchen list

Now that kitchen-terraform is setup check that the configuration is valid, If the configuration is valid then apply it and also verify with:

bundle exec kitchen converge

Verify

bundle exec kitchen verify

To test end to end

bundle exec kitchen test

Clean Up

Remove the infrastructure created by Terraform with:

bundle exec kitchen destroy

Sometimes Terraform may report a failure to destroy some resources due to dependencies and timing contention. In this case wait a few seconfds and run the above command again. If it is still unable to remove everything it may be necessary to remove resources manually using the gcloud command or the Cloud Console.

The GCS Bucket used for Terraform state storage can be removed with:

gsutil rm -r gs:[BUCKET_NAME]

terraform-gcp-gke's People

Contributors

vjkri avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.