<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Pradeep Bhadani</title>
    <description>The latest articles on Forem by Pradeep Bhadani (@pradeepbhadani).</description>
    <link>https://forem.com/pradeepbhadani</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F287992%2F5845ec01-28df-4f54-a767-6fb8392ba9c2.png</url>
      <title>Forem: Pradeep Bhadani</title>
      <link>https://forem.com/pradeepbhadani</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/pradeepbhadani"/>
    <language>en</language>
    <item>
      <title>Run your own Jupyter Notebook on the Cloud</title>
      <dc:creator>Pradeep Bhadani</dc:creator>
      <pubDate>Mon, 11 May 2020 07:56:30 +0000</pubDate>
      <link>https://forem.com/pradeepbhadani/run-your-own-jupyter-notebook-on-the-cloud-37c0</link>
      <guid>https://forem.com/pradeepbhadani/run-your-own-jupyter-notebook-on-the-cloud-37c0</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://pbhadani.com/posts/run-your-own-jupyter-notebook/"&gt;pbhadani.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Jupyter Notebook is an open-source web-based application that allows data scientists to build end-to-end Machine Learning pipeline starting from Data exploration, visualization, data transformation, feature extraction, and manage ML model lifecycle.&lt;/p&gt;

&lt;p&gt;In this video, I explain the installation process of the Jupyter Notebook on the choice of hardware on the Cloud, particularly the Google Cloud Platform(GCP).&lt;/p&gt;

&lt;p&gt;Hope you enjoy the video tutorial.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Lk0SmRYtGt8"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;This video explains how to install Jupyter Notebook on Google Cloud Platform(GCP) in less than 10mins.&lt;br&gt;
Below are the steps and commands performed in the video:&lt;/p&gt;
&lt;h5&gt;
  
  
  Step 0 (Optional)
&lt;/h5&gt;

&lt;p&gt;Generate the public/private SSH keypair.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh-keygen &lt;span class="nt"&gt;-t&lt;/span&gt; rsa &lt;span class="nt"&gt;-b&lt;/span&gt; 4096 &lt;span class="nt"&gt;-C&lt;/span&gt; jupyter_demo &lt;span class="nt"&gt;-f&lt;/span&gt; jupyter_demo
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Step 1
&lt;/h5&gt;

&lt;p&gt;Create the Virtual Machine using Google Cloud Console UI, gcloud commands or with automation tools like Terraform.&lt;/p&gt;

&lt;h5&gt;
  
  
  Step 2
&lt;/h5&gt;

&lt;p&gt;Install the software packages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;python3-pip
pip3 &lt;span class="nb"&gt;install &lt;/span&gt;jupyter
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"export PATH=&lt;/span&gt;&lt;span class="nv"&gt;$PATH&lt;/span&gt;&lt;span class="s2"&gt;:~/.local/bin"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; ~/.bashrc
&lt;span class="nb"&gt;source&lt;/span&gt; ~/.bashrc
jupyter notebook &lt;span class="nt"&gt;--no-browser&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h5&gt;
  
  
  Step 3
&lt;/h5&gt;

&lt;p&gt;Access the Jupyter Notebook.&lt;br&gt;
Run the following command to create the SSH tunnel.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="nt"&gt;-i&lt;/span&gt; private_key &lt;span class="nt"&gt;-N&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="nt"&gt;-L&lt;/span&gt; 8888:localhost:8888 username@your_remote_host_name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once the tunnel is setup, open the browser, go to &lt;code&gt;localhost:8888&lt;/code&gt; and provide the token generated in &lt;strong&gt;Step 2&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
Congratulations!!! Jupyter Notebook is now accessible from the local workstation.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rnX-fwnS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/74r30gvyhmxxjk2cap1n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rnX-fwnS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/74r30gvyhmxxjk2cap1n.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
Please subscribe to the &lt;a href="https://www.youtube.com/channel/UCR8RtRbr87S86UJakb7D0Pw"&gt;YouTube&lt;/a&gt; channel for the updates.  &lt;/p&gt;

&lt;p&gt;If you have feedback or questions, please reach out to me on &lt;a href="https://linkedin.com/in/pradeepbhadani"&gt;LinkedIn&lt;/a&gt; or &lt;a href="https://twitter.com/bhadanipradeep"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>jupyter</category>
      <category>datascience</category>
      <category>cloud</category>
      <category>googlecloudplatform</category>
    </item>
    <item>
      <title>Create a Network on Google Cloud Platform (GCP)</title>
      <dc:creator>Pradeep Bhadani</dc:creator>
      <pubDate>Thu, 23 Apr 2020 22:10:03 +0000</pubDate>
      <link>https://forem.com/pradeepbhadani/create-a-network-on-google-cloud-platform-gcp-hn2</link>
      <guid>https://forem.com/pradeepbhadani/create-a-network-on-google-cloud-platform-gcp-hn2</guid>
      <description>&lt;p&gt;Network is a fundamental resource for creating Infrastructure on the Cloud like VM Instances, Google Kubernetes Engine (GKE), etc.&lt;/p&gt;

&lt;p&gt;In this video, I explain the Network option available on the Google Cloud Platform(GCP) and how to create them using Google Cloud Console UI.&lt;/p&gt;

&lt;p&gt;Hope you enjoy the video tutorial.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/DDovDxKL6go"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Please subscribe to the &lt;a href="https://www.youtube.com/channel/UCR8RtRbr87S86UJakb7D0Pw"&gt;YouTube&lt;/a&gt; channel for the updates.  &lt;/p&gt;

&lt;p&gt;If you have feedback or questions, please reach out to me on &lt;a href="https://linkedin.com/in/pradeepbhadani"&gt;LinkedIn&lt;/a&gt; or &lt;a href="https://twitter.com/bhadanipradeep"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>gcp</category>
      <category>cloud</category>
      <category>devops</category>
    </item>
    <item>
      <title>Create a GKE Cluster (Workload Identity enabled) using Terraform</title>
      <dc:creator>Pradeep Bhadani</dc:creator>
      <pubDate>Fri, 06 Mar 2020 21:50:05 +0000</pubDate>
      <link>https://forem.com/pradeepbhadani/create-a-gke-cluster-workload-identity-enabled-using-terraform-4n2f</link>
      <guid>https://forem.com/pradeepbhadani/create-a-gke-cluster-workload-identity-enabled-using-terraform-4n2f</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://pbhadani.com/posts/gke-terraform?src=devto"&gt;pbhadani.com&lt;/a&gt;&lt;/em&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;In this blog, I will show how Terraform can be used to create a &lt;a href="https://cloud.google.com/kubernetes-engine"&gt;Google Kubernetes Engine (GKE)&lt;/a&gt; cluster.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OwnLrzqm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jtb4fvbo0ao2lgolyy5u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OwnLrzqm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jtb4fvbo0ao2lgolyy5u.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Goal
&lt;/h1&gt;

&lt;p&gt;Create a GKE Cluster which has &lt;a href="https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity"&gt;Workload Identity&lt;/a&gt; feature enabled using Terraform.&lt;/p&gt;
&lt;h1&gt;
  
  
  Prerequisites
&lt;/h1&gt;

&lt;p&gt;This post assumes the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We already have a GCP Project and a GCS Bucket (we will use this to store Terraform State file) created.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Google Kubernetes Engine&lt;/code&gt; API is enabled in the GCP Project.&lt;/li&gt;
&lt;li&gt;Google Cloud SDK (&lt;code&gt;gcloud&lt;/code&gt;), &lt;code&gt;kubectl&lt;/code&gt; and &lt;code&gt;Terraform&lt;/code&gt; is setup on your workstation. If you don't have, then refer to my previous blogs - &lt;a href="https://pbhadani.com/posts/getting-started-with-terraform/"&gt;Getting started with Terraform&lt;/a&gt; and &lt;a href="https://pbhadani.com/posts/getting-started-wth-google-cloud-sdk/"&gt;Getting started with Google Cloud SDK&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h1&gt;
  
  
  Source Code
&lt;/h1&gt;

