-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeployment-automation.hcl
More file actions
189 lines (162 loc) · 3.93 KB
/
Copy pathdeployment-automation.hcl
File metadata and controls
189 lines (162 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# IHEP Production Infrastructure
terraform {
required_version = ">= 1.5.0"
backend "gcs" {
bucket = "ihep-terraform-state"
prefix = "production"
}
required_providers {
google = {
source = "hashicorp/google"
version = "~> 5.0"
}
}
}
provider "google" {
project = var.project_id
region = var.region
}
# Cloud SQL PostgreSQL (PHI metadata)
resource "google_sql_database_instance" "ihep_primary" {
name = "ihep-primary-${var.environment}"
database_version = "POSTGRES_15"
region = var.region
settings {
tier = "db-custom-4-16384" # 4 vCPU, 16GB RAM
disk_size = 100
disk_type = "PD_SSD"
backup_configuration {
enabled = true
point_in_time_recovery_enabled = true
transaction_log_retention_days = 7
}
ip_configuration {
ipv4_enabled = false # Private IP only
private_network = google_compute_network.ihep_vpc.id
require_ssl = true
}
database_flags {
name = "max_connections"
value = "200"
}
}
deletion_protection = true # Prevent accidental deletion
}
# Cloud Memorystore Redis (caching)
resource "google_redis_instance" "ihep_cache" {
name = "ihep-cache-${var.environment}"
tier = "STANDARD_HA" # High availability
memory_size_gb = 5
region = var.region
redis_version = "REDIS_7_0"
authorized_network = google_compute_network.ihep_vpc.id
maintenance_policy {
weekly_maintenance_window {
day = "SUNDAY"
start_time {
hours = 3
minutes = 0
}
}
}
}
# Cloud Run Services (Microservices)
resource "google_cloud_run_service" "iam_service" {
name = "iam-service"
location = var.region
template {
spec {
service_account_name = google_service_account.iam_sa.email
containers {
image = "gcr.io/${var.project_id}/iam-service:${var.image_tag}"
resources {
limits = {
cpu = "1000m"
memory = "512Mi"
}
}
env {
name = "FIRESTORE_PROJECT"
value = var.project_id
}
env {
name = "JWT_SECRET"
value_from {
secret_key_ref {
name = google_secret_manager_secret.jwt_secret.secret_id
key = "latest"
}
}
}
}
}
metadata {
annotations = {
"autoscaling.knative.dev/minScale" = "2"
"autoscaling.knative.dev/maxScale" = "100"
}
}
}
traffic {
percent = 100
latest_revision = true
}
}
# Cloud Armor Security Policy
resource "google_compute_security_policy" "ihep_waf" {
name = "ihep-waf-policy"
# Block common attack patterns
rule {
action = "deny(403)"
priority = "1000"
match {
expr {
expression = "evaluatePreconfiguredExpr('sqli-stable')"
}
}
description = "Block SQL injection attempts"
}
rule {
action = "deny(403)"
priority = "1100"
match {
expr {
expression = "evaluatePreconfiguredExpr('xss-stable')"
}
}
description = "Block XSS attempts"
}
# Rate limiting
rule {
action = "rate_based_ban"
priority = "2000"
match {
versioned_expr = "SRC_IPS_V1"
config {
src_ip_ranges = ["*"]
}
}
rate_limit_options {
conform_action = "allow"
exceed_action = "deny(429)"
rate_limit_threshold {
count = 100
interval_sec = 60
}
ban_duration_sec = 600
}
description = "Rate limit: 100 req/min per IP"
}
# Default rule: allow
rule {
action = "allow"
priority = "2147483647"
match {
versioned_expr = "SRC_IPS_V1"
config {
src_ip_ranges = ["*"]
}
}
description = "Default allow"
}
}