Skip to content

Commit

Permalink
Fix terraform security groups (#48)
Browse files Browse the repository at this point in the history
* fixed the security groups

* added service identifier

* reverted example to mocks

* allowing to override the ecr repo url

* renamed

* renamed

* moved to locals
  • Loading branch information
yairsimantov20 authored Aug 3, 2023
1 parent 9eafbf9 commit 5fa49bc
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
13 changes: 11 additions & 2 deletions deployment/terraform/aws/ecs/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
locals {
security_groups = concat(
var.additional_security_groups,
var.allow_incoming_requests ? module.port_ocean_ecs_lb[0].security_groups : []
)
}

data "jsonschema_validator" "event_listener_validation" {
document = jsonencode(var.event_listener)
schema = "${path.module}/defaults/event_listener.json"
Expand All @@ -18,8 +25,10 @@ module "port_ocean_ecs" {
cluster_name = var.cluster_name


lb_targ_group_arn = var.allow_incoming_requests ? module.port_ocean_ecs_lb[0].target_group_arn : ""
additional_security_groups = var.additional_security_groups
lb_targ_group_arn = var.allow_incoming_requests ? module.port_ocean_ecs_lb[0].target_group_arn : ""
additional_security_groups = local.security_groups

image_registry = var.image_registry

port = {
client_id = var.port.client_id
Expand Down
4 changes: 3 additions & 1 deletion deployment/terraform/aws/ecs/modules/ecs_lb/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ output "target_group_arn" {
}

output "security_groups" {
value = aws_lb.ocean_lb.security_groups
value = var.create_default_sg ? concat(
var.additional_security_groups, [aws_security_group.default_ocean_sg[0].id]
) : var.additional_security_groups
}
7 changes: 5 additions & 2 deletions deployment/terraform/aws/ecs/modules/ecs_service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ data "aws_iam_policy_document" "ecs_assume_role_policy" {

principals {
type = "Service"
identifiers = ["ecs-tasks.amazonaws.com"]
identifiers = [
"ecs-tasks.amazonaws.com",
"ecs.amazonaws.com"
]
}
}
}
Expand Down Expand Up @@ -153,7 +156,7 @@ resource "aws_ecs_task_definition" "service_task_definition" {
container_definitions = jsonencode(
[
{
image = "${var.ecr_repo_url}/port-ocean-${var.integration.type}:${var.integration_version}",
image = "${var.image_registry}/port-ocean-${var.integration.type}:${var.integration_version}",
cpu = var.cpu,
memory = var.memory,
name = local.service_name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
variable "ecr_repo_url" {
variable "image_registry" {
type = string
default = "ghcr.io/port-labs"
}
Expand Down
2 changes: 1 addition & 1 deletion deployment/terraform/aws/ecs/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ variable "egress_ports" {
default = []
}

variable "ecr_repo_url" {
variable "image_registry" {
type = string
default = "ghcr.io/port-labs"
}
Expand Down

0 comments on commit 5fa49bc

Please sign in to comment.