&lt;p&gt;Full code is available on &lt;a href="https://github.com/pradeepbhadani/terraform-gke-example"&gt;GitHub&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Note:&lt;/strong&gt; This is not a production-ready codebase.&lt;/p&gt;
&lt;h1&gt;
  
  
  Create a GKE Cluster
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Create a Unix directory for the Terraform project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nb"&gt;mkdir&lt;/span&gt; ~/terraform-gke-example
  &lt;span class="nb"&gt;cd&lt;/span&gt; ~/terraform-gke-example
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Create Terraform configuration file which defines GKE and Google provider.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  vi gke.tf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This file has following content&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;  &lt;span class="c1"&gt;# Specify the GCP Provider&lt;/span&gt;
  &lt;span class="nx"&gt;provider&lt;/span&gt; &lt;span class="s2"&gt;"google-beta"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;project&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project_id&lt;/span&gt;
    &lt;span class="nx"&gt;region&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;region&lt;/span&gt;
    &lt;span class="nx"&gt;version&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"~&amp;gt; 3.10"&lt;/span&gt;
    &lt;span class="nx"&gt;alias&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"gb3"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;# Create a GKE cluster&lt;/span&gt;
  &lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"google_container_cluster"&lt;/span&gt; &lt;span class="s2"&gt;"my_k8s_cluster"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;provider&lt;/span&gt;           &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;google&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;beta&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;gb3&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;               &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"my-k8s-cluster"&lt;/span&gt;
    &lt;span class="nx"&gt;location&lt;/span&gt;           &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;region&lt;/span&gt;
    &lt;span class="nx"&gt;initial_node_count&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

    &lt;span class="nx"&gt;master_auth&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;username&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
      &lt;span class="nx"&gt;password&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;# Enable Workload Identity&lt;/span&gt;
    &lt;span class="nx"&gt;workload_identity_config&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;identity_namespace&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"${var.project_id}.svc.id.goog"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nx"&gt;node_config&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;machine_type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;machine_type&lt;/span&gt;
      &lt;span class="nx"&gt;oauth_scopes&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s2"&gt;"https://www.googleapis.com/auth/logging.write"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"https://www.googleapis.com/auth/monitoring"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;]&lt;/span&gt;

      &lt;span class="nx"&gt;metadata&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"disable-legacy-endpoints"&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"true"&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;

      &lt;span class="nx"&gt;workload_metadata_config&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;node_metadata&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"GKE_METADATA_SERVER"&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;

      &lt;span class="nx"&gt;labels&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;# Update: Replace with desired labels&lt;/span&gt;
        &lt;span class="s2"&gt;"environment"&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"test"&lt;/span&gt;
        &lt;span class="s2"&gt;"team"&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"devops"&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;code&gt;workload_identity_config&lt;/code&gt; &amp;amp; &lt;code&gt;workload_metadata_config&lt;/code&gt; block enables Workload Identity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Define Terraform variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  vi variables.tf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This file looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;  &lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"project_id"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Google Project ID."&lt;/span&gt;
    &lt;span class="nx"&gt;type&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"region"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Google Cloud region"&lt;/span&gt;
    &lt;span class="nx"&gt;type&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
    &lt;span class="nx"&gt;default&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"europe-west2"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"machine_type"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Google VM Instance type."&lt;/span&gt;
    &lt;span class="nx"&gt;type&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; We are defining a &lt;code&gt;default&lt;/code&gt; value for &lt;code&gt;region&lt;/code&gt;. This means if a value is not supplied for this variable, Terraform will use &lt;code&gt;europe-west2&lt;/code&gt; as its value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Create a &lt;code&gt;tfvars&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  vi terraform.tfvars
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;  &lt;span class="nx"&gt;project_id&lt;/span&gt;   &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;                     &lt;span class="c1"&gt;# Put GCP Project ID.&lt;/span&gt;
  &lt;span class="nx"&gt;machine_type&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"n1-standard-1"&lt;/span&gt;        &lt;span class="c1"&gt;# Put the desired VM Instance type.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Set the remote state.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  vi backend.tf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;  &lt;span class="nx"&gt;terraform&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;backend&lt;/span&gt; &lt;span class="s2"&gt;"gcs"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;bucket&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"my-tfstate-bucket"&lt;/span&gt;    &lt;span class="c1"&gt;# GCS bucket name to store terraform tfstate&lt;/span&gt;
      &lt;span class="nx"&gt;prefix&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"gke-cluster"&lt;/span&gt;          &lt;span class="c1"&gt;# Update to desired prefix name. Prefix name should be unique for each Terraform project having same remote state bucket.&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; File structure looks like below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  cntekio:~ terraform-gke-example&lt;span class="nv"&gt;$ &lt;/span&gt;tree
  &lt;span class="nb"&gt;.&lt;/span&gt;
  ├── backend.tf
  ├── gke.tf
  ├── terraform.tfvars
  └── variables.tf

  0 directories, 4 files
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 7:&lt;/strong&gt; Now, initialize the terraform project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  terraform init
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  Initializing the backend...

  Successfully configured the backend &lt;span class="s2"&gt;"gcs"&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; Terraform will automatically
  use this backend unless the backend configuration changes.

  Initializing provider plugins...
  - Checking &lt;span class="k"&gt;for &lt;/span&gt;available provider plugins...
  - Downloading plugin &lt;span class="k"&gt;for &lt;/span&gt;provider &lt;span class="s2"&gt;"google-beta"&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;terraform-providers/google-beta&lt;span class="o"&gt;)&lt;/span&gt; 3.10.0...

  Terraform has been successfully initialized!

  You may now begin working with Terraform. Try running &lt;span class="s2"&gt;"terraform plan"&lt;/span&gt; to see
  any changes that are required &lt;span class="k"&gt;for &lt;/span&gt;your infrastructure. All Terraform commands
  should now work.

  If you ever &lt;span class="nb"&gt;set &lt;/span&gt;or change modules or backend configuration &lt;span class="k"&gt;for &lt;/span&gt;Terraform,
  rerun this &lt;span class="nb"&gt;command &lt;/span&gt;to reinitialize your working directory. If you forget, other
  commands will detect it and remind you to &lt;span class="k"&gt;do &lt;/span&gt;so &lt;span class="k"&gt;if &lt;/span&gt;necessary.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;code&gt;terraform init&lt;/code&gt; downloads all the required provider and plugins.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 8:&lt;/strong&gt; Let's see the execution plan.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  terraform plan &lt;span class="nt"&gt;--out&lt;/span&gt; 1.plan
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  Refreshing Terraform state &lt;span class="k"&gt;in&lt;/span&gt;&lt;span class="nt"&gt;-memory&lt;/span&gt; prior to plan...
  The refreshed state will be used to calculate this plan, but will not be
  persisted to &lt;span class="nb"&gt;local &lt;/span&gt;or remote state storage.

  &lt;span class="nt"&gt;------------------------------------------------------------------------&lt;/span&gt;

  An execution plan has been generated and is shown below.
  Resource actions are indicated with the following symbols:
    + create

  Terraform will perform the following actions:

    &lt;span class="c"&gt;# google_container_cluster.my_k8s_cluster will be created&lt;/span&gt;
    + resource &lt;span class="s2"&gt;"google_container_cluster"&lt;/span&gt; &lt;span class="s2"&gt;"my_k8s_cluster"&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        + additional_zones            &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + cluster_ipv4_cidr           &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + default_max_pods_per_node   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + enable_binary_authorization &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;
        + enable_intranode_visibility &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;
        + enable_kubernetes_alpha     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;
        + enable_legacy_abac          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;
        + enable_shielded_nodes       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;
        + enable_tpu                  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;
        + endpoint                    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + &lt;span class="nb"&gt;id&lt;/span&gt;                          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + initial_node_count          &lt;span class="o"&gt;=&lt;/span&gt; 1
        + instance_group_urls         &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + label_fingerprint           &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + location                    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"europe-west2"&lt;/span&gt;
        + logging_service             &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"logging.googleapis.com/kubernetes"&lt;/span&gt;
        + master_version              &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + monitoring_service          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"monitoring.googleapis.com/kubernetes"&lt;/span&gt;
        + name                        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"my-k8s-cluster"&lt;/span&gt;
        + network                     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"default"&lt;/span&gt;
        + node_locations              &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + node_version                &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + operation                   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + project                     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + region                      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + services_ipv4_cidr          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + subnetwork                  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + tpu_ipv4_cidr_block         &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + zone                        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;

        + addons_config &lt;span class="o"&gt;{&lt;/span&gt;
            + cloudrun_config &lt;span class="o"&gt;{&lt;/span&gt;
                + disabled &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
              &lt;span class="o"&gt;}&lt;/span&gt;

            + horizontal_pod_autoscaling &lt;span class="o"&gt;{&lt;/span&gt;
                + disabled &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
              &lt;span class="o"&gt;}&lt;/span&gt;

            + http_load_balancing &lt;span class="o"&gt;{&lt;/span&gt;
                + disabled &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
              &lt;span class="o"&gt;}&lt;/span&gt;

            + istio_config &lt;span class="o"&gt;{&lt;/span&gt;
                + auth     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + disabled &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
              &lt;span class="o"&gt;}&lt;/span&gt;

            + kubernetes_dashboard &lt;span class="o"&gt;{&lt;/span&gt;
                + disabled &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
              &lt;span class="o"&gt;}&lt;/span&gt;

            + network_policy_config &lt;span class="o"&gt;{&lt;/span&gt;
                + disabled &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
              &lt;span class="o"&gt;}&lt;/span&gt;
          &lt;span class="o"&gt;}&lt;/span&gt;

        + authenticator_groups_config &lt;span class="o"&gt;{&lt;/span&gt;
            + security_group &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
          &lt;span class="o"&gt;}&lt;/span&gt;

        + cluster_autoscaling &lt;span class="o"&gt;{&lt;/span&gt;
            + autoscaling_profile &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + enabled             &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;

            + auto_provisioning_defaults &lt;span class="o"&gt;{&lt;/span&gt;
                + oauth_scopes    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + service_account &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
              &lt;span class="o"&gt;}&lt;/span&gt;

            + resource_limits &lt;span class="o"&gt;{&lt;/span&gt;
                + maximum       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + minimum       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + resource_type &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
              &lt;span class="o"&gt;}&lt;/span&gt;
          &lt;span class="o"&gt;}&lt;/span&gt;

        + database_encryption &lt;span class="o"&gt;{&lt;/span&gt;
            + key_name &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + state    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
          &lt;span class="o"&gt;}&lt;/span&gt;

        + master_auth &lt;span class="o"&gt;{&lt;/span&gt;
            + client_certificate     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + client_key             &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;sensitive value&lt;span class="o"&gt;)&lt;/span&gt;
            + cluster_ca_certificate &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;

            + client_certificate_config &lt;span class="o"&gt;{&lt;/span&gt;
                + issue_client_certificate &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
              &lt;span class="o"&gt;}&lt;/span&gt;
          &lt;span class="o"&gt;}&lt;/span&gt;

        + network_policy &lt;span class="o"&gt;{&lt;/span&gt;
            + enabled  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + provider &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
          &lt;span class="o"&gt;}&lt;/span&gt;

        + node_config &lt;span class="o"&gt;{&lt;/span&gt;
            + disk_size_gb      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + disk_type         &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + guest_accelerator &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + image_type        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + labels            &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                + &lt;span class="s2"&gt;"environment"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"test"&lt;/span&gt;
                + &lt;span class="s2"&gt;"team"&lt;/span&gt;        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"devops"&lt;/span&gt;
              &lt;span class="o"&gt;}&lt;/span&gt;
            + local_ssd_count   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + machine_type      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"n1-standard-1"&lt;/span&gt;
            + metadata          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                + &lt;span class="s2"&gt;"disable-legacy-endpoints"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"true"&lt;/span&gt;
              &lt;span class="o"&gt;}&lt;/span&gt;
            + oauth_scopes      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;
                + &lt;span class="s2"&gt;"https://www.googleapis.com/auth/logging.write"&lt;/span&gt;,
                + &lt;span class="s2"&gt;"https://www.googleapis.com/auth/monitoring"&lt;/span&gt;,
              &lt;span class="o"&gt;]&lt;/span&gt;
            + preemptible       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;
            + service_account   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + taint             &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;

            + shielded_instance_config &lt;span class="o"&gt;{&lt;/span&gt;
                + enable_integrity_monitoring &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + enable_secure_boot          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
              &lt;span class="o"&gt;}&lt;/span&gt;

            + workload_metadata_config &lt;span class="o"&gt;{&lt;/span&gt;
                + node_metadata &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"GKE_METADATA_SERVER"&lt;/span&gt;
              &lt;span class="o"&gt;}&lt;/span&gt;
          &lt;span class="o"&gt;}&lt;/span&gt;

        + node_pool &lt;span class="o"&gt;{&lt;/span&gt;
            + initial_node_count  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + instance_group_urls &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + max_pods_per_node   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + name                &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + name_prefix         &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + node_count          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + node_locations      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + version             &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;

            + autoscaling &lt;span class="o"&gt;{&lt;/span&gt;
                + max_node_count &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + min_node_count &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
              &lt;span class="o"&gt;}&lt;/span&gt;

            + management &lt;span class="o"&gt;{&lt;/span&gt;
                + auto_repair  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + auto_upgrade &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
              &lt;span class="o"&gt;}&lt;/span&gt;

            + node_config &lt;span class="o"&gt;{&lt;/span&gt;
                + boot_disk_kms_key &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + disk_size_gb      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + disk_type         &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + guest_accelerator &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + image_type        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + labels            &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + local_ssd_count   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + machine_type      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + metadata          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + min_cpu_platform  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + oauth_scopes      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + preemptible       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + service_account   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + tags              &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + taint             &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;

                + sandbox_config &lt;span class="o"&gt;{&lt;/span&gt;
                    + sandbox_type &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                  &lt;span class="o"&gt;}&lt;/span&gt;

                + shielded_instance_config &lt;span class="o"&gt;{&lt;/span&gt;
                    + enable_integrity_monitoring &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                    + enable_secure_boot          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                  &lt;span class="o"&gt;}&lt;/span&gt;

                + workload_metadata_config &lt;span class="o"&gt;{&lt;/span&gt;
                    + node_metadata &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                  &lt;span class="o"&gt;}&lt;/span&gt;
              &lt;span class="o"&gt;}&lt;/span&gt;

            + upgrade_settings &lt;span class="o"&gt;{&lt;/span&gt;
                + max_surge       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + max_unavailable &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
              &lt;span class="o"&gt;}&lt;/span&gt;
          &lt;span class="o"&gt;}&lt;/span&gt;

        + release_channel &lt;span class="o"&gt;{&lt;/span&gt;
            + channel &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
          &lt;span class="o"&gt;}&lt;/span&gt;

        + workload_identity_config &lt;span class="o"&gt;{&lt;/span&gt;
            + identity_namespace &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"workshop-demo-adqw12.svc.id.goog"&lt;/span&gt;
          &lt;span class="o"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;}&lt;/span&gt;
    Plan: 1 to add, 0 to change, 0 to destroy.
  &lt;span class="nt"&gt;------------------------------------------------------------------------&lt;/span&gt;
  This plan was saved to: 1.plan

  To perform exactly these actions, run the following &lt;span class="nb"&gt;command &lt;/span&gt;to apply:
      terraform apply &lt;span class="s2"&gt;"1.plan"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;code&gt;terraform plan&lt;/code&gt; output shows that this code is going to a GKE cluster.&lt;br&gt;
