Terraforma¶
Traduzione: Copia tutti i comandi
Traduzione: Generare PDF
< >
Comandi e flussi di lavoro completi di Terraform per Infrastructure come Code (IaC), tra cui gestione delle risorse, operazioni di stato e distribuzioni multi-cloud.
## Installazione e configurazione
|Command|Description|
|---------|-------------|
|`terraform version`|Show Terraform version|
|`terraform -help`|Show help information|
|`terraform -help plan`|Show help for specific command|
## Flusso di lavoro centrale
### Operazioni di base
|Command|Description|
|---------|-------------|
|`terraform init`|Initialize working directory|
|`terraform plan`|Create execution plan|
|`terraform apply`|Apply changes|
|`terraform destroy`|Destroy infrastructure|
|`terraform validate`|Validate configuration|
|`terraform fmt`|Format configuration files|
### Pianificazione avanzata
|Command|Description|
|---------|-------------|
|`terraform plan -out=tfplan`|Save plan to file|
|`terraform apply tfplan`|Apply saved plan|
|`terraform plan -target=resource.name`|Plan specific resource|
|`terraform plan -var="key=value"`|Plan with variables|
|`terraform plan -var-file="vars.tfvars"`|Plan with variable file|
## Gestione dello Stato
### Operazioni statali
|Command|Description|
|---------|-------------|
|`terraform state list`|List resources in state|
|`terraform state show resource.name`|Show resource details|
|`terraform state mv old_name new_name`|Move resource in state|
|`terraform state rm resource.name`|Remove resource from state|
|`terraform state pull`|Download remote state|
|`terraform state push`|Upload state to remote|
### Backup e recupero di stato
|Command|Description|
|---------|-------------|
|`terraform state backup`|Create state backup|
|`terraform force-unlock LOCK_ID`|Force unlock state|
|`terraform refresh`|Update state with real resources|
## Spazi di lavoro
|Command|Description|
|---------|-------------|
|`terraform workspace list`|List workspaces|
|`terraform workspace new dev`|Create new workspace|
|`terraform workspace select dev`|Switch to workspace|
|`terraform workspace delete dev`|Delete workspace|
|`terraform workspace show`|Show current workspace|
## Importazione e uscita
### Risorse di importazione
|Command|Description|
|---------|-------------|
|`terraform import resource.name id`|Import existing resource|
|`terraform import aws_instance.example i-1234567890abcdef0`|Import AWS instance|
### Uscite
|Command|Description|
|---------|-------------|
|`terraform output`|Show all outputs|
|`terraform output instance_ip`|Show specific output|
|`terraform output -json`|Show outputs in JSON|
## Esempi di configurazione
### AWS EC2 di base
Traduzione:
### Variabili
Traduzione:
### Fonti di dati
Traduzione:
### Moduli
Traduzione:
## Configurazione di stato remoto
### S3 Backend
Traduzione:
### Indietro di Azure
Traduzione:
### Google Cloud Backend
Traduzione:
## Configurazione del fornitore
### AWS Provider
Traduzione:
### Azure Provider
Traduzione:
### Google Cloud Provider
Traduzione:
## Caratteristiche avanzate
### Risorse condizionali
Traduzione:
### Per ogni
Traduzione:
### Blocchi Dinamici
#
## Test e convalida
### Convalida Terraform
|Command|Description|
|---------|-------------|
|`terraform validate`|Validate syntax|
|`terraform validate -json`|Validate with JSON output|
### Analisi del Piano Terraform
|Command|Description|
|---------|-------------|
|`terraform plan -detailed-exitcode`|Plan with detailed exit codes|
|`terraform show`|Show current state|
|`terraform show -json`|Show state in JSON|
### Strumenti di terze parti
|Command|Description|
|---------|-------------|
|`tflint`|Terraform linter|
|`terraform-docs`|Generate documentation|
|`checkov -f main.tf`|Security scanning|
|`tfsec .`|Security analysis|
## Debug e Risoluzione dei problemi
### Registrazione
|Command|Description|
|---------|-------------|
|`TF_LOG=DEBUG terraform plan`|Enable debug logging|
|`TF_LOG=TRACE terraform apply`|Enable trace logging|
|`TF_LOG_PATH=terraform.log terraform plan`|Log to file|
### Questioni comuni
|Command|Description|
|---------|-------------|
|`terraform refresh`|Sync state with reality|
|`terraform taint resource.name`|Mark resource for recreation|
|`terraform untaint resource.name`|Remove taint from resource|
## Migliori Pratiche
### Organizzazione dei file
Traduzione:
### Contratti di versione
Traduzione:
### Denominazione delle risorse
Traduzione:
### Migliori pratiche di sicurezza
1. - Si'. Usa lo stato remoto con la crittografia
2. ** Gestione dei segreti ** Utilizzare negozi segreti esterni
3. ** Controllo accesso**: implementare politiche IAM appropriate
4. **Code Review**: rivedere tutti i cambiamenti infrastrutturali
5. **Scanning**: Utilizzare strumenti di scansione della sicurezza
### Ottimizzazione delle prestazioni
1. **Parallelism**: Usa la bandiera `-parallelism` per grandi distribuzioni
2. **Targeting**: Usa `-target` per risorse specifiche
3. **State Spliting** Spalato grandi stati in quelli più piccoli
4. **Module Design**: Progettazione moduli riutilizzabili