Skip to content

Commit 0bcd649

Browse files
committed
Welcome to StackSimplify
1 parent f4d4c19 commit 0bcd649

File tree

575 files changed

+21433
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

575 files changed

+21433
-2
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.terraform*
2+
*.tfstate*
3+
*.tfplan

01-Terraform-Install-Tools/README.md

+184
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
---
2+
title: GCP Google Cloud Platform - Install CLI Tools
3+
description: Learn to install cli tools required for using Terraform on GCP
4+
---
5+
6+
## Step-01: Introduction
7+
1. Install gcloud CLI
8+
2. Install Terraform CLI
9+
3. Install VSCode Editor
10+
4. Install Terraform Pluging for VSCode
11+
5. Implement above 4 steps in both MacOS and WindowsOS
12+
13+
## Step-02: MacOS: Install gcloud cli and verify
14+
### Step-02-01: Install gcloud cli
15+
- [Install gcloud cli](https://cloud.google.com/sdk/docs/install-sdk#mac)
16+
```t
17+
# Verify Python Version (Supported versions are Python 3 (3.5 to 3.11, 3.11 recommended)
18+
python3 -V
19+
20+
# Determine your machine hardware
21+
uname -m
22+
23+
# Create Folder
24+
mkdir gcloud-cli-software
25+
cd gcloud-cli-software
26+
27+
# Download gcloud cli based on machine hardware
28+
## Important Note: Download the latest version available on that respective day
29+
Dowload Link: https://cloud.google.com/sdk/docs/install-sdk#mac
30+
31+
## As on today the below is the latest version (x86_64 bit)
32+
curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-479.0.0-darwin-x86_64.tar.gz
33+
34+
# Unzip binary
35+
ls -lrta
36+
tar -zxf google-cloud-cli-479.0.0-darwin-x86_64.tar.gz
37+
cd
38+
39+
# Run the install script with screen reader mode on:
40+
./google-cloud-sdk/install.sh --screen-reader=true
41+
```
42+
43+
### Step-02-02: Verify gcloud cli version
44+
```t
45+
# Open new terminal
46+
AS PATH is updated, open new terminal
47+
48+
# gcloud cli version
49+
gcloud version
50+
```
51+
52+
### Step-02-03: Intialize gcloud CLI in local Terminal
53+
```t
54+
# Initialize gcloud CLI
55+
./google-cloud-sdk/bin/gcloud init
56+
57+
# List accounts whose credentials are stored on the local system:
58+
gcloud auth list
59+
60+
# List the properties in your active gcloud CLI configuration
61+
gcloud config list
62+
63+
# View information about your gcloud CLI installation and the active configuration
64+
gcloud info
65+
66+
# gcloud config Configurations Commands (For Reference)
67+
gcloud config list
68+
gcloud config configurations list
69+
gcloud config configurations activate
70+
gcloud config configurations create
71+
gcloud config configurations delete
72+
gcloud config configurations describe
73+
gcloud config configurations rename
74+
75+
# Configure GCP Credentials (ADC: Application Default Credentials)
76+
# IMPORTANT: MANDATORY FOR TERRAFORM COMMANDS TO WORK WITH GCP FROM OUR LOCAL TERMINAL
77+
gcloud auth application-default login
78+
```
79+
80+
### Step-02-04: Install Terraform CLI using Homebrew
81+
- [Download Packages](https://developer.hashicorp.com/terraform/install#darwin)
82+
- [Install Terraform](https://developer.hashicorp.com/terraform/tutorials/gcp-get-started/install-cli)
83+
```t
84+
# Install the Hashicorp tap
85+
brew tap hashicorp/tap
86+
87+
# Install terraform
88+
brew install hashicorp/tap/terraform
89+
90+
# Update to the latest version of Terraform
91+
brew update
92+
brew upgrade hashicorp/tap/terraform
93+
```
94+
95+
### Step-02-05: Install Terraform CLI - Manually
96+
- [Download Packages](https://developer.hashicorp.com/terraform/install#darwin)
97+
- [Install Terraform](https://developer.hashicorp.com/terraform/tutorials/gcp-get-started/install-cli)
98+
```t
99+
# Copy binary zip file to a folder
100+
mkdir /Users/<YOUR-USER>/Documents/terraform-install
101+
COPY Package to "terraform-install" folder
102+
103+
# Unzip
104+
unzip <PACKAGE-NAME>
105+
unzip terraform_1.8.5_darwin_amd64.zip
106+
107+
# Copy terraform binary to /usr/local/bin
108+
echo $PATH
109+
mv terraform /usr/local/bin
110+
111+
# Verify Version
112+
terraform version
113+
114+
# To Uninstall Terraform (NOT REQUIRED)
115+
rm -rf /usr/local/bin/terraform
116+
```
117+
118+
### Step-02-06: MACOS: IDE for Terraform - VS Code Editor
119+
- [Microsoft Visual Studio Code Editor](https://code.visualstudio.com/download)
120+
- [Hashicorp Terraform Plugin for VS Code](https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform)
121+
122+
123+
## Step-03: WindowsOS: Install gcloud cli and verify
124+
### Step-03-01: Install gcloud cli on WindowsOS
125+
- [Install gcloud cli on WindowsOS](https://cloud.google.com/sdk/docs/install-sdk#windows)
126+
```t
127+
## Important Note: Download the latest version available on that respective day
128+
Dowload Link: https://cloud.google.com/sdk/docs/install-sdk#windows
129+
130+
## Run the Installer
131+
GoogleCloudSDKInstaller.exe
132+
```
133+
134+
### Step-03-02: Verify gcloud cli version
135+
```t
136+
# gcloud cli version
137+
gcloud version
138+
```
139+
140+
### Step-03-03: Intialize gcloud CLI in local Terminal
141+
```t
142+
# Initialize gcloud CLI
143+
gcloud init
144+
145+
# List accounts whose credentials are stored on the local system:
146+
gcloud auth list
147+
148+
# List the properties in your active gcloud CLI configuration
149+
gcloud config list
150+
151+
# View information about your gcloud CLI installation and the active configuration
152+
gcloud info
153+
154+
# gcloud config Configurations Commands (For Reference)
155+
gcloud config list
156+
gcloud config configurations list
157+
gcloud config configurations activate
158+
gcloud config configurations create
159+
gcloud config configurations delete
160+
gcloud config configurations describe
161+
gcloud config configurations rename
162+
163+
# Configure GCP Credentials (ADC: Application Default Credentials)
164+
gcloud auth application-default login
165+
```
166+
167+
### Step-03-04: Install Terraform CLI
168+
- [Download Terraform](https://developer.hashicorp.com/terraform/install#windows)
169+
- [Install Terraform](https://developer.hashicorp.com/terraform/tutorials/gcp-get-started/install-cli)
170+
```t
171+
# Install the Hashicorp tap
172+
choco install terraform
173+
```
174+
- Unzip the package
175+
- Create new folder `terraform-bins`
176+
- Copy the `terraform.exe` to a `terraform-bins`
177+
- Set PATH in windows
178+
179+
### Step-03-05: Windows: IDE for Terraform - VS Code Editor
180+
- [Microsoft Visual Studio Code Editor](https://code.visualstudio.com/download)
181+
- [Hashicorp Terraform Plugin for VS Code](https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform)
182+
183+
184+

02-Terraform-Commands/README.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
title: GCP Google Cloud Platform - Terraform Commands
3+
description: Learn Terraform Commands on Google Cloud
4+
---
5+
6+
## Step-01: Introduction
7+
- Understand basic Terraform Commands
8+
- terraform init
9+
- terraform validate
10+
- terraform plan
11+
- terraform apply
12+
- terraform destroy
13+
14+
## Step-02: Terraform Core Commands
15+
```t
16+
# Configure GCP Credentials (ADC: Application Default Credentials)
17+
gcloud auth application-default login
18+
19+
# Initialize Terraform
20+
terraform init
21+
Observation:
22+
1) Initialized Local Backend
23+
2) Downloaded the provider plugins (initialized plugins)
24+
3) Review the folder structure ".terraform folder"
25+
26+
# Terraform Validate
27+
terraform validate
28+
Observation:
29+
1) Tt performs a basic syntax check on your Terraform configuration files to ensure they are syntactically valid and internally consistent.
30+
2) It does not make any changes to the files themselves but verifies that the configuration is correct according to Terraform's rules.
31+
32+
33+
# Terraform Plan to Verify what it is going to create / update / destroy
34+
terraform plan
35+
Observation:
36+
1) Verify the plan
37+
2) Verify the number of resources that going to get created
38+
3) Plan Output: terraform plan generates an execution plan that shows what actions Terraform will take to achieve the desired state described in your configuration files.
39+
4) It will list resources to be created, updated, or destroyed.
40+
41+
# Terraform Apply
42+
terraform apply
43+
[or]
44+
terraform apply -auto-approve
45+
Observations:
46+
1) Will create resources on Google cloud
47+
2) Will create terraform.tfstate file when you run the terraform apply command containing all the resource information.
48+
```
49+
50+
## Step-03: Verify the Resources created on Google Cloud
51+
- Go to Google Cloud -> VPC Networks -> vpc1
52+
53+
54+
## Step-04: Destroy Infrastructure
55+
```t
56+
# Destroy EC2 Instance
57+
terraform destroy
58+
59+
# Delete Terraform files
60+
rm -rf .terraform*
61+
rm -rf terraform.tfstate*
62+
```
63+
64+
## Step-05: Conclusion
65+
- Re-iterate what we have learned in this section
66+
- Learned about Important Terraform Commands
67+
- terraform init
68+
- terraform validate
69+
- terraform plan
70+
- terraform apply
71+
- terraform destroy
72+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Terraform Provider Configuration: google
2+
provider "google" {
3+
project = "gcplearn9"
4+
region = "us-central1"
5+
}
6+
7+
# Resource: VPC
8+
resource "google_compute_network" "myvpc" {
9+
name = "vpc1"
10+
auto_create_subnetworks = false
11+
}
12+
13+
# Resource: Subnet
14+
resource "google_compute_subnetwork" "mysubnet" {
15+
name = "subnet1"
16+
region = "us-central1"
17+
ip_cidr_range = "10.128.0.0/20"
18+
network = google_compute_network.myvpc.id // GET VPC ID
19+
}
20+

0 commit comments

Comments
 (0)