&lt;code&gt;--out 1.plan&lt;/code&gt; flag tells terraform to save the plan in a file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 9:&lt;/strong&gt; The execution plan looks good, so let's move ahead and apply this plan.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  terraform apply 1.plan
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  google_container_cluster.my_k8s_cluster: Creating...
  google_container_cluster.my_k8s_cluster: Still creating... &lt;span class="o"&gt;[&lt;/span&gt;10s elapsed]
  google_container_cluster.my_k8s_cluster: Still creating... &lt;span class="o"&gt;[&lt;/span&gt;1m10s elapsed]
  google_container_cluster.my_k8s_cluster: Still creating... &lt;span class="o"&gt;[&lt;/span&gt;2m10s elapsed]
  google_container_cluster.my_k8s_cluster: Still creating... &lt;span class="o"&gt;[&lt;/span&gt;3m20s elapsed]
  google_container_cluster.my_k8s_cluster: Creation &lt;span class="nb"&gt;complete &lt;/span&gt;after 3m23s &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;projects/workshop-demo-adqw12/locations/europe-west2/clusters/my-k8s-cluster]

  Apply &lt;span class="nb"&gt;complete&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; Resources: 1 added, 0 changed, 0 destroyed.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;em&gt;Creating a GKE cluster could take 4-7mins.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 10:&lt;/strong&gt; Let's connect with GKE cluster.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  gcloud container clusters get-credentials my-k8s-cluster &lt;span class="nt"&gt;--region&lt;/span&gt; europe-west2 &lt;span class="nt"&gt;--project&lt;/span&gt; workshop-demo-adqw12
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  Fetching cluster endpoint and auth data.
  kubeconfig entry generated for my-k8s-cluster.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 11:&lt;/strong&gt; Now, run kubectl version command to check server version.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  kubectl version
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  Client Version: version.Info{Major:"1", Minor:"14+", GitVersion:"v1.14.10-dispatcher", GitCommit:"f5757a1dee5a89cc5e29cd7159076648bf21a02b", GitTreeState:"clean", BuildDate:"2020-02-06T03:31:35Z", GoVersion:"go1.12.12b4", Compiler:"gc", Platform:"darwin/amd64"}
  Server Version: version.Info{Major:"1", Minor:"14+", GitVersion:"v1.14.10-gke.17", GitCommit:"bdceba0734835c6cb1acbd1c447caf17d8613b44", GitTreeState:"clean", BuildDate:"2020-01-17T23:10:13Z", GoVersion:"go1.12.12b4", Compiler:"gc", Platform:"linux/amd64"}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 12:&lt;/strong&gt; Now, we will move to Google Cloud Platform Console to view GKE cluster properties.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5VmSzL7t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8i0ma6zkvpdlqnr5acf8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5VmSzL7t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8i0ma6zkvpdlqnr5acf8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WCP3ls1v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7ptpeojpbi9psgnvnnr4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WCP3ls1v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7ptpeojpbi9psgnvnnr4.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 13:&lt;/strong&gt; Once we no longer need this infrastructure, we can cleanup to reduce costs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  terraform destroy
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;    google_container_cluster.my_k8s_cluster: Refreshing state... &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;projects/workshop-demo-adqw12/locations/europe-west2/clusters/my-k8s-cluster]

    An execution plan has been generated and is shown below.
    Resource actions are indicated with the following symbols:
      - destroy

    Terraform will perform the following actions:

      &lt;span class="c"&gt;# google_container_cluster.my_k8s_cluster will be destroyed&lt;/span&gt;
      - resource &lt;span class="s2"&gt;"google_container_cluster"&lt;/span&gt; &lt;span class="s2"&gt;"my_k8s_cluster"&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
          - additional_zones            &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[]&lt;/span&gt; -&amp;gt; null
          - cluster_ipv4_cidr           &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"10.0.0.0/14"&lt;/span&gt; -&amp;gt; null
          - default_max_pods_per_node   &lt;span class="o"&gt;=&lt;/span&gt; 110 -&amp;gt; null
          - enable_binary_authorization &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt; -&amp;gt; null
          - enable_intranode_visibility &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt; -&amp;gt; null
          - enable_kubernetes_alpha     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt; -&amp;gt; null
          - enable_legacy_abac          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt; -&amp;gt; null
          - enable_shielded_nodes       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt; -&amp;gt; null
          - enable_tpu                  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt; -&amp;gt; null
          - endpoint                    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"34.89.124.93"&lt;/span&gt; -&amp;gt; null
          - &lt;span class="nb"&gt;id&lt;/span&gt;                          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"projects/workshop-demo-adqw12/locations/europe-west2/clusters/my-k8s-cluster"&lt;/span&gt; -&amp;gt; null
          - initial_node_count          &lt;span class="o"&gt;=&lt;/span&gt; 1 -&amp;gt; null
          - instance_group_urls         &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;
              - &lt;span class="s2"&gt;"https://www.googleapis.com/compute/beta/projects/workshop-demo-adqw12/zones/europe-west2-c/instanceGroups/gke-my-k8s-cluster-default-pool-7dc4a362-grp"&lt;/span&gt;,
              - &lt;span class="s2"&gt;"https://www.googleapis.com/compute/beta/projects/workshop-demo-adqw12/zones/europe-west2-b/instanceGroups/gke-my-k8s-cluster-default-pool-0538b086-grp"&lt;/span&gt;,
              - &lt;span class="s2"&gt;"https://www.googleapis.com/compute/beta/projects/workshop-demo-adqw12/zones/europe-west2-a/instanceGroups/gke-my-k8s-cluster-default-pool-858715ad-grp"&lt;/span&gt;,
            &lt;span class="o"&gt;]&lt;/span&gt; -&amp;gt; null
          - label_fingerprint           &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"a9dc16a7"&lt;/span&gt; -&amp;gt; null
          - location                    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"europe-west2"&lt;/span&gt; -&amp;gt; null
          - logging_service             &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"logging.googleapis.com/kubernetes"&lt;/span&gt; -&amp;gt; null
          - master_version              &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"1.14.10-gke.17"&lt;/span&gt; -&amp;gt; null
          - monitoring_service          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"monitoring.googleapis.com/kubernetes"&lt;/span&gt; -&amp;gt; null
          - name                        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"my-k8s-cluster"&lt;/span&gt; -&amp;gt; null
          - network                     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"projects/workshop-demo-adqw12/global/networks/default"&lt;/span&gt; -&amp;gt; null
          - node_locations              &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;
              - &lt;span class="s2"&gt;"europe-west2-a"&lt;/span&gt;,
              - &lt;span class="s2"&gt;"europe-west2-b"&lt;/span&gt;,
              - &lt;span class="s2"&gt;"europe-west2-c"&lt;/span&gt;,
            &lt;span class="o"&gt;]&lt;/span&gt; -&amp;gt; null
          - node_version                &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"1.14.10-gke.17"&lt;/span&gt; -&amp;gt; null
          - project                     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"workshop-demo-adqw12"&lt;/span&gt; -&amp;gt; null
          - resource_labels             &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{}&lt;/span&gt; -&amp;gt; null
          - services_ipv4_cidr          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"10.3.240.0/20"&lt;/span&gt; -&amp;gt; null
          - subnetwork                  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"projects/workshop-demo-adqw12/regions/europe-west2/subnetworks/default"&lt;/span&gt; -&amp;gt; null

          - addons_config &lt;span class="o"&gt;{&lt;/span&gt;

              - network_policy_config &lt;span class="o"&gt;{&lt;/span&gt;
                  - disabled &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt; -&amp;gt; null
                &lt;span class="o"&gt;}&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;

          - cluster_autoscaling &lt;span class="o"&gt;{&lt;/span&gt;
              - autoscaling_profile &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"BALANCED"&lt;/span&gt; -&amp;gt; null
              - enabled             &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt; -&amp;gt; null
            &lt;span class="o"&gt;}&lt;/span&gt;

          - database_encryption &lt;span class="o"&gt;{&lt;/span&gt;
              - state &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"DECRYPTED"&lt;/span&gt; -&amp;gt; null
            &lt;span class="o"&gt;}&lt;/span&gt;

          - master_auth &lt;span class="o"&gt;{&lt;/span&gt;
              - cluster_ca_certificate &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURERENDQWZTZ0F3SUJBZ0lSQVBmNzJzWRGZhd25uQUYvZz09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K"&lt;/span&gt; -&amp;gt; null

              - client_certificate_config &lt;span class="o"&gt;{&lt;/span&gt;
                  - issue_client_certificate &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt; -&amp;gt; null
                &lt;span class="o"&gt;}&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;

          - network_policy &lt;span class="o"&gt;{&lt;/span&gt;
              - enabled  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt; -&amp;gt; null
              - provider &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"PROVIDER_UNSPECIFIED"&lt;/span&gt; -&amp;gt; null
            &lt;span class="o"&gt;}&lt;/span&gt;

          - node_config &lt;span class="o"&gt;{&lt;/span&gt;
              - disk_size_gb      &lt;span class="o"&gt;=&lt;/span&gt; 100 -&amp;gt; null
              - disk_type         &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"pd-standard"&lt;/span&gt; -&amp;gt; null
              - guest_accelerator &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[]&lt;/span&gt; -&amp;gt; null
              - image_type        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"COS"&lt;/span&gt; -&amp;gt; null
              - labels            &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                  - &lt;span class="s2"&gt;"environment"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"test"&lt;/span&gt;
                  - &lt;span class="s2"&gt;"team"&lt;/span&gt;        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"devops"&lt;/span&gt;
                &lt;span class="o"&gt;}&lt;/span&gt; -&amp;gt; null
              - local_ssd_count   &lt;span class="o"&gt;=&lt;/span&gt; 0 -&amp;gt; null
              - machine_type      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"n1-standard-1"&lt;/span&gt; -&amp;gt; null
              - metadata          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                  - &lt;span class="s2"&gt;"disable-legacy-endpoints"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"true"&lt;/span&gt;
                &lt;span class="o"&gt;}&lt;/span&gt; -&amp;gt; null
              - oauth_scopes      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;
                  - &lt;span class="s2"&gt;"https://www.googleapis.com/auth/logging.write"&lt;/span&gt;,
                  - &lt;span class="s2"&gt;"https://www.googleapis.com/auth/monitoring"&lt;/span&gt;,
                &lt;span class="o"&gt;]&lt;/span&gt; -&amp;gt; null
              - preemptible       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt; -&amp;gt; null
              - service_account   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"default"&lt;/span&gt; -&amp;gt; null
              - tags              &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[]&lt;/span&gt; -&amp;gt; null
              - taint             &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[]&lt;/span&gt; -&amp;gt; null

              - shielded_instance_config &lt;span class="o"&gt;{&lt;/span&gt;
                  - enable_integrity_monitoring &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt; -&amp;gt; null
                  - enable_secure_boot          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt; -&amp;gt; null
                &lt;span class="o"&gt;}&lt;/span&gt;

              - workload_metadata_config &lt;span class="o"&gt;{&lt;/span&gt;
                  - node_metadata &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"GKE_METADATA_SERVER"&lt;/span&gt; -&amp;gt; null
                &lt;span class="o"&gt;}&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;

          - node_pool &lt;span class="o"&gt;{&lt;/span&gt;
              - initial_node_count  &lt;span class="o"&gt;=&lt;/span&gt; 1 -&amp;gt; null
              - instance_group_urls &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;
                  - &lt;span class="s2"&gt;"https://www.googleapis.com/compute/v1/projects/workshop-demo-adqw12/zones/europe-west2-c/instanceGroupManagers/gke-my-k8s-cluster-default-pool-7dc4a362-grp"&lt;/span&gt;,
                  - &lt;span class="s2"&gt;"https://www.googleapis.com/compute/v1/projects/workshop-demo-adqw12/zones/europe-west2-b/instanceGroupManagers/gke-my-k8s-cluster-default-pool-0538b086-grp"&lt;/span&gt;,
                  - &lt;span class="s2"&gt;"https://www.googleapis.com/compute/v1/projects/workshop-demo-adqw12/zones/europe-west2-a/instanceGroupManagers/gke-my-k8s-cluster-default-pool-858715ad-grp"&lt;/span&gt;,
                &lt;span class="o"&gt;]&lt;/span&gt; -&amp;gt; null
              - max_pods_per_node   &lt;span class="o"&gt;=&lt;/span&gt; 0 -&amp;gt; null
              - name                &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"default-pool"&lt;/span&gt; -&amp;gt; null
              - node_count          &lt;span class="o"&gt;=&lt;/span&gt; 1 -&amp;gt; null
              - node_locations      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;
                  - &lt;span class="s2"&gt;"europe-west2-a"&lt;/span&gt;,
                  - &lt;span class="s2"&gt;"europe-west2-b"&lt;/span&gt;,
                  - &lt;span class="s2"&gt;"europe-west2-c"&lt;/span&gt;,
                &lt;span class="o"&gt;]&lt;/span&gt; -&amp;gt; null
              - version             &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"1.14.10-gke.17"&lt;/span&gt; -&amp;gt; null

              - management &lt;span class="o"&gt;{&lt;/span&gt;
                  - auto_repair  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt; -&amp;gt; null
                  - auto_upgrade &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt; -&amp;gt; null
                &lt;span class="o"&gt;}&lt;/span&gt;

              - node_config &lt;span class="o"&gt;{&lt;/span&gt;
                  - disk_size_gb      &lt;span class="o"&gt;=&lt;/span&gt; 100 -&amp;gt; null
                  - disk_type         &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"pd-standard"&lt;/span&gt; -&amp;gt; null
                  - guest_accelerator &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[]&lt;/span&gt; -&amp;gt; null
                  - image_type        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"COS"&lt;/span&gt; -&amp;gt; null
                  - labels            &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                      - &lt;span class="s2"&gt;"environment"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"test"&lt;/span&gt;
                      - &lt;span class="s2"&gt;"team"&lt;/span&gt;        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"devops"&lt;/span&gt;
                    &lt;span class="o"&gt;}&lt;/span&gt; -&amp;gt; null
                  - local_ssd_count   &lt;span class="o"&gt;=&lt;/span&gt; 0 -&amp;gt; null
                  - machine_type      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"n1-standard-1"&lt;/span&gt; -&amp;gt; null
                  - metadata          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
                      - &lt;span class="s2"&gt;"disable-legacy-endpoints"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"true"&lt;/span&gt;
                    &lt;span class="o"&gt;}&lt;/span&gt; -&amp;gt; null
                  - oauth_scopes      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;
                      - &lt;span class="s2"&gt;"https://www.googleapis.com/auth/logging.write"&lt;/span&gt;,
                      - &lt;span class="s2"&gt;"https://www.googleapis.com/auth/monitoring"&lt;/span&gt;,
                    &lt;span class="o"&gt;]&lt;/span&gt; -&amp;gt; null
                  - preemptible       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt; -&amp;gt; null
                  - service_account   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"default"&lt;/span&gt; -&amp;gt; null
                  - tags              &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[]&lt;/span&gt; -&amp;gt; null
                  - taint             &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[]&lt;/span&gt; -&amp;gt; null

                  - shielded_instance_config &lt;span class="o"&gt;{&lt;/span&gt;
                      - enable_integrity_monitoring &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt; -&amp;gt; null
                      - enable_secure_boot          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt; -&amp;gt; null
                    &lt;span class="o"&gt;}&lt;/span&gt;

                  - workload_metadata_config &lt;span class="o"&gt;{&lt;/span&gt;
                      - node_metadata &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"GKE_METADATA_SERVER"&lt;/span&gt; -&amp;gt; null
                    &lt;span class="o"&gt;}&lt;/span&gt;
                &lt;span class="o"&gt;}&lt;/span&gt;
            &lt;span class="o"&gt;}&lt;/span&gt;

          - release_channel &lt;span class="o"&gt;{&lt;/span&gt;
              - channel &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"UNSPECIFIED"&lt;/span&gt; -&amp;gt; null
            &lt;span class="o"&gt;}&lt;/span&gt;

          - workload_identity_config &lt;span class="o"&gt;{&lt;/span&gt;
              - identity_namespace &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"workshop-demo-adqw12.svc.id.goog"&lt;/span&gt; -&amp;gt; null
            &lt;span class="o"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;

    Plan: 0 to add, 0 to change, 1 to destroy.

    Do you really want to destroy all resources?
      Terraform will destroy all your managed infrastructure, as shown above.
      There is no undo. Only &lt;span class="s1"&gt;'yes'&lt;/span&gt; will be accepted to confirm.

      Enter a value: &lt;span class="nb"&gt;yes

    &lt;/span&gt;google_container_cluster.my_k8s_cluster: Destroying... &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;projects/workshop-demo-adqw12/locations/europe-west2/clusters/my-k8s-cluster]
    google_container_cluster.my_k8s_cluster: Still destroying... &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;projects/workshop-demo-adqw12/locations/europe-west2/clusters/my-k8s-cluster, 10s elapsed]
    google_container_cluster.my_k8s_cluster: Still destroying... &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;projects/workshop-demo-adqw12/locations/europe-west2/clusters/my-k8s-cluster, 1m10s elapsed]
    google_container_cluster.my_k8s_cluster: Still destroying... &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;projects/workshop-demo-adqw12/locations/europe-west2/clusters/my-k8s-cluster, 2m40s elapsed]
    google_container_cluster.my_k8s_cluster: Destruction &lt;span class="nb"&gt;complete &lt;/span&gt;after 2m41s

    Destroy &lt;span class="nb"&gt;complete&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; Resources: 1 destroyed.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Hope this blog helps you build GKE Cluster Terraform.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you have a feedback or questions, please reach out to me on &lt;a href="https://linkedin.com/in/pradeepbhadani"&gt;LinkedIn&lt;/a&gt; or &lt;a href="https://twitter.com/bhadanipradeep"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>gcp</category>
      <category>kubernetes</category>
      <category>cloud</category>
      <category>devops</category>
    </item>
    <item>
      <title>How I passed Google Cloud Professional Cloud Architect Certificate</title>
      <dc:creator>Pradeep Bhadani</dc:creator>
      <pubDate>Fri, 14 Feb 2020 17:13:03 +0000</pubDate>
      <link>https://forem.com/pradeepbhadani/how-i-passed-google-cloud-professional-cloud-architect-certificate-2626</link>
      <guid>https://forem.com/pradeepbhadani/how-i-passed-google-cloud-professional-cloud-architect-certificate-2626</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://pbhadani.com/posts/gcp-pca-certification/"&gt;pbhadani.com&lt;/a&gt;&lt;/em&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;I recently passed my &lt;a href="https://www.credential.net/3c4d5bdb-08c8-45b8-9406-e3311cbb4c13"&gt;Google Cloud Certified Professional Cloud Architect&lt;/a&gt; exam and many people asked for the preparation path I took for this exam. So, I thought of putting things together in a blog that can help others.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5zBg9jMj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0v3yp3zlshgdhz1ogfkb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5zBg9jMj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0v3yp3zlshgdhz1ogfkb.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Exam Overview
&lt;/h2&gt;

&lt;p&gt;At the time of writing this blog, &lt;a href="https://cloud.google.com/certification/cloud-architect"&gt;Professional Cloud Architect&lt;/a&gt; exam is of 2-hrs in duration and 50 questions.&lt;br&gt;
There is no official passing score published by Google so at the end of the exam it only provides &lt;strong&gt;Pass/Fail&lt;/strong&gt; as a result. However, it is assumed that roughly 80% is required to &lt;strong&gt;pass&lt;/strong&gt; the exam based on various blogs and training providers.&lt;br&gt;&lt;br&gt;
I would suggest reading the &lt;a href="https://cloud.google.com/certification/cloud-architect"&gt;official certification guide&lt;/a&gt; before starting to prepare for the exam.&lt;/p&gt;

&lt;h2&gt;
  
  
  How I prepared?
&lt;/h2&gt;

&lt;p&gt;There are no prerequisites for this exam. But I did the &lt;a href="https://cloud.google.com/certification/cloud-engineer"&gt;Associate Cloud Engineer&lt;/a&gt; exam before I took the Professional one. Also, I have been working with GCP Services for more than 3-years which also helped me.&lt;/p&gt;

&lt;p&gt;To be honest, getting this certificate is not an easy task and requires good preparation. I will share some key points which helped me pass the exam:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Courses:&lt;/em&gt;&lt;/strong&gt; There are many courses that are structured to gain the knowledge that covers the exam topics. Therefore, following a course helps to learn GCP in a structured way. I decided to do the &lt;em&gt;Coursera Courses&lt;/em&gt; - &lt;a href="https://www.coursera.org/specializations/gcp-architecture"&gt;Architecting with Google Compute Engine Specialization&lt;/a&gt; and &lt;a href="https://www.coursera.org/learn/preparing-cloud-professional-cloud-architect-exam/"&gt;Preparing for the Google Cloud Professional Cloud Architect Exam&lt;/a&gt;. Many blogs and online communities also suggested to do the &lt;a href="https://acloudguru.com/course/google-cloud-certified-professional-cloud-architect-la"&gt;Linux Academy Course&lt;/a&gt; but due to time constraints, I could not go through much.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Hands-On Labs:&lt;/em&gt;&lt;/strong&gt; Hands-on Labs which comes with the Coursera course help greatly in understanding and implementing the concepts and GCP services. I would suggest putting a great focus on Hands-on labs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Play with GCP:&lt;/em&gt;&lt;/strong&gt; Addition to hands-on labs, I played with different GCP services to get a deeper knowledge.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Case Studies:&lt;/em&gt;&lt;/strong&gt; There were questions from case studies (roughly 25%) and understanding the case studies before exam saves a good time in the exam.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Practice Tests:&lt;/em&gt;&lt;/strong&gt; Google provides a small &lt;a href="https://cloud.google.com/certification/practice-exam/cloud-architect/"&gt;practice test&lt;/a&gt; that help to get an understanding of your readiness. Above mentioned Linux Academy course also offers a practice test. After finishing the courses and labs, I took practice tests and I was able to get 90-95% consistently.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Industry experience:&lt;/em&gt;&lt;/strong&gt; I have been working with Cloud technologies like AWS and GCP and that helped greatly in understanding the scenario-based questions and choosing the best option for a particular situation.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Last, I suggest getting a deep understanding of core concepts like Google Networking, Cloud IAM, BigQuery, Storage, Kubernetes, and App Engine. Exam questions are not limited to the above topics, but understanding core concepts gives good confidence.&lt;/p&gt;

