-
Notifications
You must be signed in to change notification settings - Fork 0
/
resources-google.tf
96 lines (79 loc) · 3.15 KB
/
resources-google.tf
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
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/google_project
resource "google_project" "project" {
name = var.project_id
project_id = var.project_id
org_id = var.org_id
billing_account = var.billing_account
skip_delete = true # resource can be deleted without deleting the Project
}
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/google_project_service
resource "google_project_service" "services" {
for_each = var.project_services
project = google_project.project.name
service = each.key
timeouts {
create = "30m"
update = "40m"
}
# an error will be generated if any enabled services depend on this service when destroying it.
disable_dependent_services = false
}
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster
resource "google_container_cluster" "primary" {
name = var.cluster_name
project = google_project.project.name
location = var.region
enable_autopilot = true
vertical_pod_autoscaling {
enabled = true
}
}
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance
resource "google_sql_database_instance" "master" {
name = var.database_instance_name
database_version = var.database_instance_version
project = google_project.project.name
region = var.region
settings {
tier = var.database_instance_tier
ip_configuration {
ipv4_enabled = true
authorized_networks {
name = "allow_network"
value = var.database_instance_allowed_network
}
}
}
}
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database
resource "google_sql_database" "database" {
name = var.database_name
project = google_project.project.name
instance = google_sql_database_instance.master.name
collation = var.database_collation
}
resource "google_sql_user" "user" {
name = var.database_credentials.user
instance = google_sql_database_instance.master.name
password = var.database_credentials.password
depends_on = [
google_sql_database.database
]
# Use a provisioner to seed the database with a schema from a file. This requires
# that the host running terraform has `psql` installed.
# Note: if the schema is deleted but the user exists Terraform will not re-apply the schema.
# Potential solution, replace the resource:
# terraform apply -replace="google_sql_user.user"
# https://www.terraform.io/cli/commands/plan#replace-address
provisioner "local-exec" {
command = "PGPASSWORD=${google_sql_user.user.password} psql -U ${google_sql_user.user.name} -h ${google_sql_database_instance.master.public_ip_address} -f ${var.database_seed_file} ${var.database_name}"
}
}
# https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/redis_instance#example-usage---redis-instance-basic
resource "google_redis_instance" "cache" {
name = var.redis_instance_name
project = google_project.project.name
region = var.region
memory_size_gb = var.redis_instance_size
tier = var.redis_instance_tier
}