You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-Local Terraform state (no remote backend configured)
20
+
-Remote Terraform state in AWS S3 with lockfile-based locking (no DynamoDB)
21
21
22
22
## Prerequisites
23
23
24
-
- Terraform `>= 1.5`
24
+
- Terraform `>= 1.11`
25
25
- AWS CLI v2 installed
26
26
- AWS identity with permissions to create VPC, IAM, EKS, and EC2 resources in your target account
27
27
@@ -71,14 +71,202 @@ If you prefer not to use `TF_VAR_aws_profile`, pass `-var="aws_profile=<your-ter
71
71
72
72
> Security note: do not commit `~/.aws/config`, `~/.aws/credentials`, or any copied credential values to git.
73
73
74
+
## Remote state backend (S3 + lockfile)
75
+
76
+
Terraform state is stored in an S3 bucket in `eu-central-1`. Locking uses Terraform's native S3 lockfile (`use_lockfile = true` in the backend block), so no DynamoDB lock table is required. The backend configuration committed in this repo only includes shared settings (`region`, `encrypt`, and `use_lockfile`); the bucket name and state key are supplied at init time via `-backend-config`.
77
+
78
+
### Bootstrap the S3 bucket (one-time)
79
+
80
+
Terraform cannot create its own backend bucket before backend initialization, so create and secure the bucket once with AWS CLI:
The identity used for Terraform backend access needs S3 permissions for `s3:GetObject`, `s3:PutObject`, `s3:DeleteObject` (lockfile lifecycle), and `s3:ListBucket` on the state bucket path.
116
+
117
+
### Authentication note
118
+
119
+
The S3 backend authenticates separately from the AWS provider configuration. If you use `TF_VAR_aws_profile` for provider auth, also set `AWS_PROFILE` or add `profile` to `backend.hcl` so `terraform init` can authenticate to S3.
120
+
121
+
### Migrate existing local state
122
+
123
+
If you already have a local `.tfstate` file, migrate it into S3 during init:
After importing, run `terraform plan` and confirm the result is ideally a no-op.
264
+
265
+
Common post-import issues:
266
+
267
+
- Subnet index/AZ mismatch can cause Terraform to propose subnet recreation; fix by swapping imported subnet indices (`public[0]`/`public[1]`, `private[0]`/`private[1]`) to match Terraform's AZ ordering.
268
+
- EKS add-on configuration drift may still appear depending on AWS-managed defaults; review and reconcile intentionally.
269
+
82
270
## Configure kubectl
83
271
84
272
After `terraform apply`, run the command from the Terraform output:
0 commit comments