&lt;p&gt;I wish all the best to everyone preparing for this exam and would be glad to hear about your experience.&lt;br&gt;&lt;br&gt;
My &lt;a href="https://linkedin.com/in/pradeepbhadani"&gt;LinkedIn&lt;/a&gt; and &lt;a href="https://twitter.com/bhadanipradeep"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>gcp</category>
      <category>architecture</category>
      <category>cloud</category>
      <category>certification</category>
    </item>
    <item>
      <title>Let Google do Secret Management</title>
      <dc:creator>Pradeep Bhadani</dc:creator>
      <pubDate>Wed, 29 Jan 2020 23:20:00 +0000</pubDate>
      <link>https://forem.com/pradeepbhadani/let-google-do-secret-management-57j</link>
      <guid>https://forem.com/pradeepbhadani/let-google-do-secret-management-57j</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://pbhadani.com/posts/google-secret-manager/"&gt;pbhadani.com&lt;/a&gt;&lt;/em&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;Updated on August 15, 2022&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;In this post, I will talk about Google's &lt;a href="https://cloud.google.com/secret-manager/"&gt;Secret Manager&lt;/a&gt; service and show how easy is to manage passwords/tokens in GCP.&lt;/p&gt;
&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;Managing secrets and sharing secrets(like database passwords, tokens, etc..) is a hard problem and failing to secure tokens can lead to some serious issues.  &lt;/p&gt;

&lt;p&gt;An example scenario - When an application is being developed, it might need to connect to a database or need some certificates or need tokens(for example, Slack token) to make API calls. It is not a good practice to put these secret keys in Source code as they live their forever and visible to all people who have access to the source code. Sometimes, developers keep these keys in a separate local file (added to .gitignore) and share these keys using different methods like Slack chat, Email, etc.. This approach is still not good as secret tokens are in plain text and scattered between team members. How do you manage a situation when a team member moves to a different team or different place? It is difficult to rotate keys and share it again with all the required team members.  &lt;/p&gt;

&lt;p&gt;You can read more about why secret keys should live separate than code at &lt;a href="https://12factor.net/config"&gt;12factor.net&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;The solution to this problem is Secret Management tools like &lt;a href="https://www.vaultproject.io/"&gt;Hashicorp Vault&lt;/a&gt;, &lt;a href="https://github.com/GoogleCloudPlatform/berglas"&gt;Berglas&lt;/a&gt;, &lt;a href="https://cloud.google.com/secret-manager/"&gt;Google Secret Manager&lt;/a&gt;, &lt;a href="https://aws.amazon.com/secrets-manager/"&gt;AWS Secret Manager&lt;/a&gt;, etc.&lt;br&gt;
One of the popular tools out there is Hashicorp Vault but a team has to setup and manage the own infrastructure.&lt;/p&gt;

&lt;p&gt;In this post, we will learn about Google managed secret management solution - &lt;a href="https://cloud.google.com/secret-manager/"&gt;Secret Manager&lt;/a&gt; and see how easy is to store and retrieve keys and passwords.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is Secret Manager?
&lt;/h2&gt;

&lt;p&gt;Google Secret Manager is a recent addition to Google Cloud Platform which can store API Keys, passwords, certificates, sensitive strings, etc...&lt;br&gt;
You can read the Google Secret Manager's release notes &lt;a href="https://cloud.google.com/secret-manager/docs/release-notes"&gt;here&lt;/a&gt; and pricing &lt;a href="https://cloud.google.com/secret-manager/pricing"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Google Secret Manager's access control is integrated with Cloud IAM and a project owner can control who can read the secrets.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;roles/secretmanager.admin&lt;/strong&gt; : This role gives full access to administer the Secret. A person(or service account) with this role can perform CRUD(Create, Read, Update and Delete) operations on the Secrets.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;roles/secretmanager.secretAccessor&lt;/strong&gt; : This role provides access to read the Secret. A person(or service account) with this role can read the secret value store like API key.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;roles/secretmanager.viewer&lt;/strong&gt;: This role provides access to view the metadata of the Secret. A person(or service account) with this role can read the secret metadata but not the value stored.&lt;/p&gt;

&lt;p&gt;Now that we are familiar with Google Secret Manager, let's interact with this service.&lt;/p&gt;
&lt;h2&gt;
  
  
  Interacting with Secret Manager
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;This post assumes the following:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We already have a GCP Project with the Project Owner role.
&lt;/li&gt;
&lt;li&gt;Google Cloud SDK (&lt;code&gt;gcloud&lt;/code&gt;) is setup on your workstation. If you don't have, then refer to my previous blogs - &lt;a href="https://pbhadani.com/posts/getting-started-wth-google-cloud-sdk/"&gt;Getting started with Google Cloud SDK&lt;/a&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: You can also use &lt;a href="https://cloud.google.com/shell/"&gt;Google Cloud Shell&lt;/a&gt; to run the &lt;code&gt;gcloud&lt;/code&gt; commands.&lt;/p&gt;
&lt;h3&gt;
  
  
  Enabling the Secret API
&lt;/h3&gt;

&lt;p&gt;To interact with Google Secret Manager, we need to enable this API.&lt;br&gt;&lt;br&gt;
Run the following command to enable this API.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;gcloud services &lt;span class="nb"&gt;enable &lt;/span&gt;secretmanager.googleapis.com &lt;span class="nt"&gt;--project&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;workshop-demo-23345
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Operation &lt;span class="s2"&gt;"operations/acf.xxxxxxf-xxxx-xxxx-xxxx-xxxxxxx"&lt;/span&gt; finished successfully.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create a Secret
&lt;/h3&gt;

&lt;p&gt;Run the following &lt;code&gt;gcloud&lt;/code&gt; command to create a secret.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud secrets create demo-secret &lt;span class="nt"&gt;--replication-policy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"automatic"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Created secret &lt;span class="o"&gt;[&lt;/span&gt;demo-secret].
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;This has created an empty secret that can hold multiple secret versions (actual sensitive information).
&lt;/li&gt;
&lt;li&gt;In this example, we used &lt;code&gt;--replication-policy&lt;/code&gt; as &lt;code&gt;automatic&lt;/code&gt; but can be &lt;code&gt;user-managed&lt;/code&gt; to specify the location you want to put your secret in.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Add values to Secret
&lt;/h3&gt;

&lt;p&gt;Secret Version contains the actual sensitive value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"my_super_secret_string"&lt;/span&gt; | gcloud secrets versions add &lt;span class="s1"&gt;'demo-secret'&lt;/span&gt; &lt;span class="nt"&gt;--data-file&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;-
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Created version &lt;span class="o"&gt;[&lt;/span&gt;1] of the secret &lt;span class="o"&gt;[&lt;/span&gt;demo-secret].
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Adding another version or updating the secret value&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"secret_update"&lt;/span&gt; | gcloud secrets versions add &lt;span class="s1"&gt;'demo-secret'&lt;/span&gt; &lt;span class="nt"&gt;--data-file&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;-
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Created version &lt;span class="o"&gt;[&lt;/span&gt;2] of the secret &lt;span class="o"&gt;[&lt;/span&gt;demo-secret].
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Read the Secret value
&lt;/h3&gt;

&lt;p&gt;We can access the latest or specific secret version &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Access the latest secret version&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud secrets versions access latest &lt;span class="nt"&gt;--secret&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'demo-secret'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;secret_update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Access specific secret version&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud secrets versions access 1 &lt;span class="nt"&gt;--secret&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'demo-secret'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;my_super_secret_string
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Never print the secret value in an application.&lt;/p&gt;

&lt;p&gt;We can similarly, use the &lt;code&gt;gcloud&lt;/code&gt; command or client libraries within the application to fetch the secret value when required instead of putting in source code or in some kind of property file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Google Secret Manager enables developers to store and share the API Keys, passwords, etc in an easy fashion without having to manage tools like Vault, etc...&lt;/p&gt;

&lt;p&gt;If you have feedback or questions, please reach out to me on &lt;a href="https://linkedin.com/in/pradeepbhadani"&gt;LinkedIn&lt;/a&gt; or &lt;a href="https://twitter.com/bhadanipradeep"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devops</category>
      <category>security</category>
      <category>gcp</category>
    </item>
    <item>
      <title>Deploy Web Server on Google Compute Engine (GCE) with Terraform</title>
      <dc:creator>Pradeep Bhadani</dc:creator>
      <pubDate>Mon, 13 Jan 2020 21:26:08 +0000</pubDate>
      <link>https://forem.com/pradeepbhadani/deploy-web-server-on-google-compute-engine-gce-with-terraform-2j8p</link>
      <guid>https://forem.com/pradeepbhadani/deploy-web-server-on-google-compute-engine-gce-with-terraform-2j8p</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://pbhadani.com/posts/deploy-webserver-compute-instance/"&gt;pbhadani.com&lt;/a&gt;&lt;/em&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
In this blog, I will show how to deploy a Web Server (Nginx) using Terraform on Google Compute Engine(GCE).&lt;br&gt;
There are many ways to deploy &lt;code&gt;Nginx&lt;/code&gt; server on GCP (like on GKE, App Engine, GCE etc.) but for this post I will use GCE to illustrate its usage.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ecxfoooF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/zw69pz9csjo2ov9gu0yy.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ecxfoooF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/zw69pz9csjo2ov9gu0yy.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;
&lt;center&gt; Photo by &lt;a href="https://unsplash.com/@markusspiske"&gt;Markus Spiske&lt;/a&gt; on &lt;a href="https://unsplash.com"&gt;Unsplash&lt;/a&gt;
&lt;/center&gt;
&lt;h1&gt;
  
  
  Goal
&lt;/h1&gt;

&lt;p&gt;Deploy a Web Server on Google Compute Engine (GCE) using Terraform.&lt;/p&gt;
&lt;h2&gt;
  
  
  What we will explore?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Deploying a Google Compute VM Instance using Terraform.&lt;/li&gt;
&lt;li&gt;Use of Compute Instance &lt;code&gt;startup&lt;/code&gt; script.&lt;/li&gt;
&lt;li&gt;Rendering a template in terraform.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;
  
  
  Prerequisites
&lt;/h1&gt;

