Skip to content

Commit d6c9b0b

Browse files
committed
Fix RDS password definition
1 parent 6e1324e commit d6c9b0b

File tree

6 files changed

+41
-27
lines changed

6 files changed

+41
-27
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ The module has been tested with:
4343
| [aws_iam_role_policy.materialize_s3](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy) | resource |
4444
| [aws_iam_user.materialize](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_user) | resource |
4545
| [aws_iam_user_policy.materialize_s3](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_user_policy) | resource |
46-
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
4746

4847
## Inputs
4948

@@ -94,7 +93,7 @@ The module has been tested with:
9493
| <a name="output_materialize_s3_role_arn"></a> [materialize\_s3\_role\_arn](#output\_materialize\_s3\_role\_arn) | The ARN of the IAM role for Materialize |
9594
| <a name="output_metadata_backend_url"></a> [metadata\_backend\_url](#output\_metadata\_backend\_url) | PostgreSQL connection URL in the format required by Materialize |
9695
| <a name="output_oidc_provider_arn"></a> [oidc\_provider\_arn](#output\_oidc\_provider\_arn) | The ARN of the OIDC Provider |
97-
| <a name="output_persist_backend_url"></a> [persist\_backend\_url](#output\_persist\_backend\_url) | S3 connection URL in the format required by Materialize |
96+
| <a name="output_persist_backend_url"></a> [persist\_backend\_url](#output\_persist\_backend\_url) | S3 connection URL in the format required by Materialize using IRSA |
9897
| <a name="output_s3_bucket_name"></a> [s3\_bucket\_name](#output\_s3\_bucket\_name) | Name of the S3 bucket |
9998
| <a name="output_vpc_id"></a> [vpc\_id](#output\_vpc\_id) | VPC ID |
10099
<!-- END_TF_DOCS -->

main.tf

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,20 @@ module "storage" {
4242
module "database" {
4343
source = "./modules/database"
4444

45-
db_identifier = var.db_identifier
46-
postgres_version = var.postgres_version
47-
instance_class = var.db_instance_class
48-
allocated_storage = var.db_allocated_storage
49-
database_name = var.database_name
50-
database_username = var.database_username
51-
multi_az = var.db_multi_az
52-
database_subnet_ids = module.networking.private_subnet_ids
53-
vpc_id = module.networking.vpc_id
54-
eks_security_group_id = module.eks.cluster_security_group_id
55-
tags = var.tags
56-
max_allocated_storage = var.db_max_allocated_storage
57-
database_password = var.database_password
45+
db_identifier = var.db_identifier
46+
postgres_version = var.postgres_version
47+
instance_class = var.db_instance_class
48+
allocated_storage = var.db_allocated_storage
49+
database_name = var.database_name
50+
database_username = var.database_username
51+
multi_az = var.db_multi_az
52+
database_subnet_ids = module.networking.private_subnet_ids
53+
vpc_id = module.networking.vpc_id
54+
eks_security_group_id = module.eks.cluster_security_group_id
55+
eks_node_security_group_id = module.eks.node_security_group_id
56+
tags = var.tags
57+
max_allocated_storage = var.db_max_allocated_storage
58+
database_password = var.database_password
5859
}
5960

6061
resource "aws_cloudwatch_log_group" "materialize" {
@@ -98,9 +99,6 @@ resource "aws_iam_user_policy" "materialize_s3" {
9899
})
99100
}
100101

101-
# Data source for current region
102-
data "aws_region" "current" {}
103-
104102
resource "aws_iam_role" "materialize_s3" {
105103
name = "${var.environment}-materialize-s3-role"
106104

modules/database/main.tf

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ module "db" {
1010
major_engine_version = var.postgres_version
1111
instance_class = var.instance_class
1212

13-
password = var.database_password
13+
manage_master_user_password = false
14+
password = var.database_password
1415

1516
allocated_storage = var.allocated_storage
1617
max_allocated_storage = var.max_allocated_storage
@@ -45,6 +46,15 @@ resource "aws_security_group" "database" {
4546
to_port = 5432
4647
protocol = "tcp"
4748
security_groups = [var.eks_security_group_id]
49+
description = "Allow PostgreSQL access from EKS cluster"
50+
}
51+
52+
ingress {
53+
from_port = 5432
54+
to_port = 5432
55+
protocol = "tcp"
56+
security_groups = [var.eks_node_security_group_id]
57+
description = "Allow PostgreSQL access from EKS nodes"
4858
}
4959

5060
egress {

modules/database/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ variable "eks_security_group_id" {
6060
type = string
6161
}
6262

63+
variable "eks_node_security_group_id" {
64+
description = "Security group ID of the EKS nodes"
65+
type = string
66+
}
67+
6368
variable "backup_retention_period" {
6469
description = "Number of days to retain backups"
6570
type = number

modules/eks/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ output "cluster_security_group_id" {
88
value = module.eks.cluster_security_group_id
99
}
1010

11+
output "node_security_group_id" {
12+
description = "Security group ID attached to the EKS nodes"
13+
value = module.eks.node_security_group_id
14+
}
15+
1116
output "cluster_iam_role_name" {
1217
description = "IAM role name for the cluster"
1318
value = module.eks.cluster_iam_role_name

outputs.tf

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ output "s3_bucket_name" {
2020

2121
output "metadata_backend_url" {
2222
description = "PostgreSQL connection URL in the format required by Materialize"
23-
value = format("postgres://%s:%s@%s/%s?sslmode=disable",
23+
value = format("postgres://%s:%s@%s/%s?sslmode=require",
2424
var.database_username,
2525
var.database_password,
2626
module.database.db_instance_endpoint,
@@ -30,16 +30,13 @@ output "metadata_backend_url" {
3030
}
3131

3232
output "persist_backend_url" {
33-
description = "S3 connection URL in the format required by Materialize"
34-
value = format("s3://%s:%s@%s/%s?endpoint=https%%3A%%2F%%2Fs3.%s.amazonaws.com&region=%s",
35-
aws_iam_access_key.materialize_user.id,
36-
aws_iam_access_key.materialize_user.secret,
33+
description = "S3 connection URL in the format required by Materialize using IRSA"
34+
value = format("s3://%s/%s:serviceaccount:%s:%s",
3735
var.bucket_name,
3836
var.environment,
39-
data.aws_region.current.name,
40-
data.aws_region.current.name
37+
var.namespace,
38+
var.service_account_name
4139
)
42-
sensitive = true
4340
}
4441

4542
# oidc_provider_arn

0 commit comments

Comments
 (0)