Git Product home page Git Product logo

terraform-gkp's Introduction

kubernetes-GKP-terraform

simple module and example for manage kubernetes clusters in GKE by terraform

##Setup the GCP environment

  1. Installing Google Cloud SDK, see https://cloud.google.com/sdk/install
  2. Auth in your GCP account
gcloud auth login
  1. Create a GCP project
  • configure GCP
export GCP_BILLING_ACCOUNT_ID=<YOUR_BILLING_ACCOUNT_ID>
export GCP_PROJECT_ID=<YOUR_GCP_PROJECT_ID>
export GCP_TF_SA=<YOUR_TERRAFORM_SA_NAME>

gcloud projects create ${GCP_PROJECT_ID} --set-as-default
gcloud beta billing projects link ${GCP_PROJECT_ID} --billing-account ${GCP_BILLING_ACCOUNT_ID}

*Note YOUR_BILLING_ACCOUNT_ID - you can find it by run gcloud beta billing accounts list YOUR_GCP_PROJECT_ID - GCP project ID to create YOUR_TERRAFORM_SA_NAME - name for terraform service account in GCP **

  1. Create the Terraform service account and key file in secret directory
gcloud iam service-accounts create ${GCP_TF_SA} \
  --display-name "Terraform admin account"

gcloud iam service-accounts keys create ./secrets/${GCP_PROJECT_ID}-sa.json \
  --iam-account ${GCP_TF_SA}@${GCP_PROJECT_ID}.iam.gserviceaccount.com
  1. Grant nessery service account permission for ${GCP_TF_SA}
gcloud projects add-iam-policy-binding ${GCP_PROJECT_ID} \
  --member serviceAccount:${GCP_TF_SA}@${GCP_PROJECT_ID}.iam.gserviceaccount.com \
  --role roles/owner
  1. Any actions that Terraform performs require that the API be enabled to do so. In this guide, Terraform requires the following:
gcloud services enable cloudkms.googleapis.com
gcloud services enable cloudresourcemanager.googleapis.com
gcloud services enable iam.googleapis.com
gcloud services enable logging.googleapis.com
gcloud services enable monitoring.googleapis.com
gcloud services enable container.googleapis.com
gcloud services enable compute.googleapis.com

##Run Terraform example

  1. Define main terraform variables
export TF_VAR_project=${GCP_PROJECT_ID}
export TF_VAR_file_sa=./secrets/${GCP_PROJECT_ID}-sa.json
  1. Create workspace for your project(enviroment)
cd example
terraform workspace new ${GCP_PROJECT_ID}

  1. Run terraform
terraform workspace select ${GCP_PROJECT_ID}
terraform init
terraform plan -var-file="./env/${GCP_PROJECT_ID}.tfvars"
terraform apply -var-file="./env/${GCP_PROJECT_ID}.tfvars"
terraform destroy -var-file="./env/${GCP_PROJECT_ID}.tfvars"

##re-run example

cd example
export GCP_PROJECT_ID=mbelousov-kubernetes-laba
export TF_VAR_project=${GCP_PROJECT_ID}
export TF_VAR_file_sa=./env/${GCP_PROJECT_ID}-sa.json
terraform workspace select ${GCP_PROJECT_ID}
terraform init
terraform plan -var-file="./env/${GCP_PROJECT_ID}.tfvars"
terraform apply -var-file="./env/${GCP_PROJECT_ID}.tfvars"
terraform destroy -var-file="env/${GCP_PROJECT_ID}.tfvars"

terraform-gkp's People

Contributors

mbelousov7 avatar

Watchers

 avatar

Forkers

mikhailkalikin

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.