tf-starter 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +421 -0
  3. package/bin/tf-starter.js +88 -0
  4. package/package.json +43 -0
  5. package/scripts/postinstall.js +105 -0
  6. package/setup.py +32 -0
  7. package/tf_starter/__init__.py +3 -0
  8. package/tf_starter/__main__.py +6 -0
  9. package/tf_starter/cli.py +379 -0
  10. package/tf_starter/generator.py +171 -0
  11. package/tf_starter/template_engine.py +80 -0
  12. package/tf_starter/templates/aws/environments/backend.tf.j2 +16 -0
  13. package/tf_starter/templates/aws/environments/main.tf.j2 +85 -0
  14. package/tf_starter/templates/aws/environments/terraform.tfvars.j2 +52 -0
  15. package/tf_starter/templates/aws/environments/variables.tf.j2 +127 -0
  16. package/tf_starter/templates/aws/github/terraform.yml.j2 +133 -0
  17. package/tf_starter/templates/aws/misc/Makefile.j2 +60 -0
  18. package/tf_starter/templates/aws/misc/README.md.j2 +445 -0
  19. package/tf_starter/templates/aws/misc/init.sh.j2 +110 -0
  20. package/tf_starter/templates/aws/misc/pre-commit-config.yaml.j2 +34 -0
  21. package/tf_starter/templates/aws/modules/apigateway/main.tf.j2 +224 -0
  22. package/tf_starter/templates/aws/modules/apigateway/outputs.tf.j2 +28 -0
  23. package/tf_starter/templates/aws/modules/apigateway/variables.tf.j2 +69 -0
  24. package/tf_starter/templates/aws/modules/compute/main.tf.j2 +245 -0
  25. package/tf_starter/templates/aws/modules/compute/outputs.tf.j2 +38 -0
  26. package/tf_starter/templates/aws/modules/compute/variables.tf.j2 +68 -0
  27. package/tf_starter/templates/aws/modules/database/main.tf.j2 +122 -0
  28. package/tf_starter/templates/aws/modules/database/outputs.tf.j2 +33 -0
  29. package/tf_starter/templates/aws/modules/database/variables.tf.j2 +63 -0
  30. package/tf_starter/templates/aws/modules/kubernetes/main.tf.j2 +167 -0
  31. package/tf_starter/templates/aws/modules/kubernetes/outputs.tf.j2 +33 -0
  32. package/tf_starter/templates/aws/modules/kubernetes/variables.tf.j2 +64 -0
  33. package/tf_starter/templates/aws/modules/lambda/main.tf.j2 +215 -0
  34. package/tf_starter/templates/aws/modules/lambda/outputs.tf.j2 +38 -0
  35. package/tf_starter/templates/aws/modules/lambda/variables.tf.j2 +88 -0
  36. package/tf_starter/templates/aws/modules/messaging/main.tf.j2 +85 -0
  37. package/tf_starter/templates/aws/modules/messaging/outputs.tf.j2 +28 -0
  38. package/tf_starter/templates/aws/modules/messaging/variables.tf.j2 +41 -0
  39. package/tf_starter/templates/aws/modules/monitoring/main.tf.j2 +155 -0
  40. package/tf_starter/templates/aws/modules/monitoring/outputs.tf.j2 +23 -0
  41. package/tf_starter/templates/aws/modules/monitoring/variables.tf.j2 +39 -0
  42. package/tf_starter/templates/aws/modules/network/main.tf.j2 +147 -0
  43. package/tf_starter/templates/aws/modules/network/outputs.tf.j2 +33 -0
  44. package/tf_starter/templates/aws/modules/network/variables.tf.j2 +52 -0
  45. package/tf_starter/templates/aws/modules/storage/main.tf.j2 +88 -0
  46. package/tf_starter/templates/aws/modules/storage/outputs.tf.j2 +23 -0
  47. package/tf_starter/templates/aws/modules/storage/variables.tf.j2 +25 -0
  48. package/tf_starter/templates/aws/root/backend.tf.j2 +19 -0
  49. package/tf_starter/templates/aws/root/main.tf.j2 +219 -0
  50. package/tf_starter/templates/aws/root/outputs.tf.j2 +134 -0
  51. package/tf_starter/templates/aws/root/providers.tf.j2 +24 -0
  52. package/tf_starter/templates/aws/root/variables.tf.j2 +300 -0
  53. package/tf_starter/templates/aws/root/versions.tf.j2 +26 -0
  54. package/tf_starter/templates/azure/environments/backend.tf.j2 +11 -0
  55. package/tf_starter/templates/azure/environments/main.tf.j2 +57 -0
  56. package/tf_starter/templates/azure/environments/terraform.tfvars.j2 +14 -0
  57. package/tf_starter/templates/azure/environments/variables.tf.j2 +30 -0
  58. package/tf_starter/templates/azure/github/terraform.yml.j2 +133 -0
  59. package/tf_starter/templates/azure/misc/Makefile.j2 +60 -0
  60. package/tf_starter/templates/azure/misc/README.md.j2 +426 -0
  61. package/tf_starter/templates/azure/misc/init.sh.j2 +110 -0
  62. package/tf_starter/templates/azure/misc/pre-commit-config.yaml.j2 +34 -0
  63. package/tf_starter/templates/azure/modules/apigateway/main.tf.j2 +125 -0
  64. package/tf_starter/templates/azure/modules/apigateway/outputs.tf.j2 +18 -0
  65. package/tf_starter/templates/azure/modules/apigateway/variables.tf.j2 +54 -0
  66. package/tf_starter/templates/azure/modules/compute/main.tf.j2 +114 -0
  67. package/tf_starter/templates/azure/modules/compute/outputs.tf.j2 +9 -0
  68. package/tf_starter/templates/azure/modules/compute/variables.tf.j2 +23 -0
  69. package/tf_starter/templates/azure/modules/database/main.tf.j2 +56 -0
  70. package/tf_starter/templates/azure/modules/database/outputs.tf.j2 +13 -0
  71. package/tf_starter/templates/azure/modules/database/variables.tf.j2 +38 -0
  72. package/tf_starter/templates/azure/modules/kubernetes/main.tf.j2 +50 -0
  73. package/tf_starter/templates/azure/modules/kubernetes/outputs.tf.j2 +19 -0
  74. package/tf_starter/templates/azure/modules/kubernetes/variables.tf.j2 +37 -0
  75. package/tf_starter/templates/azure/modules/lambda/main.tf.j2 +98 -0
  76. package/tf_starter/templates/azure/modules/lambda/outputs.tf.j2 +23 -0
  77. package/tf_starter/templates/azure/modules/lambda/variables.tf.j2 +53 -0
  78. package/tf_starter/templates/azure/modules/messaging/main.tf.j2 +29 -0
  79. package/tf_starter/templates/azure/modules/messaging/outputs.tf.j2 +14 -0
  80. package/tf_starter/templates/azure/modules/messaging/variables.tf.j2 +11 -0
  81. package/tf_starter/templates/azure/modules/monitoring/main.tf.j2 +31 -0
  82. package/tf_starter/templates/azure/modules/monitoring/outputs.tf.j2 +9 -0
  83. package/tf_starter/templates/azure/modules/monitoring/variables.tf.j2 +16 -0
  84. package/tf_starter/templates/azure/modules/network/main.tf.j2 +89 -0
  85. package/tf_starter/templates/azure/modules/network/outputs.tf.j2 +25 -0
  86. package/tf_starter/templates/azure/modules/network/variables.tf.j2 +25 -0
  87. package/tf_starter/templates/azure/modules/storage/main.tf.j2 +41 -0
  88. package/tf_starter/templates/azure/modules/storage/outputs.tf.j2 +17 -0
  89. package/tf_starter/templates/azure/modules/storage/variables.tf.j2 +16 -0
  90. package/tf_starter/templates/azure/root/backend.tf.j2 +11 -0
  91. package/tf_starter/templates/azure/root/main.tf.j2 +181 -0
  92. package/tf_starter/templates/azure/root/outputs.tf.j2 +45 -0
  93. package/tf_starter/templates/azure/root/providers.tf.j2 +18 -0
  94. package/tf_starter/templates/azure/root/variables.tf.j2 +114 -0
  95. package/tf_starter/templates/azure/root/versions.tf.j2 +16 -0
  96. package/tf_starter/templates/gcp/environments/backend.tf.j2 +9 -0
  97. package/tf_starter/templates/gcp/environments/main.tf.j2 +58 -0
  98. package/tf_starter/templates/gcp/environments/terraform.tfvars.j2 +12 -0
  99. package/tf_starter/templates/gcp/environments/variables.tf.j2 +21 -0
  100. package/tf_starter/templates/gcp/github/terraform.yml.j2 +133 -0
  101. package/tf_starter/templates/gcp/misc/Makefile.j2 +60 -0
  102. package/tf_starter/templates/gcp/misc/README.md.j2 +426 -0
  103. package/tf_starter/templates/gcp/misc/init.sh.j2 +110 -0
  104. package/tf_starter/templates/gcp/misc/pre-commit-config.yaml.j2 +34 -0
  105. package/tf_starter/templates/gcp/modules/apigateway/main.tf.j2 +67 -0
  106. package/tf_starter/templates/gcp/modules/apigateway/outputs.tf.j2 +18 -0
  107. package/tf_starter/templates/gcp/modules/apigateway/variables.tf.j2 +34 -0
  108. package/tf_starter/templates/gcp/modules/compute/main.tf.j2 +138 -0
  109. package/tf_starter/templates/gcp/modules/compute/outputs.tf.j2 +13 -0
  110. package/tf_starter/templates/gcp/modules/compute/variables.tf.j2 +33 -0
  111. package/tf_starter/templates/gcp/modules/database/main.tf.j2 +62 -0
  112. package/tf_starter/templates/gcp/modules/database/outputs.tf.j2 +13 -0
  113. package/tf_starter/templates/gcp/modules/database/variables.tf.j2 +29 -0
  114. package/tf_starter/templates/gcp/modules/kubernetes/main.tf.j2 +75 -0
  115. package/tf_starter/templates/gcp/modules/kubernetes/outputs.tf.j2 +14 -0
  116. package/tf_starter/templates/gcp/modules/kubernetes/variables.tf.j2 +38 -0
  117. package/tf_starter/templates/gcp/modules/lambda/main.tf.j2 +122 -0
  118. package/tf_starter/templates/gcp/modules/lambda/outputs.tf.j2 +18 -0
  119. package/tf_starter/templates/gcp/modules/lambda/variables.tf.j2 +77 -0
  120. package/tf_starter/templates/gcp/modules/messaging/main.tf.j2 +44 -0
  121. package/tf_starter/templates/gcp/modules/messaging/outputs.tf.j2 +13 -0
  122. package/tf_starter/templates/gcp/modules/messaging/variables.tf.j2 +20 -0
  123. package/tf_starter/templates/gcp/modules/monitoring/main.tf.j2 +44 -0
  124. package/tf_starter/templates/gcp/modules/monitoring/outputs.tf.j2 +9 -0
  125. package/tf_starter/templates/gcp/modules/monitoring/variables.tf.j2 +13 -0
  126. package/tf_starter/templates/gcp/modules/network/main.tf.j2 +103 -0
  127. package/tf_starter/templates/gcp/modules/network/outputs.tf.j2 +21 -0
  128. package/tf_starter/templates/gcp/modules/network/variables.tf.j2 +22 -0
  129. package/tf_starter/templates/gcp/modules/storage/main.tf.j2 +47 -0
  130. package/tf_starter/templates/gcp/modules/storage/outputs.tf.j2 +13 -0
  131. package/tf_starter/templates/gcp/modules/storage/variables.tf.j2 +16 -0
  132. package/tf_starter/templates/gcp/root/backend.tf.j2 +12 -0
  133. package/tf_starter/templates/gcp/root/main.tf.j2 +210 -0
  134. package/tf_starter/templates/gcp/root/outputs.tf.j2 +61 -0
  135. package/tf_starter/templates/gcp/root/providers.tf.j2 +18 -0
  136. package/tf_starter/templates/gcp/root/variables.tf.j2 +140 -0
  137. package/tf_starter/templates/gcp/root/versions.tf.j2 +23 -0