&lt;p&gt;This post assumes the following:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We already have a GCP Project with a network. By default, every GCP Project comes with a &lt;code&gt;default&lt;/code&gt; network.
&lt;/li&gt;
&lt;li&gt;Google Cloud SDK (&lt;code&gt;gcloud&lt;/code&gt;) and &lt;code&gt;Terraform&lt;/code&gt; is setup on your workstation. If you don't have, then refer to my previous blogs - &lt;a href="https://pbhadani.com/posts/getting-started-with-terraform/"&gt;Getting started with Terraform&lt;/a&gt; and &lt;a href="https://pbhadani.com/posts/getting-started-wth-google-cloud-sdk/"&gt;Getting started with Google Cloud SDK&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h1&gt;
  
  
  Create a Compute VM Instance
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Create a unix directory for the Terraform project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nb"&gt;mkdir&lt;/span&gt; ~/terraform-webserver
  &lt;span class="nb"&gt;cd&lt;/span&gt; ~/terraform-webserver
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Define Terraform Google Provider.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;    vi provider.tf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;This file has the following content
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# Specify the GCP Provider&lt;/span&gt;
    &lt;span class="nx"&gt;provider&lt;/span&gt; &lt;span class="s2"&gt;"google"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;project&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project_id&lt;/span&gt;
      &lt;span class="nx"&gt;region&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;region&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Write below terraform code to create a Google Compute VM Instance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;    vi vm.tf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;To use the latest `debian` disk, we can use the data source
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;    &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="s2"&gt;"google_compute_image"&lt;/span&gt; &lt;span class="s2"&gt;"debian"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;family&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ubuntu-1804-lts"&lt;/span&gt;
      &lt;span class="nx"&gt;project&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"gce-uefi-images"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# Creates a GCP VM Instance.&lt;/span&gt;
    &lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"google_compute_instance"&lt;/span&gt; &lt;span class="s2"&gt;"vm"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;name&lt;/span&gt;         &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
      &lt;span class="nx"&gt;machine_type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;machine_type&lt;/span&gt;
      &lt;span class="nx"&gt;zone&lt;/span&gt;         &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;zone&lt;/span&gt;
      &lt;span class="nx"&gt;tags&lt;/span&gt;         &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"http-server"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="nx"&gt;labels&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;labels&lt;/span&gt;

      &lt;span class="nx"&gt;boot_disk&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;initialize_params&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;image&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;google_compute_image&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;debian&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;self_link&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;

      &lt;span class="nx"&gt;network_interface&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;network&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"default"&lt;/span&gt;
        &lt;span class="nx"&gt;access_config&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="c1"&gt;// Ephemeral IP&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;

      &lt;span class="nx"&gt;metadata_startup_script&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;template_file&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nginx&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;rendered&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; To allow &lt;code&gt;HTTP&lt;/code&gt; connection to VM instance, we put &lt;code&gt;http-server&lt;/code&gt; tag on the VM as &lt;code&gt;tags = ["http-server"]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Now, let's define a template file which has script to install &lt;code&gt;Nginx&lt;/code&gt; server and create a simple webpage &lt;code&gt;index.html&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;    &lt;span class="nb"&gt;mkdir &lt;/span&gt;template
    vi template/install_nginx.tpl
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;    &lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
    &lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"*****    Installing Nginx    *****"&lt;/span&gt;
    apt update
    apt &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; nginx
    ufw allow &lt;span class="s1"&gt;'${ufw_allow_nginx}'&lt;/span&gt;
    systemctl &lt;span class="nb"&gt;enable &lt;/span&gt;nginx
    systemctl restart nginx

    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"*****   Installation Complteted!!   *****"&lt;/span&gt;

    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Welcome to Google Compute VM Instance deployed using Terraform!!!"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /var/www/html

    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"*****   Startup script completes!!    *****"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; We pass the value of &lt;code&gt;'${ufw_allow_nginx}'&lt;/code&gt; from terraform code during template rendering.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Let's, render the above template.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;    vi vm.tf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Append the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;    &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="s2"&gt;"template_file"&lt;/span&gt; &lt;span class="s2"&gt;"nginx"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;template&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"${file("&lt;/span&gt;&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt;&lt;span class="err"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;install_nginx&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tpl&lt;/span&gt;&lt;span class="s2"&gt;")}"&lt;/span&gt;

      &lt;span class="nx"&gt;vars&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;ufw_allow_nginx&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Nginx HTTP"&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; Once the instance comes up, we want to know its public IP so that we can browse the webpage. To do this, we can use terraform outputs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  vi outputs.tf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;  &lt;span class="nx"&gt;output&lt;/span&gt; &lt;span class="s2"&gt;"webserver_ip"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;google_compute_instance&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;vm&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;network_interface&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;access_config&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nat_ip&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 7:&lt;/strong&gt; Now, define all the variables in a file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;    vi variables.tf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;    &lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"project_id"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Google Cloud Platform (GCP) Project ID."&lt;/span&gt;
      &lt;span class="nx"&gt;type&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"region"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"GCP region name."&lt;/span&gt;
      &lt;span class="nx"&gt;type&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
      &lt;span class="nx"&gt;default&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"europe-west1"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"zone"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"GCP zone name."&lt;/span&gt;
      &lt;span class="nx"&gt;type&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
      &lt;span class="nx"&gt;default&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"europe-west1-b"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"name"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Web server name."&lt;/span&gt;
      &lt;span class="nx"&gt;type&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
      &lt;span class="nx"&gt;default&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"my-webserver"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"machine_type"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"GCP VM instance machine type."&lt;/span&gt;
      &lt;span class="nx"&gt;type&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
      &lt;span class="nx"&gt;default&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"f1-micro"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"labels"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"List of labels to attach to the VM instance."&lt;/span&gt;
      &lt;span class="nx"&gt;type&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;map&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 8:&lt;/strong&gt; Define require variables value in &lt;code&gt;tfvars&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;    vi terraform.tfvars
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;      &lt;span class="nx"&gt;project_id&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"gcp-project-id"&lt;/span&gt;
      &lt;span class="nx"&gt;labels&lt;/span&gt;     &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"environment"&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"test"&lt;/span&gt;
        &lt;span class="s2"&gt;"team"&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"devops"&lt;/span&gt;
        &lt;span class="s2"&gt;"application"&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"webserver"&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 9:&lt;/strong&gt; We now have all the required terraform configuration. So, let's initialize the terraform project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  terraform init
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  Initializing the backend...

  Initializing provider plugins...
  - Checking &lt;span class="k"&gt;for &lt;/span&gt;available provider plugins...
  - Downloading plugin &lt;span class="k"&gt;for &lt;/span&gt;provider &lt;span class="s2"&gt;"google"&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;hashicorp/google&lt;span class="o"&gt;)&lt;/span&gt; 3.4.0...
  - Downloading plugin &lt;span class="k"&gt;for &lt;/span&gt;provider &lt;span class="s2"&gt;"template"&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;hashicorp/template&lt;span class="o"&gt;)&lt;/span&gt; 2.1.2...

  The following providers &lt;span class="k"&gt;do &lt;/span&gt;not have any version constraints &lt;span class="k"&gt;in &lt;/span&gt;configuration,
  so the latest version was installed.

  To prevent automatic upgrades to new major versions that may contain breaking
  changes, it is recommended to add version &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"..."&lt;/span&gt; constraints to the
  corresponding provider blocks &lt;span class="k"&gt;in &lt;/span&gt;configuration, with the constraint strings
  suggested below.

  &lt;span class="k"&gt;*&lt;/span&gt; provider.google: version &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"~&amp;gt; 3.4"&lt;/span&gt;
  &lt;span class="k"&gt;*&lt;/span&gt; provider.template: version &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"~&amp;gt; 2.1"&lt;/span&gt;

  Terraform has been successfully initialized!

  You may now begin working with Terraform. Try running &lt;span class="s2"&gt;"terraform plan"&lt;/span&gt; to see
  any changes that are required &lt;span class="k"&gt;for &lt;/span&gt;your infrastructure. All Terraform commands
  should now work.

  If you ever &lt;span class="nb"&gt;set &lt;/span&gt;or change modules or backend configuration &lt;span class="k"&gt;for &lt;/span&gt;Terraform,
  rerun this &lt;span class="nb"&gt;command &lt;/span&gt;to reinitialize your working directory. If you forget, other
  commands will detect it and remind you to &lt;span class="k"&gt;do &lt;/span&gt;so &lt;span class="k"&gt;if &lt;/span&gt;necessary.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 10:&lt;/strong&gt; After successful initialization, run plan and save plan in a file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  terraform plan &lt;span class="nt"&gt;--out&lt;/span&gt; 1.plan
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  Refreshing Terraform state &lt;span class="k"&gt;in&lt;/span&gt;&lt;span class="nt"&gt;-memory&lt;/span&gt; prior to plan...
  The refreshed state will be used to calculate this plan, but will not be
  persisted to &lt;span class="nb"&gt;local &lt;/span&gt;or remote state storage.

  data.template_file.nginx: Refreshing state...
  data.google_compute_image.debian: Refreshing state...

  &lt;span class="nt"&gt;------------------------------------------------------------------------&lt;/span&gt;

  An execution plan has been generated and is shown below.
  Resource actions are indicated with the following symbols:
    + create

  Terraform will perform the following actions:

    &lt;span class="c"&gt;# google_compute_instance.vm will be created&lt;/span&gt;
    + resource &lt;span class="s2"&gt;"google_compute_instance"&lt;/span&gt; &lt;span class="s2"&gt;"vm"&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        + can_ip_forward          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;
        + cpu_platform            &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + deletion_protection     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;
        + guest_accelerator       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + &lt;span class="nb"&gt;id&lt;/span&gt;                      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + instance_id             &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + label_fingerprint       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + labels                  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            + &lt;span class="s2"&gt;"application"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"webserver"&lt;/span&gt;
            + &lt;span class="s2"&gt;"environment"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"test"&lt;/span&gt;
            + &lt;span class="s2"&gt;"team"&lt;/span&gt;        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"devops"&lt;/span&gt;
          &lt;span class="o"&gt;}&lt;/span&gt;
        + machine_type            &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"f1-micro"&lt;/span&gt;
        + metadata_fingerprint    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + metadata_startup_script &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"#!/bin/bash&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;set -e&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;echo &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;*****    Installing Nginx    *****&lt;/span&gt;&lt;span class="se"&gt;\"\n&lt;/span&gt;&lt;span class="s2"&gt;apt update&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;apt install -y nginx&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;ufw allow 'Nginx HTTP'&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;systemctl enable nginx&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;systemctl restart nginx&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;echo &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;*****   Installation Complteted!!   *****&lt;/span&gt;&lt;span class="se"&gt;\"\n&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;echo &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;Welcome to Google Compute VM Instance deployed using Terraform!!!&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; &amp;gt; /var/www/html/index.html&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;echo &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;*****   Startup script completes!!    *****&lt;/span&gt;&lt;span class="se"&gt;\"\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
        + min_cpu_platform        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + name                    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"my-webserver"&lt;/span&gt;
        + project                 &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + self_link               &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + tags                    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;
            + &lt;span class="s2"&gt;"http-server"&lt;/span&gt;,
          &lt;span class="o"&gt;]&lt;/span&gt;
        + tags_fingerprint        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + zone                    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"europe-west1-b"&lt;/span&gt;

        + boot_disk &lt;span class="o"&gt;{&lt;/span&gt;
            + auto_delete                &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt;
            + device_name                &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + disk_encryption_key_sha256 &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + kms_key_self_link          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + mode                       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"READ_WRITE"&lt;/span&gt;
            + &lt;span class="nb"&gt;source&lt;/span&gt;                     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;

            + initialize_params &lt;span class="o"&gt;{&lt;/span&gt;
                + image  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://www.googleapis.com/compute/v1/projects/gce-uefi-images/global/images/ubuntu-1804-bionic-v20191113"&lt;/span&gt;
                + labels &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + size   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + &lt;span class="nb"&gt;type&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
              &lt;span class="o"&gt;}&lt;/span&gt;
          &lt;span class="o"&gt;}&lt;/span&gt;

        + network_interface &lt;span class="o"&gt;{&lt;/span&gt;
            + name               &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + network            &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"default"&lt;/span&gt;
            + network_ip         &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + subnetwork         &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + subnetwork_project &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;

            + access_config &lt;span class="o"&gt;{&lt;/span&gt;
                + nat_ip       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + network_tier &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
              &lt;span class="o"&gt;}&lt;/span&gt;
          &lt;span class="o"&gt;}&lt;/span&gt;

        + scheduling &lt;span class="o"&gt;{&lt;/span&gt;
            + automatic_restart   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + on_host_maintenance &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
            + preemptible         &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;

            + node_affinities &lt;span class="o"&gt;{&lt;/span&gt;
                + key      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + operator &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
                + values   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
              &lt;span class="o"&gt;}&lt;/span&gt;
          &lt;span class="o"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;}&lt;/span&gt;

  Plan: 1 to add, 0 to change, 0 to destroy.

  &lt;span class="nt"&gt;------------------------------------------------------------------------&lt;/span&gt;

  This plan was saved to: 1.plan

  To perform exactly these actions, run the following &lt;span class="nb"&gt;command &lt;/span&gt;to apply:
      terraform apply &lt;span class="s2"&gt;"1.plan"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 11:&lt;/strong&gt; Plan shows to create a VM instance and use &lt;code&gt;install_nginx.tpl&lt;/code&gt; as startup script. So, let's go ahead and apply the plan.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  terraform apply 1.plan
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  google_compute_instance.vm: Creating...
  google_compute_instance.vm: Still creating... &lt;span class="o"&gt;[&lt;/span&gt;10s elapsed]
  google_compute_instance.vm: Creation &lt;span class="nb"&gt;complete &lt;/span&gt;after 15s &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;projects/workshop-demo-34293/zones/europe-west1-b/instances/my-webserver]

  Apply &lt;span class="nb"&gt;complete&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; Resources: 1 added, 0 changed, 0 destroyed.

  The state of your infrastructure has been saved to the path
  below. This state is required to modify and destroy your
  infrastructure, so keep it safe. To inspect the &lt;span class="nb"&gt;complete &lt;/span&gt;state
  use the &lt;span class="sb"&gt;`&lt;/span&gt;terraform show&lt;span class="sb"&gt;`&lt;/span&gt; command.

  State path: terraform.tfstate

  Outputs:

  webserver_ip &lt;span class="o"&gt;=&lt;/span&gt; 35.240.104.9
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 12:&lt;/strong&gt; Now if you navigate to &lt;a href="https://console.cloud.google.com"&gt;Google Console&lt;/a&gt; and navigate to &lt;code&gt;Compute Engine --&amp;gt; VM Instance&lt;/code&gt;, you will see an instance coming up. Once the instance is up successfully, browse the &lt;code&gt;webserver_ip&lt;/code&gt;. In this case, go to &lt;code&gt;http://35.240.104.9&lt;/code&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ItqSVgFy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/96hrqiz5jdqrdnltz95x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ItqSVgFy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/96hrqiz5jdqrdnltz95x.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 13:&lt;/strong&gt; For cleanup, run terraform destroy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  terraform destroy
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  data.template_file.nginx: Refreshing state...
  data.google_compute_image.debian: Refreshing state...
  google_compute_instance.vm: Refreshing state... &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;projects/workshop-demo-34293/zones/europe-west1-b/instances/my-webserver]

  An execution plan has been generated and is shown below.
  Resource actions are indicated with the following symbols:
    - destroy

  Terraform will perform the following actions:

    &lt;span class="c"&gt;# google_compute_instance.vm will be destroyed&lt;/span&gt;
    - resource &lt;span class="s2"&gt;"google_compute_instance"&lt;/span&gt; &lt;span class="s2"&gt;"vm"&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        - can_ip_forward          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt; -&amp;gt; null
        - cpu_platform            &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Intel Haswell"&lt;/span&gt; -&amp;gt; null
        - deletion_protection     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt; -&amp;gt; null
        - enable_display          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt; -&amp;gt; null
        - guest_accelerator       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[]&lt;/span&gt; -&amp;gt; null
        - &lt;span class="nb"&gt;id&lt;/span&gt;                      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"projects/workshop-demo-34293/zones/europe-west1-b/instances/my-webserver"&lt;/span&gt; -&amp;gt; null
        - instance_id             &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"3519528545052665512"&lt;/span&gt; -&amp;gt; null
        - label_fingerprint       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"k3pYoTAUZq4="&lt;/span&gt; -&amp;gt; null
        - labels                  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            - &lt;span class="s2"&gt;"application"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"webserver"&lt;/span&gt;
            - &lt;span class="s2"&gt;"environment"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"test"&lt;/span&gt;
            - &lt;span class="s2"&gt;"team"&lt;/span&gt;        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"devops"&lt;/span&gt;
          &lt;span class="o"&gt;}&lt;/span&gt; -&amp;gt; null
        - machine_type            &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"f1-micro"&lt;/span&gt; -&amp;gt; null
        - metadata                &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{}&lt;/span&gt; -&amp;gt; null
        - metadata_fingerprint    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"mE2Cwt2znPk="&lt;/span&gt; -&amp;gt; null
        - metadata_startup_script &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"#!/bin/bash&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;set -e&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;echo &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;*****    Installing Nginx    *****&lt;/span&gt;&lt;span class="se"&gt;\"\n&lt;/span&gt;&lt;span class="s2"&gt;apt update&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;apt install -y nginx&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;ufw allow 'Nginx HTTP'&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;systemctl enable nginx&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;systemctl restart nginx&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="s2"&gt;echo &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;*****   Installation Complteted!!   *****&lt;/span&gt;&lt;span class="se"&gt;\"\n\n&lt;/span&gt;&lt;span class="s2"&gt;echo &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;Welcome to Google Compute VM Instance deployed using Terraform!!!&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; &amp;gt; /var/www/html/index.html&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="s2"&gt;echo &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;*****   Startup script completes!!    *****&lt;/span&gt;&lt;span class="se"&gt;\"\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; -&amp;gt; null
        - name                    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"my-webserver"&lt;/span&gt; -&amp;gt; null
        - project                 &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"workshop-demo-34293"&lt;/span&gt; -&amp;gt; null
        - self_link               &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://www.googleapis.com/compute/v1/projects/workshop-demo-34293/zones/europe-west1-b/instances/my-webserver"&lt;/span&gt; -&amp;gt; null
        - tags                    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;
            - &lt;span class="s2"&gt;"http-server"&lt;/span&gt;,
          &lt;span class="o"&gt;]&lt;/span&gt; -&amp;gt; null
        - tags_fingerprint        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"FYLDgkTKlA4="&lt;/span&gt; -&amp;gt; null
        - zone                    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"europe-west1-b"&lt;/span&gt; -&amp;gt; null

        - boot_disk &lt;span class="o"&gt;{&lt;/span&gt;
            - auto_delete &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt; -&amp;gt; null
            - device_name &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"persistent-disk-0"&lt;/span&gt; -&amp;gt; null
            - mode        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"READ_WRITE"&lt;/span&gt; -&amp;gt; null
            - &lt;span class="nb"&gt;source&lt;/span&gt;      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://www.googleapis.com/compute/v1/projects/workshop-demo-34293/zones/europe-west1-b/disks/my-webserver"&lt;/span&gt; -&amp;gt; null

            - initialize_params &lt;span class="o"&gt;{&lt;/span&gt;
                - image  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://www.googleapis.com/compute/v1/projects/gce-uefi-images/global/images/ubuntu-1804-bionic-v20191113"&lt;/span&gt; -&amp;gt; null
                - labels &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{}&lt;/span&gt; -&amp;gt; null
                - size   &lt;span class="o"&gt;=&lt;/span&gt; 10 -&amp;gt; null
                - &lt;span class="nb"&gt;type&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"pd-standard"&lt;/span&gt; -&amp;gt; null
              &lt;span class="o"&gt;}&lt;/span&gt;
          &lt;span class="o"&gt;}&lt;/span&gt;

        - network_interface &lt;span class="o"&gt;{&lt;/span&gt;
            - name               &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"nic0"&lt;/span&gt; -&amp;gt; null
            - network            &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://www.googleapis.com/compute/v1/projects/workshop-demo-34293/global/networks/default"&lt;/span&gt; -&amp;gt; null
            - network_ip         &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"10.132.0.13"&lt;/span&gt; -&amp;gt; null
            - subnetwork         &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://www.googleapis.com/compute/v1/projects/workshop-demo-34293/regions/europe-west1/subnetworks/default"&lt;/span&gt; -&amp;gt; null
            - subnetwork_project &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"workshop-demo-34293"&lt;/span&gt; -&amp;gt; null

            - access_config &lt;span class="o"&gt;{&lt;/span&gt;
                - nat_ip       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"35.240.104.9"&lt;/span&gt; -&amp;gt; null
                - network_tier &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"PREMIUM"&lt;/span&gt; -&amp;gt; null
              &lt;span class="o"&gt;}&lt;/span&gt;
          &lt;span class="o"&gt;}&lt;/span&gt;

        - scheduling &lt;span class="o"&gt;{&lt;/span&gt;
            - automatic_restart   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt; -&amp;gt; null
            - on_host_maintenance &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"MIGRATE"&lt;/span&gt; -&amp;gt; null
            - preemptible         &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt; -&amp;gt; null
          &lt;span class="o"&gt;}&lt;/span&gt;

        - shielded_instance_config &lt;span class="o"&gt;{&lt;/span&gt;
            - enable_integrity_monitoring &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt; -&amp;gt; null
            - enable_secure_boot          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt; -&amp;gt; null
            - enable_vtpm                 &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt; -&amp;gt; null
          &lt;span class="o"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;}&lt;/span&gt;

  Plan: 0 to add, 0 to change, 1 to destroy.

  Do you really want to destroy all resources?
    Terraform will destroy all your managed infrastructure, as shown above.
    There is no undo. Only &lt;span class="s1"&gt;'yes'&lt;/span&gt; will be accepted to confirm.

    Enter a value: &lt;span class="nb"&gt;yes

  &lt;/span&gt;google_compute_instance.vm: Destroying... &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;projects/workshop-demo-34293/zones/europe-west1-b/instances/my-webserver]
  google_compute_instance.vm: Still destroying... &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;projects/workshop-demo-34293/zones/europe-west1-b/instances/my-webserver, 10s elapsed]
  google_compute_instance.vm: Still destroying... &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;projects/workshop-demo-34293/zones/europe-west1-b/instances/my-webserver, 20s elapsed]

  google_compute_instance.vm: Still destroying... &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;projects/workshop-demo-34293/zones/europe-west1-b/instances/my-webserver, 2m30s elapsed]
  google_compute_instance.vm: Destruction &lt;span class="nb"&gt;complete &lt;/span&gt;after 2m36s

  Destroy &lt;span class="nb"&gt;complete&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; Resources: 1 destroyed.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Hope this blog gives you familiarity with &lt;code&gt;google_compute_instance&lt;/code&gt; and Terraform template rendering.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Complete source code can be found &lt;a href="https://github.com/pradeepbhadani/terraform-webserver"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you have feedback or questions, please reach out to me on &lt;a href="https://linkedin.com/in/pradeepbhadani"&gt;LinkedIn&lt;/a&gt; or &lt;a href="https://twitter.com/bhadanipradeep"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>terraform</category>
      <category>devops</category>
      <category>infrastructure</category>
      <category>googlecloudplatform</category>
    </item>
    <item>
      <title>Create first GCP resource with Terraform</title>
      <dc:creator>Pradeep Bhadani</dc:creator>
      <pubDate>Thu, 09 Jan 2020 18:50:57 +0000</pubDate>
      <link>https://forem.com/pradeepbhadani/create-first-gcp-resource-with-terraform-2gj5</link>
      <guid>https://forem.com/pradeepbhadani/create-first-gcp-resource-with-terraform-2gj5</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://pbhadani.com/posts/first-gcp-resource-with-terraform/"&gt;pbhadani.com&lt;/a&gt;&lt;/em&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
