Best Practices - Terraform Provider
Learn best practices for using the Azion Terraform Provider. Organize your code, manage states, and implement CI/CD efficiently.
Learn best practices for using the Azion Terraform Provider efficiently and securely.
Code Organization
Directory Structure
Organize your Terraform files logically:
Naming Conventions
Use descriptive and consistent names:
State Management
Remote Backend
Always use a remote backend to store state:
Locking
Use locking to prevent conflicts:
Security
Sensitive Variables
Mark sensitive variables as sensitive:
Don’t Commit Secrets
Add to .gitignore:
Use Environment Variables
Modularization
Creating Modules
Create reusable modules:
Using Modules
CI/CD
Basic Pipeline
Example with GitHub Actions:
Versioning
Pin Versions
Always pin the provider version:
Use .terraform-version
For projects with multiple versions:
Outputs
Export Important IDs
Use Outputs in Modules
Dependencies
Depends_On
Use depends_on for implicit dependencies:
Implicit References
Prefer direct references:
Documentation
Comment Your Code
README
Create a README.md for each module:
Inputs
| Name | Description | Type | Default |
|---|---|---|---|
| name | Workload name | string | n/a |
Outputs
| Name | Description |
|---|---|
| workload_id | Workload ID |