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,122 @@
1
+ # ---------------------------------------------------------------------------------------------------------------------
2
+ # LAMBDA MODULE — Google Cloud Functions (2nd Gen)
3
+ # Project: {{ project_name }}
4
+ # Generated by tf-starter
5
+ # ---------------------------------------------------------------------------------------------------------------------
6
+
7
+ locals {
8
+ name_prefix = "${var.project_name}-${var.environment}"
9
+ function_name = "${local.name_prefix}-${var.function_name}"
10
+ }
11
+
12
+ # ---------------------------------------------------------------------------------------------------------------------
13
+ # SERVICE ACCOUNT
14
+ # ---------------------------------------------------------------------------------------------------------------------
15
+
16
+ resource "google_service_account" "function" {
17
+ project = var.project_id
18
+ account_id = "${local.name_prefix}-fn-sa"
19
+ display_name = "Cloud Function SA for ${local.name_prefix}"
20
+ }
21
+
22
+ resource "google_project_iam_member" "function_invoker" {
23
+ project = var.project_id
24
+ role = "roles/run.invoker"
25
+ member = "serviceAccount:${google_service_account.function.email}"
26
+ }
27
+
28
+ # ---------------------------------------------------------------------------------------------------------------------
29
+ # SOURCE BUCKET (stores function code)
30
+ # ---------------------------------------------------------------------------------------------------------------------
31
+
32
+ resource "google_storage_bucket" "function_source" {
33
+ name = "${local.function_name}-source"
34
+ project = var.project_id
35
+ location = var.region
36
+
37
+ uniform_bucket_level_access = true
38
+
39
+ versioning {
40
+ enabled = true
41
+ }
42
+
43
+ labels = var.labels
44
+ }
45
+
46
+ resource "google_storage_bucket_object" "function_zip" {
47
+ name = "function-source.zip"
48
+ bucket = google_storage_bucket.function_source.name
49
+ source = data.archive_file.function_placeholder.output_path
50
+ }
51
+
52
+ data "archive_file" "function_placeholder" {
53
+ type = "zip"
54
+ output_path = "${path.module}/placeholder.zip"
55
+
56
+ source {
57
+ content = <<-EOF
58
+ def hello_http(request):
59
+ """Placeholder Cloud Function — replace with your code."""
60
+ return "Hello from ${local.function_name}"
61
+ EOF
62
+ filename = "main.py"
63
+ }
64
+ }
65
+
66
+ # ---------------------------------------------------------------------------------------------------------------------
67
+ # CLOUD FUNCTION (2nd Gen)
68
+ # ---------------------------------------------------------------------------------------------------------------------
69
+
70
+ resource "google_cloudfunctions2_function" "main" {
71
+ name = local.function_name
72
+ project = var.project_id
73
+ location = var.region
74
+
75
+ build_config {
76
+ runtime = var.runtime
77
+ entry_point = var.entry_point
78
+
79
+ source {
80
+ storage_source {
81
+ bucket = google_storage_bucket.function_source.name
82
+ object = google_storage_bucket_object.function_zip.name
83
+ }
84
+ }
85
+ }
86
+
87
+ service_config {
88
+ max_instance_count = var.max_instances
89
+ min_instance_count = var.min_instances
90
+ available_memory = var.memory
91
+ timeout_seconds = var.timeout
92
+ service_account_email = google_service_account.function.email
93
+
94
+ environment_variables = merge(
95
+ {
96
+ ENVIRONMENT = var.environment
97
+ PROJECT_NAME = var.project_name
98
+ },
99
+ var.environment_variables,
100
+ )
101
+ }
102
+
103
+ labels = merge(var.labels, {
104
+ function = var.function_name
105
+ })
106
+
107
+ ### MUST EDIT THIS ###
108
+ # Replace the placeholder source above with your real function code.
109
+ }
110
+
111
+ # Allow unauthenticated invocations (for API Gateway integration)
112
+ resource "google_cloud_run_service_iam_member" "invoker" {
113
+ project = var.project_id
114
+ location = var.region
115
+ service = google_cloudfunctions2_function.main.service_config[0].service
116
+ role = "roles/run.invoker"
117
+ member = "allUsers"
118
+
119
+ ### MUST EDIT THIS ###
120
+ # For production, restrict to specific service accounts:
121
+ # member = "serviceAccount:${google_service_account.function.email}"
122
+ }
@@ -0,0 +1,18 @@
1
+ # ---------------------------------------------------------------------------------------------------------------------
2
+ # LAMBDA MODULE (Cloud Functions) — Outputs
3
+ # ---------------------------------------------------------------------------------------------------------------------
4
+
5
+ output "function_name" {
6
+ description = "Name of the Cloud Function"
7
+ value = google_cloudfunctions2_function.main.name
8
+ }
9
+
10
+ output "function_uri" {
11
+ description = "HTTPS URI of the Cloud Function"
12
+ value = google_cloudfunctions2_function.main.service_config[0].uri
13
+ }
14
+
15
+ output "service_account_email" {
16
+ description = "Service account email used by the function"
17
+ value = google_service_account.function.email
18
+ }
@@ -0,0 +1,77 @@
1
+ # ---------------------------------------------------------------------------------------------------------------------
2
+ # LAMBDA MODULE (Cloud Functions) — Variables
3
+ # ---------------------------------------------------------------------------------------------------------------------
4
+
5
+ variable "project_name" {
6
+ description = "Name of the project"
7
+ type = string
8
+ }
9
+
10
+ variable "environment" {
11
+ description = "Deployment environment"
12
+ type = string
13
+ }
14
+
15
+ variable "project_id" {
16
+ description = "GCP project ID"
17
+ type = string
18
+ }
19
+
20
+ variable "region" {
21
+ description = "GCP region"
22
+ type = string
23
+ }
24
+
25
+ variable "function_name" {
26
+ description = "Short name for the function"
27
+ type = string
28
+ default = "app"
29
+ }
30
+
31
+ variable "runtime" {
32
+ description = "Cloud Function runtime"
33
+ type = string
34
+ default = "python312"
35
+ }
36
+
37
+ variable "entry_point" {
38
+ description = "Function entry point"
39
+ type = string
40
+ default = "hello_http"
41
+ }
42
+
43
+ variable "timeout" {
44
+ description = "Function timeout in seconds"
45
+ type = number
46
+ default = 60
47
+ }
48
+
49
+ variable "memory" {
50
+ description = "Available memory (e.g., 256M, 512M, 1Gi)"
51
+ type = string
52
+ default = "256M"
53
+ }
54
+
55
+ variable "max_instances" {
56
+ description = "Maximum concurrent instances"
57
+ type = number
58
+ default = 100
59
+ }
60
+
61
+ variable "min_instances" {
62
+ description = "Minimum instances (0 for scale-to-zero)"
63
+ type = number
64
+ default = 0
65
+ }
66
+
67
+ variable "environment_variables" {
68
+ description = "Additional environment variables"
69
+ type = map(string)
70
+ default = {}
71
+ }
72
+
73
+ variable "labels" {
74
+ description = "Resource labels"
75
+ type = map(string)
76
+ default = {}
77
+ }
@@ -0,0 +1,44 @@
1
+ # ---------------------------------------------------------------------------------------------------------------------
2
+ # MESSAGING MODULE — Pub/Sub
3
+ # Generated by tf-starter
4
+ # ---------------------------------------------------------------------------------------------------------------------
5
+
6
+ locals {
7
+ name_prefix = "${var.project_name}-${var.environment}"
8
+ }
9
+
10
+ resource "google_pubsub_topic" "main" {
11
+ name = "${local.name_prefix}-topic"
12
+ project = var.project_id
13
+
14
+ message_retention_duration = var.message_retention_duration
15
+
16
+ labels = var.labels
17
+ }
18
+
19
+ resource "google_pubsub_subscription" "main" {
20
+ name = "${local.name_prefix}-subscription"
21
+ project = var.project_id
22
+ topic = google_pubsub_topic.main.id
23
+
24
+ ack_deadline_seconds = var.ack_deadline_seconds
25
+ message_retention_duration = var.message_retention_duration
26
+
27
+ retry_policy {
28
+ minimum_backoff = "10s"
29
+ maximum_backoff = "600s"
30
+ }
31
+
32
+ dead_letter_policy {
33
+ dead_letter_topic = google_pubsub_topic.dead_letter.id
34
+ max_delivery_attempts = 5
35
+ }
36
+
37
+ labels = var.labels
38
+ }
39
+
40
+ resource "google_pubsub_topic" "dead_letter" {
41
+ name = "${local.name_prefix}-dlq"
42
+ project = var.project_id
43
+ labels = var.labels
44
+ }
@@ -0,0 +1,13 @@
1
+ # MESSAGING MODULE — Outputs (GCP)
2
+
3
+ output "topic_id" {
4
+ value = google_pubsub_topic.main.id
5
+ }
6
+
7
+ output "topic_name" {
8
+ value = google_pubsub_topic.main.name
9
+ }
10
+
11
+ output "subscription_id" {
12
+ value = google_pubsub_subscription.main.id
13
+ }
@@ -0,0 +1,20 @@
1
+ # MESSAGING MODULE — Variables (GCP)
2
+
3
+ variable "project_name" { type = string }
4
+ variable "environment" { type = string }
5
+ variable "project_id" { type = string }
6
+
7
+ variable "message_retention_duration" {
8
+ type = string
9
+ default = "604800s"
10
+ }
11
+
12
+ variable "ack_deadline_seconds" {
13
+ type = number
14
+ default = 20
15
+ }
16
+
17
+ variable "labels" {
18
+ type = map(string)
19
+ default = {}
20
+ }
@@ -0,0 +1,44 @@
1
+ # ---------------------------------------------------------------------------------------------------------------------
2
+ # MONITORING MODULE — Cloud Monitoring
3
+ # Generated by tf-starter
4
+ # ---------------------------------------------------------------------------------------------------------------------
5
+
6
+ locals {
7
+ name_prefix = "${var.project_name}-${var.environment}"
8
+ }
9
+
10
+ resource "google_monitoring_notification_channel" "email" {
11
+ count = var.notification_email != "" ? 1 : 0
12
+ display_name = "${local.name_prefix}-email"
13
+ project = var.project_id
14
+ type = "email"
15
+
16
+ labels = {
17
+ email_address = var.notification_email
18
+ }
19
+ }
20
+
21
+ resource "google_monitoring_alert_policy" "cpu_high" {
22
+ display_name = "${local.name_prefix}-cpu-high"
23
+ project = var.project_id
24
+ combiner = "OR"
25
+
26
+ conditions {
27
+ display_name = "CPU utilization > 80%"
28
+ condition_threshold {
29
+ filter = "metric.type=\"compute.googleapis.com/instance/cpu/utilization\" AND resource.type=\"gce_instance\""
30
+ comparison = "COMPARISON_GT"
31
+ threshold_value = 0.8
32
+ duration = "300s"
33
+
34
+ aggregations {
35
+ alignment_period = "60s"
36
+ per_series_aligner = "ALIGN_MEAN"
37
+ }
38
+ }
39
+ }
40
+
41
+ notification_channels = var.notification_email != "" ? [google_monitoring_notification_channel.email[0].id] : []
42
+
43
+ user_labels = var.labels
44
+ }
@@ -0,0 +1,9 @@
1
+ # MONITORING MODULE — Outputs (GCP)
2
+
3
+ output "notification_channel_id" {
4
+ value = length(google_monitoring_notification_channel.email) > 0 ? google_monitoring_notification_channel.email[0].id : ""
5
+ }
6
+
7
+ output "alert_policy_id" {
8
+ value = google_monitoring_alert_policy.cpu_high.id
9
+ }
@@ -0,0 +1,13 @@
1
+ # MONITORING MODULE — Variables (GCP)
2
+
3
+ variable "project_name" { type = string }
4
+ variable "environment" { type = string }
5
+ variable "project_id" { type = string }
6
+ variable "notification_email" {
7
+ type = string
8
+ default = ""
9
+ }
10
+ variable "labels" {
11
+ type = map(string)
12
+ default = {}
13
+ }
@@ -0,0 +1,103 @@
1
+ # ---------------------------------------------------------------------------------------------------------------------
2
+ # NETWORK MODULE — VPC, Subnets, Cloud NAT, Cloud Router
3
+ # Generated by tf-starter
4
+ # ---------------------------------------------------------------------------------------------------------------------
5
+
6
+ locals {
7
+ name_prefix = "${var.project_name}-${var.environment}"
8
+ }
9
+
10
+ resource "google_compute_network" "main" {
11
+ name = "${local.name_prefix}-vpc"
12
+ project = var.project_id
13
+ auto_create_subnetworks = false
14
+ }
15
+
16
+ resource "google_compute_subnetwork" "public" {
17
+ name = "${local.name_prefix}-public"
18
+ project = var.project_id
19
+ region = var.region
20
+ network = google_compute_network.main.id
21
+ ip_cidr_range = "10.0.1.0/24"
22
+ }
23
+
24
+ resource "google_compute_subnetwork" "private" {
25
+ name = "${local.name_prefix}-private"
26
+ project = var.project_id
27
+ region = var.region
28
+ network = google_compute_network.main.id
29
+ ip_cidr_range = "10.0.10.0/24"
30
+ private_ip_google_access = true
31
+ }
32
+
33
+ resource "google_compute_router" "main" {
34
+ name = "${local.name_prefix}-router"
35
+ project = var.project_id
36
+ region = var.region
37
+ network = google_compute_network.main.id
38
+ }
39
+
40
+ resource "google_compute_router_nat" "main" {
41
+ name = "${local.name_prefix}-nat"
42
+ project = var.project_id
43
+ region = var.region
44
+ router = google_compute_router.main.name
45
+ nat_ip_allocate_option = "AUTO_ONLY"
46
+ source_subnetwork_ip_ranges_to_nat = "ALL_SUBNETWORKS_ALL_IP_RANGES"
47
+
48
+ log_config {
49
+ enable = true
50
+ filter = "ERRORS_ONLY"
51
+ }
52
+ }
53
+
54
+ resource "google_compute_global_address" "private_ip" {
55
+ name = "${local.name_prefix}-private-ip"
56
+ project = var.project_id
57
+ purpose = "VPC_PEERING"
58
+ address_type = "INTERNAL"
59
+ prefix_length = 16
60
+ network = google_compute_network.main.id
61
+ }
62
+
63
+ resource "google_service_networking_connection" "private" {
64
+ network = google_compute_network.main.id
65
+ service = "servicenetworking.googleapis.com"
66
+ reserved_peering_ranges = [google_compute_global_address.private_ip.name]
67
+ }
68
+
69
+ resource "google_compute_firewall" "allow_internal" {
70
+ name = "${local.name_prefix}-allow-internal"
71
+ project = var.project_id
72
+ network = google_compute_network.main.name
73
+
74
+ allow {
75
+ protocol = "tcp"
76
+ ports = ["0-65535"]
77
+ }
78
+
79
+ allow {
80
+ protocol = "udp"
81
+ ports = ["0-65535"]
82
+ }
83
+
84
+ allow {
85
+ protocol = "icmp"
86
+ }
87
+
88
+ source_ranges = ["10.0.0.0/8"]
89
+ }
90
+
91
+ resource "google_compute_firewall" "allow_http" {
92
+ name = "${local.name_prefix}-allow-http"
93
+ project = var.project_id
94
+ network = google_compute_network.main.name
95
+
96
+ allow {
97
+ protocol = "tcp"
98
+ ports = ["80", "443"]
99
+ }
100
+
101
+ source_ranges = ["0.0.0.0/0"]
102
+ target_tags = ["http-server"]
103
+ }
@@ -0,0 +1,21 @@
1
+ # NETWORK MODULE — Outputs (GCP)
2
+
3
+ output "network_self_link" {
4
+ value = google_compute_network.main.self_link
5
+ }
6
+
7
+ output "network_name" {
8
+ value = google_compute_network.main.name
9
+ }
10
+
11
+ output "public_subnet_self_link" {
12
+ value = google_compute_subnetwork.public.self_link
13
+ }
14
+
15
+ output "private_subnet_self_link" {
16
+ value = google_compute_subnetwork.private.self_link
17
+ }
18
+
19
+ output "private_ip_range_name" {
20
+ value = google_compute_global_address.private_ip.name
21
+ }
@@ -0,0 +1,22 @@
1
+ # NETWORK MODULE — Variables (GCP)
2
+
3
+ variable "project_name" {
4
+ type = string
5
+ }
6
+
7
+ variable "environment" {
8
+ type = string
9
+ }
10
+
11
+ variable "region" {
12
+ type = string
13
+ }
14
+
15
+ variable "project_id" {
16
+ type = string
17
+ }
18
+
19
+ variable "labels" {
20
+ type = map(string)
21
+ default = {}
22
+ }
@@ -0,0 +1,47 @@
1
+ # ---------------------------------------------------------------------------------------------------------------------
2
+ # STORAGE MODULE — GCS
3
+ # Generated by tf-starter
4
+ # ---------------------------------------------------------------------------------------------------------------------
5
+
6
+ locals {
7
+ name_prefix = "${var.project_name}-${var.environment}"
8
+ }
9
+
10
+ resource "random_id" "bucket_suffix" {
11
+ byte_length = 4
12
+ }
13
+
14
+ resource "google_storage_bucket" "main" {
15
+ name = "${local.name_prefix}-storage-${random_id.bucket_suffix.hex}"
16
+ project = var.project_id
17
+ location = var.region
18
+
19
+ storage_class = "STANDARD"
20
+ uniform_bucket_level_access = true
21
+
22
+ versioning {
23
+ enabled = var.enable_versioning
24
+ }
25
+
26
+ lifecycle_rule {
27
+ action {
28
+ type = "SetStorageClass"
29
+ storage_class = "NEARLINE"
30
+ }
31
+ condition {
32
+ age = 90
33
+ }
34
+ }
35
+
36
+ lifecycle_rule {
37
+ action {
38
+ type = "SetStorageClass"
39
+ storage_class = "COLDLINE"
40
+ }
41
+ condition {
42
+ age = 180
43
+ }
44
+ }
45
+
46
+ labels = var.labels
47
+ }
@@ -0,0 +1,13 @@
1
+ # STORAGE MODULE — Outputs (GCP)
2
+
3
+ output "bucket_name" {
4
+ value = google_storage_bucket.main.name
5
+ }
6
+
7
+ output "bucket_url" {
8
+ value = google_storage_bucket.main.url
9
+ }
10
+
11
+ output "bucket_self_link" {
12
+ value = google_storage_bucket.main.self_link
13
+ }
@@ -0,0 +1,16 @@
1
+ # STORAGE MODULE — Variables (GCP)
2
+
3
+ variable "project_name" { type = string }
4
+ variable "environment" { type = string }
5
+ variable "project_id" { type = string }
6
+ variable "region" { type = string }
7
+
8
+ variable "enable_versioning" {
9
+ type = bool
10
+ default = true
11
+ }
12
+
13
+ variable "labels" {
14
+ type = map(string)
15
+ default = {}
16
+ }
@@ -0,0 +1,12 @@
1
+ # ---------------------------------------------------------------------------------------------------------------------
2
+ # REMOTE BACKEND — GCS
3
+ # Generated by tf-starter
4
+ # ---------------------------------------------------------------------------------------------------------------------
5
+
6
+ terraform {
7
+ backend "gcs" {
8
+ ### MUST EDIT THIS ###
9
+ bucket = "{{ project_name }}-terraform-state"
10
+ prefix = "{{ project_name }}/terraform.tfstate"
11
+ }
12
+ }