Skip to content

Commit

Permalink
adding Module to test if Logs for ALB work
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Elhaiek committed Apr 9, 2024
1 parent a4bd000 commit aef4543
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 6 deletions.
20 changes: 20 additions & 0 deletions terraform/iam.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# # POLICY TO LET BUCKET PERMISSIONS:

data "aws_elb_service_account" "main" {}

data "aws_iam_policy_document" "bucket_policy" {
statement {
actions = ["s3:PutObject"]
resources = ["${aws_s3_bucket.logging_bucket.arn}/*"]

principals {
type = "AWS"
identifiers = [data.aws_elb_service_account.main.arn]
}
}
}

resource "aws_s3_bucket_policy" "bucket_policy" {
bucket = aws_s3_bucket.nlb_logs.id
policy = data.aws_iam_policy_document.bucket_policy.json
}



# # subir como data y statement como en el infra ops en vez de esta forma:
# resource "aws_s3_bucket_policy" "alb_log_bucket_policy" {
Expand Down
15 changes: 10 additions & 5 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ resource "aws_route_table_association" "vectorstore_rta" {
# }
# }

module "alb_logging" {
source = "./modules/alb_logging"
bucket_name = "milvus-api-alb-logs"
// other necessary variables
}



Expand All @@ -106,11 +111,11 @@ resource "aws_lb" "vectorstore_nlb" {
subnets = [aws_subnet.vectorstore_subnet.id, aws_subnet.vectorstore_subnet_2.id]
enable_deletion_protection = false

# access_logs {
# bucket = aws_s3_bucket.nlb_logs.bucket
# prefix = "access-logs"
# enabled = true
# }
access_logs {
bucket = module.alb_logging.bucket_name
prefix = "logs"
enabled = true
}

tags = {
Name = "vectorstore_nlb"
Expand Down
22 changes: 22 additions & 0 deletions terraform/modules/alb_logging/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
resource "aws_s3_bucket" "logging_bucket" {
bucket = var.bucket_name
}

data "aws_elb_service_account" "main" {}

data "aws_iam_policy_document" "bucket_policy" {
statement {
actions = ["s3:PutObject"]
resources = ["${aws_s3_bucket.logging_bucket.arn}/*"]

principals {
type = "AWS"
identifiers = [data.aws_elb_service_account.main.arn]
}
}
}

resource "aws_s3_bucket_policy" "bucket_policy" {
bucket = aws_s3_bucket.logging_bucket.id
policy = data.aws_iam_policy_document.bucket_policy.json
}
4 changes: 4 additions & 0 deletions terraform/modules/alb_logging/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "bucket_name" {
description = "The name of the S3 bucket for ALB logs"
value = aws_s3_bucket.logging_bucket.bucket
}
5 changes: 5 additions & 0 deletions terraform/modules/alb_logging/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "bucket_name" {
description = "The name of the bucket to be created for storing ALB logs."
type = string
default = "milvus-api-alb-logs"
}
1 change: 0 additions & 1 deletion terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ variable "key_name" {
# No default provided; should be specified at runtime or via terraform.tfvars for security reasons
}


0 comments on commit aef4543

Please sign in to comment.