Skip to content

Commit ba2dde9

Browse files
feat: add Terraform notes (#111)
1 parent 77fd595 commit ba2dde9

31 files changed

+1102
-31
lines changed

Diff for: .gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ yarn-error.log*
2323
.DS_Store
2424
.vercel
2525
TODO.md
26+
.terraform
27+
.terraform.lock.hcl
28+
terraform.tfstate
29+
terraform.tfstate.backup

Diff for: README.md

+9-27
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
- [Compose/Stack Files](https://github.com/Pradumnasaraf/DevOps/tree/main/docs/docker/docker-compose)
1313
- [Dockerfile](https://github.com/Pradumnasaraf/DevOps/tree/main/docs/docker/dockerfiles)
1414

15-
<be>
16-
1715
## Kubernetes
1816

1917
<img align="right" src="https://user-images.githubusercontent.com/51878265/200594367-f416d081-af8f-4f48-8008-998d005b317f.png" height="100" alt="Kubernetes">
@@ -27,8 +25,6 @@
2725
- [Playground](docs/kubernetes/playground.md)
2826
- [Other Resources](docs/kubernetes/other-resources.md)
2927

30-
<br>
31-
3228
## GitHub Actions
3329

3430
<img align="right" src="https://user-images.githubusercontent.com/51878265/211621722-c2ddc389-6e4e-4769-9dac-f18f8e71fed3.png" height="100" alt="GitHub Action">
@@ -38,9 +34,7 @@
3834
- [Workflows](https://github.com/Pradumnasaraf/DevOps/tree/main/docs/github-actions/Workflows)
3935
- [Scenarios](docs/github-actions/scenarios.md)
4036
- [Other Resources](docs/github-actions/other-resources.md)
41-
42-
<br>
43-
37+
-
4438
## Linux
4539

4640
<img align="right" src="https://user-images.githubusercontent.com/51878265/209197882-51406a8f-04ff-4c53-a362-ac32ae8566ad.png" height="100" alt="linux">
@@ -49,7 +43,6 @@
4943
- [Learning Resources](docs/linux/learning-resources.md)
5044
- [Commands](docs/linux/commands.md)
5145

52-
<br>
5346

5447
## Git
5548

@@ -59,8 +52,6 @@
5952
- [Learning Resources](docs/git/learning-resources.md)
6053
- [Commands](docs/git/commands.md)
6154

62-
<br>
63-
6455
## Networking
6556

6657
<img align="right" src="https://user-images.githubusercontent.com/51878265/204347251-efd0e271-5d3c-4008-bdab-6f6ce5b2195f.png" height="100" alt="network">
@@ -69,17 +60,13 @@
6960
- [Learning Resources](docs/networking/learning-resources.md)
7061
- [Commands](docs/networking/commands.md)
7162

72-
<br>
73-
7463
## YAML
7564

7665
<img align="right" src="https://user-images.githubusercontent.com/51878265/202765143-55758916-b631-4c18-aaad-718b42507d67.png" height="100" alt="YAML">
7766

7867
- [Notes](docs/yaml/introduction.md)
7968
- [Learning Resources](docs/yaml/learning-resources.md)
8069

81-
<br>
82-
8370
## Golang (Go)
8471

8572
<img align="right" src="https://user-images.githubusercontent.com/51878265/213385507-52f03107-388c-4992-9b5e-c89de6906e37.png" height="100" alt="network">
@@ -90,8 +77,6 @@
9077
- [Practice App](https://github.com/Pradumnasaraf/DevOps/tree/main/docs/golang/apps)
9178
- [Other Resources](docs/go/other-resources.md)
9279

93-
<br>
94-
9580
## Helm
9681

9782
<img align="right" src="https://user-images.githubusercontent.com/51878265/202859249-b90ac510-d8e8-408d-9c07-0d2bd8e1b092.png" height="100" alt="Helm">
@@ -100,26 +85,20 @@
10085
- [Learning Resources](docs/helm/learning-resources.md)
10186
- [Charts](https://github.com/Pradumnasaraf/DevOps/tree/main/docs/helm/charts)
10287

103-
<br>
104-
10588
## Prometheus
10689

10790
<img align="right" src="https://user-images.githubusercontent.com/51878265/202859485-eba6809e-1cb8-4bbc-ab22-efa3c91d6463.png" height="100" alt="Prometheus">
10891

10992
- [Notes](docs/prometheus/introduction.md)
11093
- [Learning Resources](docs/prometheus/learning-resources.md)
11194

112-
<br>
113-
11495
## GitOps
11596

11697
<img align="right" src="https://user-images.githubusercontent.com/51878265/206730962-b20f94c1-17af-48b2-b62c-b6c02dbeeb77.png" height="100" alt="Gitops">
11798

11899
- [Notes](docs/gitops/introduction.md)
119100
- [Learning Resources](docs/gitops/learning-resources.md)
120101

121-
<br>
122-
123102
## ArgoCD
124103

125104
<img align="right" src="https://user-images.githubusercontent.com/51878265/205495495-b3f0b395-3ce3-42d8-9274-220ff10334f6.png" height="100" alt="Argo">
@@ -128,16 +107,13 @@
128107
- [Learning Resources](docs/argocd/learning-resources.md)
129108
- [Manifest Files](https://github.com/Pradumnasaraf/DevOps/tree/main/docs/argocd/manifests)
130109

131-
<br>
132-
133110
## Jenkins
134111

135112
<img align="right" src="https://user-images.githubusercontent.com/51878265/209197795-570330e6-fbee-4bf3-a42e-b8609e3afc46.png" height="100" alt="Jenkins">
136113

137114
- [Notes](docs/jenkins/introduction.md)
138115
- [Learning Resources](docs/jenkins/learning-resources.md)
139116
- [Jenkinsfile](https://github.com/Pradumnasaraf/DevOps/tree/main/docs/jenkins/jenkinsfiles)
140-
<br>
141117

142118
## Bash Scripting
143119

@@ -147,8 +123,6 @@
147123
- [Learning Resources](docs/bash-scripting/learning-resources.md)
148124
- [Script](https://github.com/Pradumnasaraf/DevOps/tree/main/docs/bash-scripting/scripts)
149125

150-
<br>
151-
152126
## WebAssembly (WASM)
153127

154128
<img align="right" src="https://github.com/user-attachments/assets/0687a31f-fa90-4aeb-b3f2-b841d8758f77" height="100" alt="Wasm">
@@ -157,3 +131,11 @@
157131
- [Learning Resources](docs/webassembly/learning-resources.md)
158132
- [Tools](docs/webassembly/tools.md)
159133
- [Files and Sample Apps](https://github.com/Pradumnasaraf/DevOps/tree/main/docs/webassembly/files)
134+
135+
## Terraform
136+
137+
<img align="right" src="https://github.com/user-attachments/assets/b81903bd-4377-4517-a1fd-8e6c99bdfa9a" height="100" alt="Terraform">
138+
139+
- [Notes](docs/terraform/introduction.md)
140+
- [Learning Resources](docs/terraform/learning-resources.md)
141+
- [Commands](docs/terraform/commands.md)

Diff for: docs/devsecops/_category_.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"label": "DevSecOps",
3-
"position": 18
3+
"position": 19
44
}

Diff for: docs/feedback.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 20
2+
sidebar_position: 21
33
description: Feedback and suggestions
44
title: Feedback & Suggestions
55

Diff for: docs/qna.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
sidebar_position: 19
2+
sidebar_position: 20
33
description: Questions and answers about DevOps
44
title: Q&A
55

Diff for: docs/terraform/_category_.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"label": "Terraform",
3+
"position": 18
4+
}

Diff for: docs/terraform/commands.md

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
sidebar_position: 3
3+
title: Terraform Commands
4+
description: Terraform commands and their usage
5+
tags: ["Terraform", "Infrastructure as Code", "HashiCorp"]
6+
keywords: ["Terraform", "Infrastructure as Code", "HashiCorp"]
7+
slug: "/terraform/commands"
8+
---
9+
10+
1. Terraform Init
11+
12+
It is used to initialize a working directory containing Terraform configuration files.
13+
14+
```bash
15+
terraform init
16+
```
17+
18+
2. Terraform Plan
19+
20+
It is used to create an execution plan. It shows what Terraform will do when you call apply.
21+
22+
```bash
23+
terraform plan
24+
```
25+
26+
3. Terraform Apply
27+
28+
It is used to apply the changes required to reach the desired state of the configuration.
29+
30+
```bash
31+
terraform apply
32+
```
33+
34+
4. Terraform Validate
35+
36+
We can run this command before applying the changes to check whether the configuration is syntactically valid and internally consistent.
37+
38+
```bash
39+
terraform validate
40+
```
41+
42+
It will print the exact in the console if there is any error in the configuration file.
43+
44+
5. Terraform Format
45+
46+
It is used to rewrite Terraform configuration files to canonical format and style.
47+
48+
```bash
49+
terraform fmt
50+
```
51+
52+
6. Terraform Show
53+
54+
It is used to provide human-readable output of current state of the resources.
55+
56+
```bash
57+
terraform show
58+
```
59+
60+
We can also output the state in JSON format by using the following command:
61+
62+
```bash
63+
terraform show -json
64+
```
65+
66+
7. Terraform Providers
67+
68+
To know the list of providers used in the configuration file, we can use the following command:
69+
70+
```bash
71+
terraform providers
72+
```
73+
74+
To mirror the provider configurations from the configuration file, we can use the following command:
75+
76+
```bash
77+
terraform providers mirror ./path/to/new_local_file
78+
```
79+
80+
8. Terraform Output
81+
82+
It is used to extract the output variables from the state file.
83+
84+
```bash
85+
terraform output
86+
```
87+
88+
9. Terraform Refresh
89+
90+
It is used to update the state file according to the real-world infrastructure.
91+
92+
```bash
93+
terraform plan
94+
```
95+
96+
or
97+
98+
```bash
99+
terraform apply -refresh-only
100+
```
101+
102+
10. Terraform Graph
103+
104+
It is used to generate a visual representation of the configuration and state file.
105+
106+
```bash
107+
terraform graph
108+
```
109+
110+
11. Terraform Destroy
111+
112+
It is used to destroy the Terraform-managed infrastructure.
113+
114+
```bash
115+
terraform destroy
116+
```

Diff for: docs/terraform/files/Terraform-KodeKloud.pdf

5.84 MB
Binary file not shown.

Diff for: docs/terraform/files/count/main.tf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
resource "local_file" "pet" {
2+
count = length(var.pet_filenames)
3+
filename = var.pet_filenames[count.index]
4+
content = "This is a file named ${var.pet_filenames[count.index]}"
5+
}
6+
7+
output "pets" {
8+
value = local_file.pet
9+
}

Diff for: docs/terraform/files/count/variable.tf

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
variable "pet_filenames" {
2+
default = [
3+
"./cats.txt",
4+
"./dogs.txt",
5+
"./fish.txt",
6+
"./birds.txt",
7+
]
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
resource local_file "my-file" {
2+
content = "I love Pets"
3+
filename = "/tmp/my-file.txt"
4+
depends_on = [random_pet.my-pet]
5+
}
6+
resource random_pet "my-pet" {
7+
prefix = "Mrs"
8+
separator = "."
9+
length = "1"
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
resource local_file "my-file" {
2+
content = "My pet is ${random_pet.my-pet.id}"
3+
filename = "/tmp/my-file.txt"
4+
}
5+
resource random_pet "my-pet" {
6+
prefix = "Mrs"
7+
separator = "."
8+
length = "1"
9+
}

Diff for: docs/terraform/files/interactive-mode/hello.tf

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resource "local_file" hello{
2+
filename = "./hello.txt"
3+
content = var.say_hello
4+
file_permission = "0700"
5+
}

Diff for: docs/terraform/files/interactive-mode/hello.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Helloo

Diff for: docs/terraform/files/interactive-mode/variables.tf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
variable "say_hello" {
2+
description = "The message to write to the file"
3+
type = string
4+
}

Diff for: docs/terraform/files/local-files/local.tf

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resource "local_file" "pet" {
2+
filename = "./pets.txt"
3+
content = "We love pets!"
4+
file_permission = "0700"
5+
}

Diff for: docs/terraform/files/multiple-providers/my-pets.tf

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
resource "local_file" "pet" {
2+
filename = "./pets.txt"
3+
content = "We love pets!"
4+
}
5+
6+
resource "random_pet" "my-pet" {
7+
prefix = "Mrs"
8+
separator = "."
9+
length = "1"
10+
}

Diff for: docs/terraform/files/output-values/main.tf

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resource "random_pet" "my-pet" {
2+
prefix = "Mrs"
3+
separator = "."
4+
length = "1"
5+
}

Diff for: docs/terraform/files/output-values/outputs.tf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "pet_name" {
2+
value = random_pet.my-pet.id # The random pet name from main.tf
3+
description = "The random pet name generated by Terraform"
4+
}

Diff for: docs/terraform/files/variable-definition/hello.tf

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resource "local_file" hello{
2+
filename = "./hello.txt"
3+
content = var.say_hello
4+
file_permission = "0700"
5+
}

Diff for: docs/terraform/files/variable-definition/hello.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello World
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
say_hello = "Hello World"
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
variable "say_hello" {
2+
description = "The message to write to the file"
3+
type = string
4+
}

0 commit comments

Comments
 (0)