Welcome to my post and Happy New year!&lt;/p&gt;

&lt;p&gt;Let's create our first GCP resource using Terraform in this post.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bN9jAYpU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/cra9jscnmcqvn7s429wo.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bN9jAYpU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/cra9jscnmcqvn7s429wo.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;
&lt;center&gt; Photo by &lt;a href="https://unsplash.com/@markusspiske"&gt;Markus Spiske&lt;/a&gt; on &lt;a href="https://unsplash.com"&gt;Unsplash&lt;/a&gt;
&lt;/center&gt;
&lt;h1&gt;
  
  
  Goal
&lt;/h1&gt;

&lt;p&gt;Create a Google Cloud Storage(GCS) Bucket using Terraform.&lt;/p&gt;
&lt;h1&gt;
  
  
  Prerequisites
&lt;/h1&gt;

&lt;p&gt;This post assumes the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We already have a GCP Project and a GCS Bucket (we will use this to store Terraform State file) created.&lt;/li&gt;
&lt;li&gt;Google Cloud SDK (&lt;code&gt;gcloud&lt;/code&gt;) and &lt;code&gt;Terraform&lt;/code&gt; is setup on your workstation. If you don't have, then refer to my previous blogs - &lt;a href="https://pbhadani.com/posts/getting-started-with-terraform/"&gt;Getting started with Terraform&lt;/a&gt; and &lt;a href="https://pbhadani.com/posts/getting-started-wth-google-cloud-sdk/"&gt;Getting started with Google Cloud SDK&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h1&gt;
  
  
  Create a Google Cloud Storage(GCS) Bucket with Terraform
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Create a unix directory for the Terraform project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nb"&gt;mkdir&lt;/span&gt; ~/terraform-gcs-example
  &lt;span class="nb"&gt;cd&lt;/span&gt; ~/terraform-gcs-example
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Create Terraform configuration file which defines GCS bucket and provider.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  vi bucket.tf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This file has following content&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;  &lt;span class="c1"&gt;# Specify the GCP Provider&lt;/span&gt;
  &lt;span class="nx"&gt;provider&lt;/span&gt; &lt;span class="s2"&gt;"google"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;project&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project_id&lt;/span&gt;
    &lt;span class="nx"&gt;region&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;region&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;# Create a GCS Bucket&lt;/span&gt;
  &lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"google_storage_bucket"&lt;/span&gt; &lt;span class="s2"&gt;"my_bucket"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bucket_name&lt;/span&gt;
    &lt;span class="nx"&gt;location&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;region&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Define Terraform variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  vi variables.tf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This file looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;  &lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"project_id"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Google Project ID."&lt;/span&gt;
    &lt;span class="nx"&gt;type&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"bucket_name"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"GCS Bucket name. Value should be unique ."&lt;/span&gt;
    &lt;span class="nx"&gt;type&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"region"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Google Cloud region"&lt;/span&gt;
    &lt;span class="nx"&gt;type&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
    &lt;span class="nx"&gt;default&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"europe-west2"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;**Note:** We are defining a `default` value for `region`. This means if a value is not supplied for this variable, Terraform will use `europe-west2` as its value.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Create a &lt;code&gt;tfvars&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  vi terraform.tfvars
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;  &lt;span class="nx"&gt;project_id&lt;/span&gt;  &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;                   &lt;span class="c1"&gt;# Put your GCP Project ID.&lt;/span&gt;
  &lt;span class="nx"&gt;bucket_name&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"my-bucket-48693"&lt;/span&gt;    &lt;span class="c1"&gt;# Put the desired GCS Bucket name.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Set the remote state.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  vi backend.tf
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight hcl"&gt;&lt;code&gt;  &lt;span class="nx"&gt;terraform&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;backend&lt;/span&gt; &lt;span class="s2"&gt;"gcs"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;bucket&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"my-tfstate-bucket"&lt;/span&gt;   &lt;span class="c1"&gt;# GCS bucket name to store terraform tfstate&lt;/span&gt;
      &lt;span class="nx"&gt;prefix&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"first-app"&lt;/span&gt;           &lt;span class="c1"&gt;# Update to desired prefix name. Prefix name should be unique for each Terraform project having same remote state bucket.&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; File structure looks like below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  cntekio:~ terraform-gcs-example&lt;span class="nv"&gt;$ &lt;/span&gt;tree
  &lt;span class="nb"&gt;.&lt;/span&gt;
  ├── backend.tf
  ├── bucket.tf
  ├── terraform.tfvars
  └── variables.tf

  0 directories, 4 files
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 7:&lt;/strong&gt; Now, initialize the terraform project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  terraform init
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  Initializing the backend...

  Successfully configured the backend &lt;span class="s2"&gt;"gcs"&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; Terraform will automatically
  use this backend unless the backend configuration changes.

  Initializing provider plugins...
  - Checking &lt;span class="k"&gt;for &lt;/span&gt;available provider plugins...
  - Downloading plugin &lt;span class="k"&gt;for &lt;/span&gt;provider &lt;span class="s2"&gt;"google"&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;hashicorp/google&lt;span class="o"&gt;)&lt;/span&gt; 3.3.0...

  The following providers &lt;span class="k"&gt;do &lt;/span&gt;not have any version constraints &lt;span class="k"&gt;in &lt;/span&gt;configuration,
  so the latest version was installed.

  To prevent automatic upgrades to new major versions that may contain breaking
  changes, it is recommended to add version &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"..."&lt;/span&gt; constraints to the
  corresponding provider blocks &lt;span class="k"&gt;in &lt;/span&gt;configuration, with the constraint strings
  suggested below.

  &lt;span class="k"&gt;*&lt;/span&gt; provider.google: version &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"~&amp;gt; 3.3"&lt;/span&gt;

  Terraform has been successfully initialized!

  You may now begin working with Terraform. Try running &lt;span class="s2"&gt;"terraform plan"&lt;/span&gt; to see
  any changes that are required &lt;span class="k"&gt;for &lt;/span&gt;your infrastructure. All Terraform commands
  should now work.

  If you ever &lt;span class="nb"&gt;set &lt;/span&gt;or change modules or backend configuration &lt;span class="k"&gt;for &lt;/span&gt;Terraform,
  rerun this &lt;span class="nb"&gt;command &lt;/span&gt;to reinitialize your working directory. If you forget, other
  commands will detect it and remind you to &lt;span class="k"&gt;do &lt;/span&gt;so &lt;span class="k"&gt;if &lt;/span&gt;necessary.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;code&gt;terraform init&lt;/code&gt; downloads all the required provider and plugins.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 8:&lt;/strong&gt; Let's see the execution plan.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  terraform plan &lt;span class="nt"&gt;--out&lt;/span&gt; 1.plan
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  Refreshing Terraform state &lt;span class="k"&gt;in&lt;/span&gt;&lt;span class="nt"&gt;-memory&lt;/span&gt; prior to plan...
  The refreshed state will be used to calculate this plan, but will not be
  persisted to &lt;span class="nb"&gt;local &lt;/span&gt;or remote state storage.
  &lt;span class="nt"&gt;------------------------------------------------------------------------&lt;/span&gt;

  An execution plan has been generated and is shown below.
  Resource actions are indicated with the following symbols:
    + create

  Terraform will perform the following actions:

    &lt;span class="c"&gt;# google_storage_bucket.my_bucket will be created&lt;/span&gt;
    + resource &lt;span class="s2"&gt;"google_storage_bucket"&lt;/span&gt; &lt;span class="s2"&gt;"my_bucket"&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        + bucket_policy_only &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + force_destroy      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt;
        + &lt;span class="nb"&gt;id&lt;/span&gt;                 &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + location           &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"EUROPE-WEST2"&lt;/span&gt;
        + name               &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"my-bucket-48693"&lt;/span&gt;
        + project            &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + self_link          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
        + storage_class      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"STANDARD"&lt;/span&gt;
        + url                &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;known after apply&lt;span class="o"&gt;)&lt;/span&gt;
      &lt;span class="o"&gt;}&lt;/span&gt;

  Plan: 1 to add, 0 to change, 0 to destroy.

  &lt;span class="nt"&gt;------------------------------------------------------------------------&lt;/span&gt;

  This plan was saved to: 1.plan

  To perform exactly these actions, run the following &lt;span class="nb"&gt;command &lt;/span&gt;to apply:
      terraform apply &lt;span class="s2"&gt;"1.plan"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;code&gt;terraform plan&lt;/code&gt; output shows that this code is going to create one GCS bucket.&lt;br&gt;
  &lt;code&gt;--out 1.plan&lt;/code&gt; flag tells terraform to save the plan in a file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 9:&lt;/strong&gt; The execution plan looks good, so let's move ahead and apply this plan.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  terraform apply 1.plan
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  google_storage_bucket.my_bucket: Creating...
  google_storage_bucket.my_bucket: Creation &lt;span class="nb"&gt;complete &lt;/span&gt;after 3s &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;my-bucket-48693]

  Apply &lt;span class="nb"&gt;complete&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; Resources: 1 added, 0 changed, 0 destroyed.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 10:&lt;/strong&gt; Once we no longer need this infrastructure, we can cleanup to reduce costs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  terraform destroy
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  google_storage_bucket.my_bucket: Refreshing state... &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;my-bucket-48693]

  An execution plan has been generated and is shown below.
  Resource actions are indicated with the following symbols:
    - destroy

  Terraform will perform the following actions:

    &lt;span class="c"&gt;# google_storage_bucket.my_bucket will be destroyed&lt;/span&gt;
    - resource &lt;span class="s2"&gt;"google_storage_bucket"&lt;/span&gt; &lt;span class="s2"&gt;"my_bucket"&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        - bucket_policy_only &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt; -&amp;gt; null
        - force_destroy      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt; -&amp;gt; null
        - &lt;span class="nb"&gt;id&lt;/span&gt;                 &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"my-bucket-48693"&lt;/span&gt; -&amp;gt; null
        - labels             &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;{}&lt;/span&gt; -&amp;gt; null
        - location           &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"EUROPE-WEST2"&lt;/span&gt; -&amp;gt; null
        - name               &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"my-bucket-48693"&lt;/span&gt; -&amp;gt; null
        - project            &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"my-project-id"&lt;/span&gt; -&amp;gt; null
        - requester_pays     &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;false&lt;/span&gt; -&amp;gt; null
        - self_link          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://www.googleapis.com/storage/v1/b/my-bucket-48693"&lt;/span&gt; -&amp;gt; null
        - storage_class      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"STANDARD"&lt;/span&gt; -&amp;gt; null
        - url                &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"gs://my-bucket-48693"&lt;/span&gt; -&amp;gt; null
      &lt;span class="o"&gt;}&lt;/span&gt;

  Plan: 0 to add, 0 to change, 1 to destroy.

  Do you really want to destroy all resources?
    Terraform will destroy all your managed infrastructure, as shown above.
    There is no undo. Only &lt;span class="s1"&gt;'yes'&lt;/span&gt; will be accepted to confirm.

    Enter a value: &lt;span class="nb"&gt;yes

  &lt;/span&gt;google_storage_bucket.my_bucket: Destroying... &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;my-bucket-48693]
  google_storage_bucket.my_bucket: Destruction &lt;span class="nb"&gt;complete &lt;/span&gt;after 6s

  Destroy &lt;span class="nb"&gt;complete&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; Resources: 1 destroyed.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Hope this blog helps you get started with creating GCP resources using Terraform&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you have a feedback or questions, please reach out to me on &lt;a href="https://linkedin.com/in/pradeepbhadani"&gt;LinkedIn&lt;/a&gt; or &lt;a href="https://twitter.com/bhadanipradeep"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>terraform</category>
      <category>devops</category>
      <category>infrastructure</category>
      <category>googlecloudplatform</category>
    </item>
    <item>
      <title>Enabling GKE Workload Identity</title>
      <dc:creator>Pradeep Bhadani</dc:creator>
      <pubDate>Sat, 21 Dec 2019 16:33:00 +0000</pubDate>
      <link>https://forem.com/pradeepbhadani/getting-started-with-terraform-35fg</link>
      <guid>https://forem.com/pradeepbhadani/getting-started-with-terraform-35fg</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://pbhadani.com/posts/gke-workload-identity/" rel="noopener noreferrer"&gt;pbhadani.com&lt;/a&gt;&lt;/em&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
