-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
75 lines (63 loc) · 1.9 KB
/
main.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
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
postgresql = {
source = "cyrilgdn/postgresql"
version = "1.21.0"
}
}
}
locals {
port = var.port != "" ? var.port : "5432"
subnet_ids = var.subnet_ids != "" ? split(",", var.subnet_ids) : []
}
module "aws_terraform" {
source = "github.com/zeet-dev/terraform-aws-rds"
engine = "postgres"
family = "postgres15"
major_engine_version = "15"
create_db_instance = true
publicly_accessible = true
identifier = var.identifier
allocated_storage = var.allocated_storage
storage_type = var.storage_type
storage_encrypted = var.storage_encrypted
engine_version = var.engine_version
instance_class = var.instance_class
db_name = var.db_name
username = var.username
password = var.password
availability_zone = var.availability_zone
subnet_ids = local.subnet_ids
port = local.port
}
data "aws_region" "current" {}
provider "postgresql" {
host = module.aws_terraform.db_instance_address
port = module.aws_terraform.db_instance_port
database = module.aws_terraform.db_instance_name
username = module.aws_terraform.db_instance_username
password = module.aws_terraform.db_instance_password
sslmode = "require"
superuser = false
}
resource "postgresql_extension" "pgvector" {
name = "vector"
}
resource "null_resource" "update_visibility" {
count = var.publicly_accessible ? 0 : 1
depends_on = [
postgresql_extension.pgvector
]
triggers = {
instance_id = module.aws_terraform.db_instance_id
}
provisioner "local-exec" {
command = <<-EOT
aws rds modify-db-instance --db-instance-identifier ${module.aws_terraform.db_instance_id} --region ${data.aws_region.current.name} --no-publicly-accessible --apply-immediately
EOT
}
}