Skip to content

Commit

Permalink
feat: add Terraform notes (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pradumnasaraf authored Jan 20, 2025
1 parent 77fd595 commit ba2dde9
Show file tree
Hide file tree
Showing 31 changed files with 1,102 additions and 31 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ yarn-error.log*
.DS_Store
.vercel
TODO.md
.terraform
.terraform.lock.hcl
terraform.tfstate
terraform.tfstate.backup
36 changes: 9 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
- [Compose/Stack Files](https://github.com/Pradumnasaraf/DevOps/tree/main/docs/docker/docker-compose)
- [Dockerfile](https://github.com/Pradumnasaraf/DevOps/tree/main/docs/docker/dockerfiles)

<be>

## Kubernetes

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

<br>

## GitHub Actions

<img align="right" src="https://user-images.githubusercontent.com/51878265/211621722-c2ddc389-6e4e-4769-9dac-f18f8e71fed3.png" height="100" alt="GitHub Action">
Expand All @@ -38,9 +34,7 @@
- [Workflows](https://github.com/Pradumnasaraf/DevOps/tree/main/docs/github-actions/Workflows)
- [Scenarios](docs/github-actions/scenarios.md)
- [Other Resources](docs/github-actions/other-resources.md)

<br>

-
## Linux

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

<br>

## Git

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

<br>

## Networking

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

<br>

## YAML

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

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

<br>

## Golang (Go)

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

<br>

## Helm

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

<br>

## Prometheus

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

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

<br>

## GitOps

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

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

<br>

## ArgoCD

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

<br>

## Jenkins

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

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

## Bash Scripting

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

<br>

## WebAssembly (WASM)

<img align="right" src="https://github.com/user-attachments/assets/0687a31f-fa90-4aeb-b3f2-b841d8758f77" height="100" alt="Wasm">
Expand All @@ -157,3 +131,11 @@
- [Learning Resources](docs/webassembly/learning-resources.md)
- [Tools](docs/webassembly/tools.md)
- [Files and Sample Apps](https://github.com/Pradumnasaraf/DevOps/tree/main/docs/webassembly/files)

## Terraform

<img align="right" src="https://github.com/user-attachments/assets/b81903bd-4377-4517-a1fd-8e6c99bdfa9a" height="100" alt="Terraform">

- [Notes](docs/terraform/introduction.md)
- [Learning Resources](docs/terraform/learning-resources.md)
- [Commands](docs/terraform/commands.md)
2 changes: 1 addition & 1 deletion docs/devsecops/_category_.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"label": "DevSecOps",
"position": 18
"position": 19
}
2 changes: 1 addition & 1 deletion docs/feedback.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 20
sidebar_position: 21
description: Feedback and suggestions
title: Feedback & Suggestions

Expand Down
2 changes: 1 addition & 1 deletion docs/qna.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 19
sidebar_position: 20
description: Questions and answers about DevOps
title: Q&A

Expand Down
4 changes: 4 additions & 0 deletions docs/terraform/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "Terraform",
"position": 18
}
116 changes: 116 additions & 0 deletions docs/terraform/commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
sidebar_position: 3
title: Terraform Commands
description: Terraform commands and their usage
tags: ["Terraform", "Infrastructure as Code", "HashiCorp"]
keywords: ["Terraform", "Infrastructure as Code", "HashiCorp"]
slug: "/terraform/commands"
---

1. Terraform Init

It is used to initialize a working directory containing Terraform configuration files.

```bash
terraform init
```

2. Terraform Plan

It is used to create an execution plan. It shows what Terraform will do when you call apply.

```bash
terraform plan
```

3. Terraform Apply

It is used to apply the changes required to reach the desired state of the configuration.

```bash
terraform apply
```

4. Terraform Validate

We can run this command before applying the changes to check whether the configuration is syntactically valid and internally consistent.

```bash
terraform validate
```

It will print the exact in the console if there is any error in the configuration file.

5. Terraform Format

It is used to rewrite Terraform configuration files to canonical format and style.

```bash
terraform fmt
```

6. Terraform Show

It is used to provide human-readable output of current state of the resources.

```bash
terraform show
```

We can also output the state in JSON format by using the following command:

```bash
terraform show -json
```

7. Terraform Providers

To know the list of providers used in the configuration file, we can use the following command:

```bash
terraform providers
```

To mirror the provider configurations from the configuration file, we can use the following command:

```bash
terraform providers mirror ./path/to/new_local_file
```

8. Terraform Output

It is used to extract the output variables from the state file.

```bash
terraform output
```

9. Terraform Refresh

It is used to update the state file according to the real-world infrastructure.

```bash
terraform plan
```

or

```bash
terraform apply -refresh-only
```

10. Terraform Graph

It is used to generate a visual representation of the configuration and state file.

```bash
terraform graph
```

11. Terraform Destroy

It is used to destroy the Terraform-managed infrastructure.

```bash
terraform destroy
```
Binary file added docs/terraform/files/Terraform-KodeKloud.pdf
Binary file not shown.
9 changes: 9 additions & 0 deletions docs/terraform/files/count/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "local_file" "pet" {
count = length(var.pet_filenames)
filename = var.pet_filenames[count.index]
content = "This is a file named ${var.pet_filenames[count.index]}"
}

output "pets" {
value = local_file.pet
}
8 changes: 8 additions & 0 deletions docs/terraform/files/count/variable.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
variable "pet_filenames" {
default = [
"./cats.txt",
"./dogs.txt",
"./fish.txt",
"./birds.txt",
]
}
10 changes: 10 additions & 0 deletions docs/terraform/files/dependencies-type/explicit/explicit.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resource local_file "my-file" {
content = "I love Pets"
filename = "/tmp/my-file.txt"
depends_on = [random_pet.my-pet]
}
resource random_pet "my-pet" {
prefix = "Mrs"
separator = "."
length = "1"
}
9 changes: 9 additions & 0 deletions docs/terraform/files/dependencies-type/implicit/implicit.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource local_file "my-file" {
content = "My pet is ${random_pet.my-pet.id}"
filename = "/tmp/my-file.txt"
}
resource random_pet "my-pet" {
prefix = "Mrs"
separator = "."
length = "1"
}
5 changes: 5 additions & 0 deletions docs/terraform/files/interactive-mode/hello.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "local_file" hello{
filename = "./hello.txt"
content = var.say_hello
file_permission = "0700"
}
1 change: 1 addition & 0 deletions docs/terraform/files/interactive-mode/hello.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Helloo
4 changes: 4 additions & 0 deletions docs/terraform/files/interactive-mode/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "say_hello" {
description = "The message to write to the file"
type = string
}
5 changes: 5 additions & 0 deletions docs/terraform/files/local-files/local.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "local_file" "pet" {
filename = "./pets.txt"
content = "We love pets!"
file_permission = "0700"
}
10 changes: 10 additions & 0 deletions docs/terraform/files/multiple-providers/my-pets.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resource "local_file" "pet" {
filename = "./pets.txt"
content = "We love pets!"
}

resource "random_pet" "my-pet" {
prefix = "Mrs"
separator = "."
length = "1"
}
5 changes: 5 additions & 0 deletions docs/terraform/files/output-values/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "random_pet" "my-pet" {
prefix = "Mrs"
separator = "."
length = "1"
}
4 changes: 4 additions & 0 deletions docs/terraform/files/output-values/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "pet_name" {
value = random_pet.my-pet.id # The random pet name from main.tf
description = "The random pet name generated by Terraform"
}
5 changes: 5 additions & 0 deletions docs/terraform/files/variable-definition/hello.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "local_file" hello{
filename = "./hello.txt"
content = var.say_hello
file_permission = "0700"
}
1 change: 1 addition & 0 deletions docs/terraform/files/variable-definition/hello.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World
1 change: 1 addition & 0 deletions docs/terraform/files/variable-definition/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
say_hello = "Hello World"
4 changes: 4 additions & 0 deletions docs/terraform/files/variable-definition/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "say_hello" {
description = "The message to write to the file"
type = string
}
Loading

0 comments on commit ba2dde9

Please sign in to comment.