@@ -0,0 +1,445 @@
1
+ # {{ project_name }}
2
+
3
+ > Infrastructure-as-Code project generated by **tf-starter** for **{{ provider | upper }}**
4
+
5
+ ---
6
+
7
+ ## Architecture
8
+
9
+ {% if provider == "aws" %}
10
+ ```
11
+ Internet
12
+ |
13
+ {% if "apigateway" in services and "compute" in services %}
14
+ +------------+------------+
15
+ | |
16
+ +-------+--------+ +----------+-------+
17
+ | API Gateway | | ALB |
18
+ +-------+--------+ +----------+-------+
19
+ | |
20
+ +-------+--------+ +----------+-------+
21
+ | Lambda | | Auto Scaling EC2 |
22
+ +-------+--------+ +----------+-------+
23
+ {% elif "apigateway" in services %}
24
+ +---------------+
25
+ | API Gateway |
26
+ +---------------+
27
+ |
28
+ +---------------+
29
+ | Lambda |
30
+ +---------------+
31
+ {% elif "kubernetes" in services and "compute" in services %}
32
+ +---------------+
33
+ | ALB |
34
+ +---------------+
35
+ |
36
+ +------------+------------+
37
+ | |
38
+ +-------+--------+ +----------+-------+
39
+ | EKS Cluster | | Auto Scaling EC2 |
40
+ +-------+--------+ +----------+-------+
41
+ {% elif "kubernetes" in services %}
42
+ +---------------+
43
+ | ALB |
44
+ +---------------+
45
+ |
46
+ +---------------+
47
+ | EKS Cluster |
48
+ +---------------+
49
+ {% elif "compute" in services %}
50
+ +---------------+
51
+ | ALB |
52
+ +---------------+
53
+ |
54
+ +---------------+
55
+ | Auto Scaling |
56
+ | EC2 |
57
+ +---------------+
58
+ {% elif "lambda" in services %}
59
+ +---------------+
60
+ | Lambda |
61
+ +---------------+
62
+ {% else %}
63
+ +---------------+
64
+ | VPC |
65
+ +---------------+
66
+ {% endif %}
67
+ {% if "database" in services %}
68
+ |
69
+ +---------------+
70
+ | RDS PostgreSQL|
71
+ | (Multi-AZ) |
72
+ +---------------+
73
+ {% endif %}
74
+ {% if "messaging" in services %}
75
+ |
76
+ +---------------+
77
+ | SQS Queue |
78
+ +---------------+
79
+ {% endif %}
80
+ {% if "storage" in services %}
81
+ |
82
+ +---------------+
83
+ | S3 Bucket |
84
+ +---------------+
85
+ {% endif %}
86
+ ```
87
+ {% elif provider == "gcp" %}
88
+ ```
89
+ {% if "kubernetes" in services %}
90
+ Internet
91
+ |
92
+ +------------------+
93
+ | Cloud Load Bal. |
94
+ +------------------+
95
+ |
96
+ +------------------+
97
+ | GKE Cluster |
98
+ +------------------+
99
+ {% elif "compute" in services %}
100
+ Internet
101
+ |
102
+ +------------------+
103
+ | Cloud Load Bal. |
104
+ +------------------+
105
+ |
106
+ +------------------+
107
+ | Managed Inst. |
108
+ | Group |
109
+ +------------------+
110
+ {% else %}
111
+ Internet
112
+ |
113
+ +------------------+
114
+ | VPC Network |
115
+ +------------------+
116
+ {% endif %}
117
+ {% if "database" in services %}
118
+ |
119
+ +------------------+
120
+ | Cloud SQL |
121
+ | PostgreSQL |
122
+ +------------------+
123
+ {% endif %}
124
+ {% if "messaging" in services %}
125
+ |
126
+ +------------------+
127
+ | Pub/Sub |
128
+ +------------------+
129
+ {% endif %}
130
+ {% if "storage" in services %}
131
+ |
132
+ +------------------+
133
+ | GCS Bucket |
134
+ +------------------+
135
+ {% endif %}
136
+ ```
137
+ {% elif provider == "azure" %}
138
+ ```
139
+ {% if "kubernetes" in services %}
140
+ Internet
141
+ |
142
+ +------------------+
143
+ | App Gateway |
144
+ +------------------+
145
+ |
146
+ +------------------+
147
+ | AKS Cluster |
148
+ +------------------+
149
+ {% elif "compute" in services %}
150
+ Internet
151
+ |
152
+ +------------------+
153
+ | App Gateway |
154
+ +------------------+
155
+ |
156
+ +------------------+
157
+ | VMSS |
158
+ +------------------+
159
+ {% else %}
160
+ Internet
161
+ |
162
+ +------------------+
163
+ | VNet |
164
+ +------------------+
165
+ {% endif %}
166
+ {% if "database" in services %}
167
+ |
168
+ +------------------+
169
+ | Azure PostgreSQL |
170
+ | Flexible Server |
171
+ +------------------+
172
+ {% endif %}
173
+ {% if "messaging" in services %}
174
+ |
175
+ +------------------+
176
+ | Service Bus |
177
+ +------------------+
178
+ {% endif %}
179
+ {% if "storage" in services %}
180
+ |
181
+ +------------------+
182
+ | Storage Account |
183
+ +------------------+
184
+ {% endif %}
185
+ ```
186
+ {% endif %}
187
+
188
+ ---
189
+
190
+ ## Project Overview
191
+
192
+ This project provisions cloud infrastructure on **{{ provider | upper }}** using Terraform.
193
+ It was generated using the `tf-starter` CLI tool and follows enterprise-grade
194
+ infrastructure-as-code best practices.
195
+
196
+ ### Enabled Services
197
+
198
+ | Service | Status |
199
+ |---------|--------|
200
+ | Network | Enabled (always) |
201
+ {% for svc in services %}
202
+ {% if svc != "network" %}
203
+ | {{ svc | capitalize }} | Enabled |
204
+ {% endif %}
205
+ {% endfor %}
206
+
207
+ ---
208
+
209
+ ## Folder Structure
210
+
211
+ ```
212
+ {{ project_name }}/
213
+ ├── environments/ # Per-environment configurations
214
+ {% for env in environments %}
215
+ │ ├── {{ env }}/
216
+ │ │ ├── main.tf
217
+ │ │ ├── variables.tf
218
+ │ │ ├── terraform.tfvars
219
+ {% if enable_backend %}
220
+ │ │ └── backend.tf
221
+ {% endif %}
222
+ {% endfor %}
223
+ ├── modules/ # Reusable Terraform modules
224
+ {% for svc in services %}
225
+ │ ├── {{ svc }}/
226
+ {% endfor %}
227
+ ├── main.tf # Root module composition
228
+ ├── providers.tf # Provider configuration
229
+ ├── variables.tf # Input variables
230
+ ├── outputs.tf # Output values
231
+ ├── versions.tf # Terraform & provider versions
232
+ {% if enable_backend %}
233
+ ├── backend.tf # Remote state backend
234
+ {% endif %}
235
+ ├── Makefile # Automation targets
236
+ ├── init.sh # Bootstrap script
237
+ └── README.md # This file
238
+ ```
239
+
240
+ ---
241
+
242
+ ## Environments
243
+
244
+ | Environment | Description |
245
+ |-------------|-------------|
246
+ {% for env in environments %}
247
+ {% if env == "prod" %}
248
+ | **{{ env }}** | Production — HA enabled, deletion protection on, extended backups |
249
+ {% elif env == "staging" %}
250
+ | **{{ env }}** | Staging — mirrors production at reduced scale for pre-release testing |
251
+ {% elif env == "dev" %}
252
+ | **{{ env }}** | Development — minimal resources, fast iteration |
253
+ {% else %}
254
+ | **{{ env }}** | Custom environment |
255
+ {% endif %}
256
+ {% endfor %}
257
+
258
+ Each environment has its own `terraform.tfvars` file. Edit these to customize
259
+ resource sizing, networking CIDRs, and service-specific parameters.
260
+
261
+ ---
262
+
263
+ {% if enable_backend %}
264
+ ## Remote Backend
265
+
266
+ This project uses a remote backend for Terraform state:
267
+
268
+ {% if provider == "aws" %}
269
+ - **State storage:** S3 bucket (`{{ project_name }}-terraform-state`)
270
+ - **State locking:** DynamoDB table (`{{ project_name }}-terraform-lock`)
271
+ {% elif provider == "gcp" %}
272
+ - **State storage:** GCS bucket (`{{ project_name }}-terraform-state`)
273
+ {% elif provider == "azure" %}
274
+ - **State storage:** Azure Storage Account
275
+ {% endif %}
276
+
277
+ > **Important:** You must create the backend resources before running `terraform init`.
278
+ > Use the `init.sh` script to bootstrap them.
279
+
280
+ ---
281
+ {% endif %}
282
+
283
+ ## Deployment
284
+
285
+ ### Prerequisites
286
+
287
+ - [Terraform](https://www.terraform.io/downloads) >= 1.6.0
288
+ {% if provider == "aws" %}
289
+ - [AWS CLI](https://aws.amazon.com/cli/) configured with credentials
290
+ {% elif provider == "gcp" %}
291
+ - [Google Cloud SDK](https://cloud.google.com/sdk) with `gcloud auth application-default login`
292
+ {% elif provider == "azure" %}
293
+ - [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/) with `az login`
294
+ {% endif %}
295
+
296
+ ### Quick Start
297
+
298
+ ```bash
299
+ # 1. Navigate to your target environment
300
+ cd environments/dev
301
+
302
+ # 2. Initialize Terraform
303
+ terraform init
304
+
305
+ # 3. Review the execution plan
306
+ terraform plan
307
+
308
+ # 4. Apply the changes
309
+ terraform apply
310
+ ```
311
+
312
+ ### Using the Makefile
313
+
314
+ ```bash
315
+ # Initialize
316
+ make init
317
+
318
+ # Plan changes
319
+ make plan
320
+
321
+ # Apply changes
322
+ make apply
323
+
324
+ # Format code
325
+ make fmt
326
+
327
+ # Validate configuration
328
+ make validate
329
+
330
+ # Destroy infrastructure
331
+ make destroy
332
+ ```
333
+
334
+ ---
335
+
336
+ ## Destroy Instructions
337
+
338
+ ```bash
339
+ # Review what will be destroyed
340
+ terraform plan -destroy
341
+
342
+ # Destroy all resources
343
+ terraform destroy
344
+
345
+ # Or use Makefile
346
+ make destroy
347
+ ```
348
+
349
+ > **Warning:** Destroying production infrastructure is irreversible. Ensure you
350
+ > have backups and have communicated with your team before proceeding.
351
+
352
+ ---
353
+
354
+ ## Security Considerations
355
+
356
+ - All data-at-rest is encrypted
357
+ {% if "database" in services %}
358
+ - Database credentials are managed via Terraform (consider using Vault or Secrets Manager)
359
+ - Database is deployed in private subnets only
360
+ {% endif %}
361
+ {% if "storage" in services %}
362
+ - S3/GCS/Blob public access is blocked by default
363
+ {% endif %}
364
+ - Security groups follow the principle of least privilege
365
+ - All resources are tagged for cost allocation and ownership tracking
366
+ {% if enable_backend %}
367
+ - Terraform state is encrypted at rest
368
+ {% endif %}
369
+
370
+ ---
371
+
372
+ ## Scaling
373
+
374
+ {% if "compute" in services %}
375
+ ### Compute
376
+ Adjust `asg_min_size`, `asg_max_size`, and `asg_desired_capacity` in
377
+ your environment's `terraform.tfvars` to scale horizontally.
378
+ {% endif %}
379
+
380
+ {% if "kubernetes" in services %}
381
+ ### Kubernetes
382
+ Adjust `eks_node_min_size`, `eks_node_max_size`, and `eks_node_desired_size`
383
+ to control the cluster node pool. Consider enabling Cluster Autoscaler.
384
+ {% endif %}
385
+
386
+ {% if "lambda" in services %}
387
+ ### Lambda
388
+ - Adjust `lambda_memory_size` (128–10240 MB) — CPU scales proportionally with memory
389
+ - Adjust `lambda_timeout` (1–900 seconds) based on workload
390
+ - For high-throughput, consider reserved concurrency and provisioned concurrency
391
+ {% endif %}
392
+
393
+ {% if "apigateway" in services %}
394
+ ### API Gateway
395
+ - Adjust `apigw_throttle_burst_limit` and `apigw_throttle_rate_limit` for traffic control
396
+ - Use caching to reduce Lambda invocations for repeated requests
397
+ - Consider usage plans and API keys for external consumers
398
+ {% endif %}
399
+
400
+ {% if "database" in services %}
401
+ ### Database
402
+ - Vertical scaling: change `db_instance_class`
403
+ - Storage auto-scaling is enabled (up to 2x allocated storage)
404
+ - Production uses Multi-AZ for high availability
405
+ {% endif %}
406
+
407
+ ---
408
+
409
+ ## Adding New Modules
410
+
411
+ 1. Create a new directory under `modules/`:
412
+ ```bash
413
+ mkdir -p modules/my-module
414
+ ```
415
+
416
+ 2. Add `main.tf`, `variables.tf`, and `outputs.tf` inside it.
417
+
418
+ 3. Reference it in the root `main.tf`:
419
+ ```hcl
420
+ module "my_module" {
421
+ source = "./modules/my-module"
422
+ # pass variables
423
+ }
424
+ ```
425
+
426
+ 4. Add corresponding variables to `variables.tf` and outputs to `outputs.tf`.
427
+
428
+ ---
429
+
430
+ ## Customizing Variables
431
+
432
+ 1. Open the relevant environment's `terraform.tfvars` file.
433
+ 2. Override any variable defined in `variables.tf`.
434
+ 3. Run `terraform plan` to preview changes.
435
+ 4. Run `terraform apply` to apply.
436
+
437
+ For sensitive values, use environment variables:
438
+ ```bash
439
+ export TF_VAR_db_username="admin"
440
+ terraform plan
441
+ ```
442
+
443
+ ---
444
+
445
+ *Generated by [tf-starter](https://github.com/tf-starter) v1.0.0*
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env bash
2
+ # ---------------------------------------------------------------------------------------------------------------------
3
+ # Bootstrap script for {{ project_name }}
4
+ # Creates remote backend resources (if enabled) and initializes Terraform.
5
+ # Generated by tf-starter
6
+ # ---------------------------------------------------------------------------------------------------------------------
7
+
8
+ set -euo pipefail
9
+
10
+ PROJECT_NAME="{{ project_name }}"
11
+ REGION="{{ region }}"
12
+
13
+ echo "============================================="
14
+ echo " {{ project_name }} — Infrastructure Bootstrap"
15
+ echo "============================================="
16
+ echo ""
17
+
18
+ {% if enable_backend %}
19
+ {% if provider == "aws" %}
20
+ # ----- Create S3 bucket for Terraform state -----
21
+
22
+ BUCKET_NAME="${PROJECT_NAME}-terraform-state"
23
+ TABLE_NAME="${PROJECT_NAME}-terraform-lock"
24
+
25
+ echo "Creating S3 bucket for Terraform state: ${BUCKET_NAME}"
26
+ if aws s3api head-bucket --bucket "${BUCKET_NAME}" 2>/dev/null; then
27
+ echo " Bucket already exists. Skipping."
28
+ else
29
+ aws s3api create-bucket \
30
+ --bucket "${BUCKET_NAME}" \
31
+ --region "${REGION}" \
32
+ $([ "${REGION}" != "us-east-1" ] && echo "--create-bucket-configuration LocationConstraint=${REGION}")
33
+
34
+ aws s3api put-bucket-versioning \
35
+ --bucket "${BUCKET_NAME}" \
36
+ --versioning-configuration Status=Enabled
37
+
38
+ aws s3api put-bucket-encryption \
39
+ --bucket "${BUCKET_NAME}" \
40
+ --server-side-encryption-configuration '{"Rules":[{"ApplyServerSideEncryptionByDefault":{"SSEAlgorithm":"AES256"}}]}'
41
+
42
+ aws s3api put-public-access-block \
43
+ --bucket "${BUCKET_NAME}" \
44
+ --public-access-block-configuration "BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true"
45
+
46
+ echo " Bucket created."
47
+ fi
48
+
49
+ # ----- Create DynamoDB table for state locking -----
50
+
51
+ echo "Creating DynamoDB table for state locking: ${TABLE_NAME}"
52
+ if aws dynamodb describe-table --table-name "${TABLE_NAME}" --region "${REGION}" >/dev/null 2>&1; then
53
+ echo " Table already exists. Skipping."
54
+ else
55
+ aws dynamodb create-table \
56
+ --table-name "${TABLE_NAME}" \
57
+ --attribute-definitions AttributeName=LockID,AttributeType=S \
58
+ --key-schema AttributeName=LockID,KeyType=HASH \
59
+ --billing-mode PAY_PER_REQUEST \
60
+ --region "${REGION}"
61
+
62
+ echo " Table created."
63
+ fi
64
+ {% elif provider == "gcp" %}
65
+ BUCKET_NAME="${PROJECT_NAME}-terraform-state"
66
+
67
+ echo "Creating GCS bucket for Terraform state: ${BUCKET_NAME}"
68
+ if gsutil ls -b "gs://${BUCKET_NAME}" 2>/dev/null; then
69
+ echo " Bucket already exists. Skipping."
70
+ else
71
+ gsutil mb -l "${REGION}" "gs://${BUCKET_NAME}"
72
+ gsutil versioning set on "gs://${BUCKET_NAME}"
73
+ echo " Bucket created."
74
+ fi
75
+ {% elif provider == "azure" %}
76
+ RESOURCE_GROUP="${PROJECT_NAME}-tfstate-rg"
77
+ STORAGE_ACCOUNT=$(echo "${PROJECT_NAME}tfstate" | tr -d '-' | head -c 24)
78
+ CONTAINER_NAME="tfstate"
79
+
80
+ echo "Creating Azure Storage for Terraform state..."
81
+ az group create --name "${RESOURCE_GROUP}" --location "${REGION}" || true
82
+
83
+ az storage account create \
84
+ --resource-group "${RESOURCE_GROUP}" \
85
+ --name "${STORAGE_ACCOUNT}" \
86
+ --sku Standard_LRS \
87
+ --encryption-services blob 2>/dev/null || echo " Storage account already exists."
88
+
89
+ az storage container create \
90
+ --name "${CONTAINER_NAME}" \
91
+ --account-name "${STORAGE_ACCOUNT}" 2>/dev/null || echo " Container already exists."
92
+ {% endif %}
93
+
94
+ echo ""
95
+ {% endif %}
96
+
97
+ # ----- Initialize Terraform -----
98
+
99
+ echo "Initializing Terraform..."
100
+ for env_dir in environments/*/; do
101
+ env_name=$(basename "${env_dir}")
102
+ echo " Initializing environment: ${env_name}"
103
+ (cd "${env_dir}" && terraform init)
104
+ done
105
+
106
+ echo ""
107
+ echo "============================================="
108
+ echo " Bootstrap complete!"
109
+ echo " Run 'make plan ENV=dev' to preview changes."
110
+ echo "============================================="
@@ -0,0 +1,34 @@
1
+ # Pre-commit configuration for {{ project_name }}
2
+ # Install: pip install pre-commit && pre-commit install
3
+ # Generated by tf-starter
4
+
5
+ repos:
6
+ - repo: https://github.com/antonbabenko/pre-commit-terraform
7
+ rev: v1.88.0
8
+ hooks:
9
+ - id: terraform_fmt
10
+ name: Terraform fmt
11
+ description: Rewrites Terraform config to canonical format
12
+
13
+ - id: terraform_validate
14
+ name: Terraform validate
15
+ description: Validates Terraform configuration
16
+ args:
17
+ - --hook-config=--retry-once-with-cleanup=true
18
+
19
+ - id: terraform_tflint
20
+ name: Terraform tflint
21
+ description: Lints Terraform configuration
22
+
23
+ - id: terraform_docs
24
+ name: Terraform docs
25
+ description: Generates documentation from Terraform modules
26
+
27
+ - repo: https://github.com/pre-commit/pre-commit-hooks
28
+ rev: v4.5.0
29
+ hooks:
30
+ - id: trailing-whitespace
31
+ - id: end-of-file-fixer
32
+ - id: check-yaml
33
+ - id: check-merge-conflict
34
+ - id: detect-private-key