In this blog, I will talk about the GKE Workload Identity feature and why to use this feature.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fjxwpgdkm0cusoodo6wgw.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fjxwpgdkm0cusoodo6wgw.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;center&gt; Photo by [chuttersnap](https://unsplash.com/@chuttersnap) on [Unsplash](https://unsplash.com)&lt;/center&gt;
&lt;h2&gt;
  
  
  What's the Problem?
&lt;/h2&gt;

&lt;p&gt;An application running on GKE must authenticate to use Google Services such as Google Cloud Storage (GCS), Cloud SQL, BigQuery, etc.&lt;br&gt;
Authentication can be done by providing a service account key JSON file to an application using Kubernetes Secret space or a different method such as Vault.&lt;br&gt;
But in these approaches, service account key JSON (which has 10years of a lifetime) must be stored in plain text within the pod or base64 encoded in Kubernetes secret space.&lt;br&gt;
Also, the key rotation process must be in a place that is not a fun process.&lt;/p&gt;

&lt;p&gt;We can avoid using the service account key by attaching a service account to Kubernetes Node but then all the pods running on the Node gets the same permission which is not an ideal thing to do.&lt;/p&gt;
&lt;h2&gt;
  
  
  Goal?
&lt;/h2&gt;

&lt;p&gt;We want to assign a service account to a Pod so we can isolate permissions for different pods.&lt;/p&gt;

&lt;p&gt;Hurray, we have Workload Identity feature available in beta which solves this problem on GKE.&lt;/p&gt;
&lt;h2&gt;
  
  
  So, What is Workload Identity?
&lt;/h2&gt;

&lt;p&gt;As per Google documentation, "&lt;em&gt;Workload Identity is the recommended way to access Google Cloud services from within GKE due to its improved security properties and manageability.&lt;/em&gt;"&lt;/p&gt;

&lt;p&gt;GKE Workload identity allows us to attach the service account to the Kubernetes pod and remove the hassle to manage the service account credentials JSON file within the pod or cluster.&lt;/p&gt;
&lt;h2&gt;
  
  
  Let's use Workload Identity in a GKE cluster
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;If you have not setup &lt;code&gt;gcloud&lt;/code&gt; on your workstation, then refer my &lt;a href="https://pbhadani.com/posts/getting-started-wth-google-cloud-sdk/" rel="noopener noreferrer"&gt;previous blog&lt;/a&gt; to get it up and running quickly.&lt;br&gt;&lt;br&gt;
Alternatively, you can use &lt;a href="https://cloud.google.com/shell/" rel="noopener noreferrer"&gt;Google Cloud Shell&lt;/a&gt; to run the commands.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make sure you are a Project Editor or Project Owner or have enough permissions to run the below commands.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Setup a GKE Cluster
&lt;/h3&gt;

&lt;p&gt;Follow the below step to create a new GKE Cluster and enable Workload Identity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Enable the &lt;a href="https://console.cloud.google.com/apis/api/iamcredentials.googleapis.com/" rel="noopener noreferrer"&gt;Cloud IAM API&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Install and configure &lt;code&gt;gke-gcloud-auth-plugin&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
&lt;code&gt;gke-gcloud-auth-plugin&lt;/code&gt; is the new Kubectl authentication plugin for GKE. Please read the &lt;a href="https://cloud.google.com/blog/products/containers-kubernetes/kubectl-auth-changes-in-gke" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; for more details.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install plugin
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud components &lt;span class="nb"&gt;install &lt;/span&gt;gke-gcloud-auth-plugin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If &lt;code&gt;gcloud CLI component manager&lt;/code&gt; is disabled, use the &lt;code&gt;yum&lt;/code&gt; or &lt;code&gt;apt&lt;/code&gt; package to install this plugin.&lt;br&gt;
 For Debian:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;google-cloud-sdk-gke-gcloud-auth-plugin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Configure plugin
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"export USE_GKE_GCLOUD_AUTH_PLUGIN=True"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; ~/.bashrc
&lt;span class="nb"&gt;source&lt;/span&gt; ~/.bashrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Set GCP defaults.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set GCP Project
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;GCP_PROJECT_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;YOUR_GCP_PROJECT_ID&amp;gt;

  gcloud config &lt;span class="nb"&gt;set &lt;/span&gt;project &lt;span class="nv"&gt;$GCP_PROJECT_ID&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Set default region and zone
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  gcloud config &lt;span class="nb"&gt;set &lt;/span&gt;compute/region europe-west1

  gcloud config &lt;span class="nb"&gt;set &lt;/span&gt;compute/zone europe-west1-b
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Make sure you have &lt;code&gt;kubectl&lt;/code&gt; command installed.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   &lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;kubectl
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Run following to verify&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   kubectl &lt;span class="nb"&gt;help&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Please refer documentation: &lt;a href="https://cloud.google.com/sdk/docs/components#external_package_managers" rel="noopener noreferrer"&gt;External package managers&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Create a new Google Service Account (GSA).&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  gcloud iam service-accounts create workload-identity-test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Notes:&lt;/strong&gt;&lt;br&gt;
  You can use the existing service account.&lt;br&gt;
  Permission Required: &lt;code&gt;iam.serviceAccounts.create&lt;/code&gt; on the GCP Project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; Add permissions to the Google Service Account required by an application. For example, &lt;code&gt;roles/storage.objectViewer&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  gcloud projects add-iam-policy-binding &lt;span class="nv"&gt;$GCP_PROJECT_ID&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--member&lt;/span&gt; serviceAccount:workload-identity-test@&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GCP_PROJECT_ID&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;.iam.gserviceaccount.com &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--role&lt;/span&gt; roles/storage.objectViewer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Step 7:&lt;/strong&gt; Setup a GKE cluster with &lt;em&gt;Workload Identity&lt;/em&gt; enabled.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;GKE_CLUSTER_NAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;gke-wi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  gcloud container clusters create &lt;span class="nv"&gt;$GKE_CLUSTER_NAME&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--cluster-version&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1.24 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--workload-pool&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$GCP_PROJECT_ID&lt;/span&gt;.svc.id.goog
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Notes:&lt;/strong&gt;&lt;br&gt;
  GKE Cluster could take 5-10mins to become fully functional.&lt;br&gt;
  Permission required: &lt;code&gt;container.clusters.create&lt;/code&gt; on the GCP Project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 8:&lt;/strong&gt; Configure &lt;code&gt;kubectl&lt;/code&gt; command on your terminal.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  gcloud container clusters get-credentials &lt;span class="nv"&gt;$GKE_CLUSTER_NAME&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Notes:&lt;/strong&gt;&lt;br&gt;
  This will populate &lt;code&gt;~/.kube/config&lt;/code&gt; file.&lt;br&gt;
  Permission Required: &lt;code&gt;container.clusters.get&lt;/code&gt; on the GCP Project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 9:&lt;/strong&gt; (Optional) Create a Kubernetes namespace if you don't want to use &lt;code&gt;default&lt;/code&gt; namespace.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  kubectl create namespace newspace
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Step 10:&lt;/strong&gt; Create Kubernetes Service Account (KSA).&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  kubectl create serviceaccount &lt;span class="se"&gt;\&lt;/span&gt;
 --namespace newspace &lt;span class="se"&gt;\&lt;/span&gt;
 workload-identity-test-ksa
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Step 11:&lt;/strong&gt; Bind the Google Service Account (GSA) and Kubernetes Service Account (KSA), so that KSA can use the permissions granted to GSA.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  gcloud iam service-accounts add-iam-policy-binding &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--role&lt;/span&gt; roles/iam.workloadIdentityUser &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--member&lt;/span&gt; &lt;span class="s2"&gt;"serviceAccount:&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GCP_PROJECT_ID&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.svc.id.goog[newspace/workload-identity-test-ksa]"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  workload-identity-test@&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GCP_PROJECT_ID&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;.iam.gserviceaccount.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Step 12:&lt;/strong&gt; Add annotation&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  kubectl annotate serviceaccount &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--namespace&lt;/span&gt; newspace &lt;span class="se"&gt;\&lt;/span&gt;
  workload-identity-test-ksa &lt;span class="se"&gt;\&lt;/span&gt;
  iam.gke.io/gcp-service-account&lt;span class="o"&gt;=&lt;/span&gt;workload-identity-test@&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GCP_PROJECT_ID&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;.iam.gserviceaccount.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Step 13:&lt;/strong&gt; Create a Pod with the KSA created to verify.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  kubectl run &lt;span class="nt"&gt;--rm&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; test-pod &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--image&lt;/span&gt; google/cloud-sdk:slim &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--namespace&lt;/span&gt; newspace &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--overrides&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'{ "spec": { "serviceAccount": "workload-identity-test-ksa" }  }'&lt;/span&gt; sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Running above command will login to Pod and provides its bash shell.&lt;br&gt;
  Now run below command to see which service account this pod is configured with.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  gcloud auth list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This should print the GSA name.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                           Credentialed Accounts
    ACTIVE  ACCOUNT
    *       workload-identity-test@workshop-demo-namwcb.iam.gserviceaccount.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Cleanup
&lt;/h3&gt;

&lt;p&gt;Don't forget to cleanup the resources, once you no longer need it.&lt;br&gt;&lt;br&gt;
Run the following commands:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Delete the GKE cluster.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  gcloud container clusters delete &lt;span class="nv"&gt;$GKE_CLUSTER_NAME&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Delete the Google Service Account (GSA).&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  gcloud iam service-accounts delete workload-identity-test@&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;GCP_PROJECT_ID&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;.iam.gserviceaccount.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;br&gt;&lt;br&gt;
Below is the terminal recording:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_asciinema"&gt;
  
&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Hope this blog helps you get familiar with Workload Identity and securely deploy apps on GKE.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you have feedback or questions, please reach out to me on &lt;a href="https://linkedin.com/in/pradeepbhadani" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; or &lt;a href="https://twitter.com/bhadanipradeep" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>googlecloud</category>
      <category>devops</category>
      <category>kubernetes</category>
      <category>gcp</category>
    </item>
    <item>
      <title>Getting started with Google Cloud SDK</title>
      <dc:creator>Pradeep Bhadani</dc:creator>
      <pubDate>Sun, 08 Dec 2019 19:19:00 +0000</pubDate>
      <link>https://forem.com/pradeepbhadani/getting-started-with-google-cloud-sdk-3la4</link>
      <guid>https://forem.com/pradeepbhadani/getting-started-with-google-cloud-sdk-3la4</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://pbhadani.com/posts/getting-started-wth-google-cloud-sdk/"&gt;pbhadani.com&lt;/a&gt;&lt;/em&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
Learn to setup Google Cloud SDK on your workstation and some operations in this step-by-step guide.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  What is Cloud SDK?
&lt;/h1&gt;

&lt;p&gt;The Cloud SDK is a collection of tools to interact with the Google Cloud Platform (GCP). It includes &lt;code&gt;bq&lt;/code&gt;, &lt;code&gt;kubectl&lt;/code&gt;, &lt;code&gt;gcloud&lt;/code&gt; and &lt;code&gt;gsutil&lt;/code&gt; command-line tools that can interact with various GCP Services using CLI or in automation scripts.&lt;br&gt;
Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create/manage a Google Cloud Storage (GCS) bucket.&lt;/li&gt;
&lt;li&gt;Create/manage Google Compute Engine (GCE) instance.&lt;/li&gt;
&lt;li&gt;Create/manage Google Datalab.&lt;/li&gt;
&lt;li&gt;Create a BigQuery Dataset.&lt;/li&gt;
&lt;li&gt;Submit a job to BigQuery.&lt;/li&gt;
&lt;li&gt;Create/manage firewall rules.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;
  
  
  Let's get it up and running
&lt;/h1&gt;

&lt;p&gt;Google provides a script to download and install the Cloud SDK quickly and interactively.&lt;/p&gt;
&lt;h2&gt;
  
  
  Install Google Cloud SDK
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; Run the following command in your terminal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; curl https://sdk.cloud.google.com | bash
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This will download the Cloud SDK package and run the installation script.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                   Dload  Upload   Total   Spent    Left  Speed
  100   443  100   443    0     0   3475      0 &lt;span class="nt"&gt;--&lt;/span&gt;:--:-- &lt;span class="nt"&gt;--&lt;/span&gt;:--:-- &lt;span class="nt"&gt;--&lt;/span&gt;:--:--  3488
  Downloading Google Cloud SDK &lt;span class="nb"&gt;install &lt;/span&gt;script: https://dl.google.com/dl/cloudsdk/channels/rapid/install_google_cloud_sdk.bash
  &lt;span class="c"&gt;######################################################################## 100.0%&lt;/span&gt;
  Running &lt;span class="nb"&gt;install &lt;/span&gt;script from: /tmp/tmp.GZI3OtObH9/install_google_cloud_sdk.bash
  which curl
  curl -# &lt;span class="nt"&gt;-f&lt;/span&gt; https://dl.google.com/dl/cloudsdk/channels/rapid/google-cloud-sdk.tar.gz
  &lt;span class="c"&gt;######################################################################## 100.0%&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; Provide the directory path on prompt&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  Installation directory &lt;span class="o"&gt;(&lt;/span&gt;this will create a google-cloud-sdk subdirectory&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;/home/vagrant&lt;span class="o"&gt;)&lt;/span&gt;:
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt; Once you provide the directory, the script will prompt for reporting. Choose one of the options.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  Welcome to the Google Cloud SDK!

  To &lt;span class="nb"&gt;help &lt;/span&gt;improve the quality of this product, we collect anonymized usage data and anonymized stacktraces when crashes are encountered&lt;span class="p"&gt;;&lt;/span&gt; additional information is available at &amp;lt;https://cloud.google.com/sdk/usage-statistics&amp;gt;. This data is handled &lt;span class="k"&gt;in &lt;/span&gt;accordance with our privacy policy &amp;lt;https://policies.google.com/privacy&amp;gt;. You may choose to opt &lt;span class="k"&gt;in &lt;/span&gt;this collection now &lt;span class="o"&gt;(&lt;/span&gt;by choosing &lt;span class="s1"&gt;'Y'&lt;/span&gt; at the below prompt&lt;span class="o"&gt;)&lt;/span&gt;, or at any &lt;span class="nb"&gt;time &lt;/span&gt;&lt;span class="k"&gt;in &lt;/span&gt;the future by running the following &lt;span class="nb"&gt;command&lt;/span&gt;:

  gcloud config &lt;span class="nb"&gt;set &lt;/span&gt;disable_usage_reporting &lt;span class="nb"&gt;false

  &lt;/span&gt;Do you want to &lt;span class="nb"&gt;help &lt;/span&gt;improve the Google Cloud SDK &lt;span class="o"&gt;(&lt;/span&gt;y/N&lt;span class="o"&gt;)&lt;/span&gt;?
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;4.&lt;/strong&gt; This will start installing the package and ask to update the &lt;code&gt;$PATH&lt;/code&gt; and enable the auto-complete feature.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  This will &lt;span class="nb"&gt;install &lt;/span&gt;all the core &lt;span class="nb"&gt;command &lt;/span&gt;line tools necessary &lt;span class="k"&gt;for &lt;/span&gt;working with the Google Cloud Platform.

  Your current Cloud SDK version is: 272.0.0
  Installing components from version: 272.0.0

  ┌────────────────────────────────────────────────────────────────────────────┐
  │                    These components will be installed.                     │
  ├─────────────────────────────────────────────────────┬────────────┬─────────┤
  │                         Name                        │  Version   │   Size  │
  ├─────────────────────────────────────────────────────┼────────────┼─────────┤
  │ BigQuery Command Line Tool                          │     2.0.50 │ &amp;lt; 1 MiB │
  │ BigQuery Command Line Tool &lt;span class="o"&gt;(&lt;/span&gt;Platform Specific&lt;span class="o"&gt;)&lt;/span&gt;      │     2.0.50 │ &amp;lt; 1 MiB │
  │ Cloud SDK Core Libraries &lt;span class="o"&gt;(&lt;/span&gt;Platform Specific&lt;span class="o"&gt;)&lt;/span&gt;        │ 2019.11.08 │ &amp;lt; 1 MiB │
  │ Cloud Storage Command Line Tool                     │       4.46 │ 3.6 MiB │
  │ Cloud Storage Command Line Tool &lt;span class="o"&gt;(&lt;/span&gt;Platform Specific&lt;span class="o"&gt;)&lt;/span&gt; │       4.46 │ &amp;lt; 1 MiB │
  │ Default &lt;span class="nb"&gt;set &lt;/span&gt;of gcloud commands                      │            │         │
  │ gcloud cli dependencies                             │ 2018.08.03 │ 8.6 MiB │
  └─────────────────────────────────────────────────────┴────────────┴─────────┘

  For the latest full release notes, please visit:
    https://cloud.google.com/sdk/release_notes

  ╔════════════════════════════════════════════════════════════╗
  ╠═ Creating update staging area                             ═╣
  ╠════════════════════════════════════════════════════════════╣
  ╠═ Installing: BigQuery Command Line Tool                   ═╣
  ╠════════════════════════════════════════════════════════════╣
  ╠═ Installing: BigQuery Command Line Tool &lt;span class="o"&gt;(&lt;/span&gt;Platform Spec... ═╣
  ╠════════════════════════════════════════════════════════════╣
  ╠═ Installing: Cloud SDK Core Libraries &lt;span class="o"&gt;(&lt;/span&gt;Platform Specific&lt;span class="o"&gt;)&lt;/span&gt; ═╣
  ╠════════════════════════════════════════════════════════════╣
  ╠═ Installing: Cloud Storage Command Line Tool              ═╣
  ╠════════════════════════════════════════════════════════════╣
  ╠═ Installing: Cloud Storage Command Line Tool &lt;span class="o"&gt;(&lt;/span&gt;Platform... ═╣
  ╠════════════════════════════════════════════════════════════╣
  ╠═ Installing: Default &lt;span class="nb"&gt;set &lt;/span&gt;of gcloud commands               ═╣
  ╠════════════════════════════════════════════════════════════╣
  ╠═ Installing: gcloud cli dependencies                      ═╣
  ╠════════════════════════════════════════════════════════════╣
  ╠═ Creating backup and activating new installation          ═╣
  ╚════════════════════════════════════════════════════════════╝

  Performing post processing steps...done.

  Update &lt;span class="k"&gt;done&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;

  Modify profile to update your &lt;span class="nv"&gt;$PATH&lt;/span&gt; and &lt;span class="nb"&gt;enable &lt;/span&gt;shell &lt;span class="nb"&gt;command
  &lt;/span&gt;completion?

  Do you want to &lt;span class="k"&gt;continue&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;Y/n&lt;span class="o"&gt;)&lt;/span&gt;? Y
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;5.&lt;/strong&gt; Provide the &lt;code&gt;bashrc&lt;/code&gt; path.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;The Google Cloud SDK installer will now prompt you to update an rc file to bring the Google Cloud CLIs into your environment.

Enter a path to an rc file to update, or leave blank to use
&lt;span class="o"&gt;[&lt;/span&gt;/home/vagrant/.bashrc]:
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;6.&lt;/strong&gt; Now, open a new terminal or reload the current session by running below command.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; &lt;span class="nv"&gt;$SHELL&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;7.&lt;/strong&gt; Verify installation.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; gcloud version
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This should list the current version of &lt;code&gt;gcloud&lt;/code&gt; utility.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  Google Cloud SDK 272.0.0
  bq 2.0.50
  core 2019.11.16
  gsutil 4.46
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;8.&lt;/strong&gt; The above script only install core packages and all we can list all the available packages.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; gcloud components list
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  Your current Cloud SDK version is: 272.0.0
  The latest available version is: 272.0.0

  ┌────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  │                                                 Components                                                 │
  ├───────────────┬──────────────────────────────────────────────────────┬──────────────────────────┬──────────┤
  │     Status    │                         Name                         │            ID            │   Size   │
  ├───────────────┼──────────────────────────────────────────────────────┼──────────────────────────┼──────────┤
  │ Not Installed │ App Engine Go Extensions                             │ app-engine-go            │  4.9 MiB │
  │ Not Installed │ Appctl                                               │ appctl                   │ 21.0 MiB │
  │ Not Installed │ Cloud Bigtable Command Line Tool                     │ cbt                      │  7.5 MiB │
  │ Not Installed │ Cloud Bigtable Emulator                              │ bigtable                 │  6.6 MiB │
  │ Not Installed │ Cloud Datalab Command Line Tool                      │ datalab                  │  &amp;lt; 1 MiB │
  │ Not Installed │ Cloud Datastore Emulator                             │ cloud-datastore-emulator │ 18.4 MiB │
  │ Not Installed │ Cloud Firestore Emulator                             │ cloud-firestore-emulator │ 40.0 MiB │
  │ Not Installed │ Cloud Pub/Sub Emulator                               │ pubsub-emulator          │ 34.9 MiB │
  │ Not Installed │ Cloud SQL Proxy                                      │ cloud_sql_proxy          │  3.8 MiB │
  │ Not Installed │ Emulator Reverse Proxy                               │ emulator-reverse-proxy   │ 14.5 MiB │
  │ Not Installed │ Google Cloud Build Local Builder                     │ cloud-build-local        │  6.0 MiB │
  │ Not Installed │ Google Container Registry's Docker credential helper │ docker-credential-gcr    │  1.8 MiB │
  │ Not Installed │ Skaffold                                             │ skaffold                 │ 22.1 MiB │
  │ Not Installed │ gcloud Alpha Commands                                │ alpha                    │  &amp;lt; 1 MiB │
  │ Not Installed │ gcloud Beta Commands                                 │ beta                     │  &amp;lt; 1 MiB │
  │ Not Installed │ gcloud app Java Extensions                           │ app-engine-java          │ 62.0 MiB │
  │ Not Installed │ gcloud app PHP Extensions                            │ app-engine-php           │          │
  │ Not Installed │ gcloud app Python Extensions                         │ app-engine-python        │  6.0 MiB │
  │ Not Installed │ gcloud app Python Extensions (Extra Libraries)       │ app-engine-python-extras │ 27.1 MiB │
  │ Not Installed │ kubectl                                              │ kubectl                  │  &amp;lt; 1 MiB │
  │ Installed     │ BigQuery Command Line Tool                           │ bq                       │  &amp;lt; 1 MiB │
  │ Installed     │ Cloud SDK Core Libraries                             │ core                     │ 12.5 MiB │
  │ Installed     │ Cloud Storage Command Line Tool                      │ gsutil                   │  3.6 MiB │
  └───────────────┴──────────────────────────────────────────────────────┴──────────────────────────┴──────────┘
  To install or remove components at your current SDK version [272.0.0], run:
    $ gcloud components install COMPONENT_ID
    $ gcloud components remove COMPONENT_ID

  To update your SDK installation to the latest version [272.0.0], run:
    $ gcloud components update
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;9.&lt;/strong&gt; Install additional component, for e.g. &lt;code&gt;kubectl&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; gcloud components &lt;span class="nb"&gt;install &lt;/span&gt;kubectl
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;10.&lt;/strong&gt; To install, &lt;code&gt;beta&lt;/code&gt; functionality&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; gcloud components &lt;span class="nb"&gt;install &lt;/span&gt;beta
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Initialize Google Cloud SDK
&lt;/h2&gt;

&lt;p&gt;Now to interact with GCP services, we must initialize SDK and setup authentication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; Initialize the SDK.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; gcloud init
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; Accept to login to your Google account.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  To continue, you must login. Would you like to log in (Y/n)? Y
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt; This will open your browser and &lt;strong&gt;prompt for permissions&lt;/strong&gt;. Login with your Google account credentials and &lt;strong&gt;Allow&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.&lt;/strong&gt; Select the preferred &lt;code&gt;project&lt;/code&gt; and &lt;code&gt;zone&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5.&lt;/strong&gt; You should now see the following message for successful initialization.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  gcloud has now been configured!
  You can use [gcloud config] to change more gcloud settings.

  Your active configuration is: [default]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;6.&lt;/strong&gt; Verify initialization.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; gcloud auth list
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This will display the active account.&lt;/p&gt;
&lt;h1&gt;
  
  
  Let's do something with gcloud
&lt;/h1&gt;
&lt;h2&gt;
  
  
  Google Cloud Storage (GCS) Bucket Operations
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; Create a GCS Bucket&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; gsutil mb gs://my-bucket-34678945/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; Create a file locally and upload to GCS Bucket.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Hello GCS"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; hello-gcs.txt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; gsutil &lt;span class="nb"&gt;cp &lt;/span&gt;hello-gcs.txt gs://my-bucket-34678945/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt; List objects in a GCS Bucket.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; gsutil &lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; gs://my-bucket-34678945/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;4.&lt;/strong&gt; Get the GCS Bucket size.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; gsutil &lt;span class="nb"&gt;du&lt;/span&gt; &lt;span class="nt"&gt;-sh&lt;/span&gt; gs://my-bucket-34678945/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;5.&lt;/strong&gt; Delete a GCS Bucket.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;warning:&lt;/strong&gt; Following command deletes all the objects stored in the specified bucket and cannot be recovered.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; gsutil &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; gs://my-bucket-34678945
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Google Compute Engine (GCE) Operation
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; Create a VM instance.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; gcloud compute instances create my-instance
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This will create a VM instance will default configuration.&lt;br&gt;&lt;br&gt;
  Output will be similar as below:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  Created &lt;span class="o"&gt;[&lt;/span&gt;https://www.googleapis.com/compute/v1/projects/your-project-id/zones/europe-west1-d/instances/my-instance].
  NAME         ZONE            MACHINE_TYPE   PREEMPTIBLE  INTERNAL_IP  EXTERNAL_IP    STATUS
  my-instance  europe-west1-d  n1-standard-1               10.132.0.3   IP.IP.IP.IP  RUNNING
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; Update VM instance and add some labels.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; gcloud compute instances update my-instance &lt;span class="se"&gt;\&lt;/span&gt;
        &lt;span class="nt"&gt;--update-labels&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;key1&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;value1,key2&lt;span class="o"&gt;=&lt;/span&gt;value2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt; Delete a VM instance.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; gcloud compute instances delete my-instance
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;




&lt;p&gt;Below is the terminal recording:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_asciinema"&gt;
  
&lt;/div&gt;



&lt;h4&gt;
  
  
  To revoke gcloud access from terminal
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; gcloud auth revoke
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Hope this blog helps you get familiar with Google Cloud SDK.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>googlecloudplatform</category>
      <category>devops</category>
      <category>gcp</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Getting started with Terraform</title>
      <dc:creator>Pradeep Bhadani</dc:creator>
      <pubDate>Sun, 08 Dec 2019 18:54:45 +0000</pubDate>
      <link>https://forem.com/pradeepbhadani/getting-started-with-terraform-36io</link>
      <guid>https://forem.com/pradeepbhadani/getting-started-with-terraform-36io</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://pbhadani.com/posts/getting-started-with-terraform/"&gt;pbhadani.com&lt;/a&gt;&lt;/em&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;
Learn to setup Terraform on your workstation in this step-by-step guide.&lt;br&gt;
&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3nnVfw97--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/f9epjiuj3zaqqwxukzva.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3nnVfw97--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/f9epjiuj3zaqqwxukzva.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;
&lt;center&gt; Photo by &lt;a href="https://unsplash.com/@firdoussross"&gt;Firdouss Ross&lt;/a&gt; on &lt;a href="https://unsplash.com"&gt;Unsplash&lt;/a&gt;
&lt;/center&gt;


&lt;h1&gt;
  
  
  What is Terraform?
&lt;/h1&gt;

&lt;p&gt;&lt;a href="//www.terraform.io"&gt;Terraform&lt;/a&gt; is an open-source tool allows to build, change and version our infrastructure in an easy and efficient way.&lt;br&gt;
It uses declarative language &lt;a href="https://github.com/hashicorp/hcl"&gt;HCL&lt;/a&gt; (Hashicorp Configuration Language) to define infrastructure as code.&lt;/p&gt;
&lt;h1&gt;
  
  
  Terraform concepts
&lt;/h1&gt;

&lt;p&gt;Let's quickly learn about some concepts in Terraform.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Providers&lt;/strong&gt;&lt;br&gt;
Terraform Providers enables interaction with APIs and handle authentication of different &lt;em&gt;IaaS&lt;/em&gt;(e.g. Google Cloud Platform, Amazon Web Service, Azure) or &lt;em&gt;SaaS&lt;/em&gt;(e.g. Cloudflare). There are many Terraform supported providers already available and a full list can be seen &lt;a href="https://www.terraform.io/docs/providers/index.html"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Resource&lt;/strong&gt;&lt;br&gt;
Terraform Resource is a very important component. Each resource block describes the infrastructure object(e.g. VM instance, Storage buckets, DNS records, Cloud NAT).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Modules&lt;/strong&gt;&lt;br&gt;
Terraform modules are the collection of resources defined in a way that can be reused.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Sources&lt;/strong&gt;&lt;br&gt;
Terraform Data Sources help to read infrastructure which is created using (or without using) Terraform.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;State&lt;/strong&gt;&lt;br&gt;
Terraform State stores information about the infrastructure created by Terraform code. It is used by Terraform to detect changes in the resources defined in the code.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Terraform state is stored on &lt;em&gt;local machine&lt;/em&gt; by default in the name of &lt;em&gt;terraform.tfstate&lt;/em&gt; but can be stored remotely on systems like Google Cloud Storage(GCS), AWS S3.&lt;/p&gt;
&lt;h1&gt;
  
  
  Let's setup Terraform
&lt;/h1&gt;

&lt;blockquote&gt;
&lt;p&gt;Below steps are for Linux based system. For MAC, download the relevant package and the rest of the steps should be the same.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Download the latest terraform package from &lt;a href="https://terraform.io/downloads.html"&gt;terraform.io/downloads&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export TF_VERSION=0.12.16
wget https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip -O /tmp/terraform.zip
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Unzip the terraform binary to a directory which is included in your system &lt;code&gt;PATH&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo unzip /tmp/terraform.zip -d /usr/local/bin/
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Reload your shell.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exec -l $SHELL
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Verify installation.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;terraform --help
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
Below is the terminal recording:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_asciinema"&gt;
  
&lt;/div&gt;
&lt;br&gt;
&lt;em&gt;Hope this blog help you get started quickly with Terraform.&lt;/em&gt;

</description>
      <category>terraform</category>
      <category>devops</category>
      <category>infrastructure</category>
    </item>
  </channel>
</rss>
