---
type: archive
area: archive
status: archived
date: 2026-05-03
created: 2026-05-03
updated: 1980-01-01
tags:
  - archive
---
- terraform validate
This command vaidate the config and checks for errors
- terraform fmt
scans conf files and format the code
- terraform show
	-json
Displays the current state of the resources
+ terraform providers
Show the providers
- terraform output
Print all the output vars in terminal
- terraform refresh
Sync terraform or update state file base on actual infrastructure
- terraform graph
Create a visual representation of dependencies in a Terraform configuration. It will generate a code used with graph tools like graphiz and with should pass the to it to generate this graph as **svg** file 
#### Mutable vs Immutable
- Immutable
means unchangeable 
terraform is immutable means that remove all the old configuration and then create the new one

#### Life cycle rules
If we update something in resources the process is :
1. Deleting the old services
2. Creating the new services with required modification
id we want to reverse this process
```python
lifecycle {
	create_before_destroy = true
}
```
or to don't delete the old resources
```python
lifecycle {
	prebvent_destroy = true
}
```
If we deploy an infrastructure using terraform after we do some changes outside of terraform for example manually in AWS
Another time when we run terraform it will detect this changes and revert it to the first state created with terraform so to prevent that we can use
``` python
lifecycle {
		ignore_changes = all
}
```

``` python
lifecycle {
		ignore_changes = [
			argument_name1, argument_name2 
		]
}
```
![[img-20240918-213415-ac7e155a.png]]
#### Data Sources
Data Sources allow terraform to read attributes from resources which are provisioned outside its control.
Example
![[img-20240918-220814-1e0b0814.png]]
In this case **dog.txt** file is created outside terrform and with this thing we bring it to terraform to use it's content with it
![[img-20240918-221122-c1eb5bd8.png]]

#### Meta argument
Can be uses with any resource block
example:
	1. depends_on
	2. lifecycle

- count
Tells terraform to create a specific resources with the value of count indicated
![[img-20240918-234411-9d6e4d84.png]]
This will create 3 files 
- Predefined terraform functions
![[img-20240918-234528-d7a50e2b.png]]
When using count the resource became a list of resources so when removing one from the list, **Terraform** state will recreate the whole resources
- For_each
Stores data as Map identified with keys (for example: {filename:unique}) 
fix the problem of updating the state if there is an update it update only the specific resource and don't touch the others
![[img-20240919-002048-77e671de.png]]
![[img-20240919-002105-ab0e0d78.png]]
- Version constraint
we can make that a specific version of provider is used when running the code
![[img-20240919-002414-4a5aa852.png]]
- tell terraform to don't use a specific version
![[img-20240919-002529-77444ff9.png]]
or 
![[img-20240919-002539-930c35dc.png]]
or
![[img-20240919-002550-8515c630.png]]
or
![[img-20240919-002719-4ecd5892.png]]
This will tell terraform to use any version from 1.2 -> 1.9

