Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set enable_ecs_service_role to true only if there is a load balancer #118

Closed
wants to merge 4 commits into from

Conversation

verbalius
Copy link

When creating service, and there is no LB defined "You cannot specify an IAM role for services that require a service linked role."
Set enable_ecs_service_role to false when there is 0 LB or more than 1.

what

When creating service with network mode != awsvpc and there is no LB defined it throws error: "You cannot specify an IAM role for services that require a service linked.

why

When setting value enable_ecs_service_role we check if there is no more than 1 LB, but less than 1 is 0 and we can't assign IAM role when it is no LB and network mode is bridge, host or none.

solution

Set enable_ecs_service_role to false when there is 0 LB or more than 1 when network mode is not awsvpc

When creating service, and there is no LB defined "You cannot specify an IAM role for services that require a service linked role."
Set enable_ecs_service_role to false when there is 0 LB or more than 1.
@verbalius verbalius requested review from a team as code owners June 3, 2021 11:22
@verbalius verbalius requested a review from a team as a code owner June 3, 2021 11:23
@verbalius verbalius requested review from Makeshift and 3h4x and removed request for a team June 3, 2021 11:23
@mergify
Copy link

mergify bot commented Jun 15, 2021

This pull request is now in conflict. Could you fix it @verbalius? 🙏

main.tf Outdated
@@ -1,6 +1,6 @@
locals {
enabled = module.this.enabled
enable_ecs_service_role = module.this.enabled && var.network_mode != "awsvpc" && length(var.ecs_load_balancers) <= 1
enable_ecs_service_role = module.this.enabled && var.network_mode != "awsvpc" && length(var.ecs_load_balancers) == 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@verbalius the original code enables the enable_ecs_service_role if the length(var.ecs_load_balancers) <= 1 meaning if there aren't any load balancers.

Your change sets enables the enable_ecs_service_role if the number of load balancers is equivalent to 1 which conflicts with the PR title. Is this intended ? Could you explain ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi :)
I tried doing all the steps manually in the console and see

  1. Task with bridge mode network
    2.a. Service without LB (means length(var.ecs_load_balancers))
    Result: You can't specify IAM role

image
2.b Service with application LB for example
Result: Lets you choose a role

image

So if we transfer it to expression:
if LB count = 0 this should be null:
iam_role = local.enable_ecs_service_role ? coalesce(var.service_role_arn, join("", aws_iam_role.ecs_service.*.arn)) : null
But how it is now length(var.ecs_load_balancers)=0 <= 1 -> true

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or if you want to try it yourself via terraform just try to create service with bridge network mode without load balancer.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why your commit contains: length(var.ecs_load_balancers) == 1 ?

In our case we can define more than one load balancer for service..

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@verbalius can you update this PR please? Change it to >= 1

@nitrocode nitrocode changed the title set enable_ecs_service_role to false if there is no lb for service set enable_ecs_service_role to true only if there is a load balancer Jul 8, 2021
@nitrocode
Copy link
Member

/test all

@nitrocode nitrocode self-requested a review July 8, 2021 18:39
Copy link
Member

@nitrocode nitrocode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to wait for the security group module to be complete before this can go through.

See https://github.com/cloudposse/terraform-aws-ecs-alb-service-task/releases

Sorry!

@Nuru Nuru added the do not merge Do not merge this PR, doing so would cause problems label Jul 13, 2021
@nitrocode
Copy link
Member

@n0rig
Copy link

n0rig commented Oct 8, 2021

@nitrocode this PR (#118) should be closed and this one re-opened:
#137

The code change in this PR (#118) is wrong.

@verbalius verbalius closed this Oct 11, 2021
@verbalius verbalius reopened this Oct 11, 2021
@mergify mergify bot dismissed nitrocode’s stale review October 11, 2021 16:10

This Pull Request has been updated, so we're dismissing all reviews.

@verbalius
Copy link
Author

Sorry for inactivity, added a fix commit as is in pull request #137. Thank you for help

@n0rig
Copy link

n0rig commented Oct 12, 2021

@nitrocode / @joe-niland mind reviewing and merging?

Copy link

@n0rig n0rig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@joe-niland
Copy link
Member

/test all

@n0rig
Copy link

n0rig commented Oct 13, 2021

@Nuru Can you remove the 'do not merge' label?

@joe-niland
Copy link
Member

@n0rig just FYI, we are still waiting on some related fixes to happen before merging this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge Do not merge this PR, doing so would cause problems
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants