Skip to content

Commit b39c076

Browse files
author
Alexander Wiechert
committed
fixing base variables
1 parent c200eb5 commit b39c076

File tree

6 files changed

+92
-27
lines changed

6 files changed

+92
-27
lines changed

main.tf

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1+
module "grafana" {
2+
source = "./modules/grafana"
3+
vpc_id = var.vpc_id
4+
project_name = var.project_name
5+
}
6+
17
resource "aws_ecs_cluster" "this" {
2-
name = var.cluster_name
8+
name = var.project_name
39
}
410

511
# --- Load Balancer + Target Group ---
612
resource "aws_lb" "grafana" {
7-
name = "${var.name}-alb"
13+
name = "${var.project_name}-alb"
814
internal = false
915
load_balancer_type = "application"
1016
security_groups = [aws_security_group.grafana_sg.id]
1117
subnets = var.subnet_ids
1218
}
1319

1420
resource "aws_lb_target_group" "grafana_tg" {
15-
name = "${var.name}-tg"
21+
name = "${var.project_name}-tg"
1622
port = 3000
1723
protocol = "HTTP"
1824
target_type = "ip"
@@ -32,10 +38,8 @@ resource "aws_lb_target_group" "grafana_tg" {
3238

3339
resource "aws_lb_listener" "https" {
3440
load_balancer_arn = aws_lb.grafana.arn
35-
port = 443
36-
protocol = "HTTPS"
37-
ssl_policy = "ELBSecurityPolicy-2016-08"
38-
certificate_arn = var.certificate_arn
41+
port = 3000
42+
protocol = "HTTP"
3943

4044
default_action {
4145
type = "forward"
@@ -45,9 +49,9 @@ resource "aws_lb_listener" "https" {
4549

4650
# --- ECS Service ---
4751
resource "aws_ecs_service" "grafana" {
48-
name = "${var.name}-service"
52+
name = "${var.project_name}-service"
4953
cluster = aws_ecs_cluster.this.id
50-
task_definition = aws_ecs_task_definition.grafana.arn
54+
task_definition = module.grafana.task_definition_arn
5155
launch_type = "FARGATE"
5256
desired_count = 1
5357

@@ -62,19 +66,44 @@ resource "aws_ecs_service" "grafana" {
6266
container_name = "grafana"
6367
container_port = 3000
6468
}
65-
66-
depends_on = [aws_iam_role_policy_attachment.ecs_task_exec_policy]
6769
}
6870

6971
# --- DNS (optional) ---
70-
resource "aws_route53_record" "grafana_dns" {
71-
zone_id = var.zone_id
72-
name = var.domain_name
73-
type = "A"
72+
# resource "aws_route53_record" "grafana_dns" {
73+
# zone_id = var.zone_id
74+
# name = var.domain_name
75+
# type = "A"
76+
#
77+
# alias {
78+
# name = aws_lb.grafana.dns_name
79+
# zone_id = aws_lb.grafana.zone_id
80+
# evaluate_target_health = true
81+
# }
82+
# }
83+
84+
resource "aws_security_group" "grafana_sg" {
85+
name = "${var.project_name}-grafana-sg"
86+
description = "Security Group for Grafana"
87+
vpc_id = var.vpc_id
7488

75-
alias {
76-
name = aws_lb.grafana.dns_name
77-
zone_id = aws_lb.grafana.zone_id
78-
evaluate_target_health = true
89+
ingress {
90+
description = "Allow ALB to Grafana on port 3000"
91+
from_port = 3000
92+
to_port = 3000
93+
protocol = "tcp"
94+
cidr_blocks = ["0.0.0.0/0"] # Nur für Tests – später auf ALB Security Group einschränken!
95+
# security_groups = [var.alb_security_group_id] # Besser: explizite SG, siehe oben
7996
}
80-
}
97+
98+
egress {
99+
description = "Allow all outbound traffic"
100+
from_port = 0
101+
to_port = 0
102+
protocol = "-1"
103+
cidr_blocks = ["0.0.0.0/0"]
104+
}
105+
106+
tags = {
107+
Name = "${var.project_name}-grafana-sg"
108+
}
109+
}

modules/grafana/main.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# --- IAM Role for Fargate Task Execution ---
22
resource "aws_iam_role" "grafana_task_execution" {
3-
name = "${var.name}-task-execution-role"
3+
name = "${var.project_name}-task-execution-role"
44

55
assume_role_policy = jsonencode({
66
Version = "2012-10-17",
@@ -22,15 +22,15 @@ resource "aws_iam_role_policy_attachment" "ecs_task_exec_policy" {
2222

2323
# --- Security Group ---
2424
resource "aws_security_group" "grafana_sg" {
25-
name = "${var.name}-sg"
26-
description = "Allow HTTP/HTTPS access to Grafana"
25+
name = "${var.project_name}-sg"
26+
description = "Allow HTTP 3000 access to Grafana"
2727
vpc_id = var.vpc_id
2828

2929
ingress {
30-
from_port = 443
31-
to_port = 443
30+
from_port = 3000
31+
to_port = 3000
3232
protocol = "tcp"
33-
cidr_blocks = var.allowed_cidr_blocks
33+
cidr_blocks = var.subnet_ids // muss auf öffentlich gesetzt werden sobald SSL verfübar ist.
3434
}
3535

3636
egress {
@@ -43,7 +43,7 @@ resource "aws_security_group" "grafana_sg" {
4343

4444
# --- Task Definition ---
4545
resource "aws_ecs_task_definition" "grafana" {
46-
family = "${var.name}-task"
46+
family = "${var.project_name}-task"
4747
network_mode = "awsvpc"
4848
requires_compatibilities = ["FARGATE"]
4949
cpu = "256"
File renamed without changes.

modules/grafana/variables.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,19 @@ variable "execution_role_name" {
4646
type = string
4747
default = "ecsTaskExecutionRole"
4848
}
49+
50+
variable "vpc_id" {
51+
description = "The id of the VPC"
52+
type = string
53+
}
54+
55+
variable "subnet_ids" {
56+
type = list(string)
57+
default = []
58+
description = "A list of subnet ids."
59+
}
60+
61+
variable "project_name" {
62+
type = string
63+
default = "FinOPS-reporting"
64+
}

outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "vpc_id" {
2+
value = var.vpc_id
3+
}
4+

variables.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
variable "project_name" {
2+
type = string
3+
default = "FinOPS-reporting"
4+
}
5+
16
variable "use_fake_data" {
27
description = "Enable fake/test mode (no AWS resources created)"
38
type = bool
@@ -55,4 +60,15 @@ variable "tag_filter_value" {
5560
description = "Tag value used to filter for ENV"
5661
type = string
5762
default = "Production"
63+
}
64+
65+
variable "vpc_id" {
66+
description = "The id of the VPC"
67+
type = string
68+
}
69+
70+
variable "subnet_ids" {
71+
type = list(string)
72+
default = []
73+
description = "A list of subnet ids."
5874
}

0 commit comments

Comments
 (0)