Terraform Backend:
- store statefile in remote location.
- terraform.tfstate
types:
- local: its store file in local
- remote : its store file in remote
AWS Backend Flow
flowchart TD
A[terraform init] --> B[Read backend config: S3 bucket + DynamoDB table]
B --> C{State file exists in S3?}
C -->|Yes| D[Download state from S3]
C -->|No| E[Initialize empty state]
D --> F[terraform plan / apply]
E --> F
F --> G[Acquire lock: write LockID item to DynamoDB]
G --> H{Lock acquired?}
H -->|No| I[Error: state locked by another user/process]
H -->|Yes| J[Execute plan/apply against AWS resources]
J --> K[Write updated state back to S3 bucket]
K --> L[Release lock: delete LockID item from DynamoDB]
Task:
- create github workflow for terraform and configure cridentals in secrets
- steps:
- checkout
- install/setup terraform
- aws cridentals configure
- terrform init
- terraform fmt
- terraform validate
- if condition terraform action – plan , apply, none
- paln
- plan and apply -auto-approve
