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

Feat/instance profile iam #187

Closed

Conversation

florian0410
Copy link
Contributor

@florian0410 florian0410 commented Aug 2, 2021

what

  • Enhancement of Allow use of existing IAM role for EC2 instance profile #107 + Allow use of existing IAM role for EC2 instance profile #113, due to original developer seemingly abandoning the original PR.
    • Adds service_role_name as another 'override', like instance_role_name is in the original PR.
  • Allow the user of the module to specify an existing IAM Role name for the instance profile.
  • Allow the user of the module to specify an existing IAM Role name for the service profile.
  • This IAM role name will be used to create the instance profile that is assigned to the EC2 instances managed by Elastic Beanstalk.
  • Add lifecycle create_before_destroy since some of my testings showed that we could break the environment if we remove the IAM role before Beanstalk finished to update the environment.
  • Add example using nlb

why

  • Some environments/users do not have the ability to create their own IAM roles/policies, for security reasons. This change allows a user to provide their own IAM role if one already exists.
  • Currently the module creates an IAM role and a series of permissions for the role.
  • It is hard to specify what permission to use
  • We cannot entirely define the permissions to use even with extended_ec2_policy_document

references

Mentions

I reused propositions from #113 and #107 for this PR with some rebase, thank you to @bstascavage and @JBarna

@florian0410 florian0410 requested review from a team as code owners August 2, 2021 21:24
@florian0410 florian0410 requested review from adamcrews and Benbentwo and removed request for a team August 2, 2021 21:24
@florian0410
Copy link
Contributor Author

/test all

main.tf Outdated Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
Enable trigger to new resources associated

Co-authored-by: nitrocode <nitrocode@users.noreply.github.com>
README.yaml Outdated Show resolved Hide resolved
name = "${module.this.id}-eb-service"
assume_role_policy = data.aws_iam_policy_document.service.json
tags = module.this.tags
lifecycle {
create_before_destroy = true
}
Copy link
Member

Choose a reason for hiding this comment

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

If these resources are created before destroyed, there would be a name conflict, no?

Why are these lifecycles added?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The role should never change except if we rename it so it's safe to add.

I added it because I encountered a stuck issue with beanstalk while refreshing my environment. Imagine you are changing from default aws_iam_role to service_role_name but for some reason, beanstalk fail during process. Beanstalk will try to rollback but if terraform already removed the original role, it's going to hard stuck the environment and will require an advanced debug maybe with CLI or by recreating the whole environment.

By ensuring we destroy this resource at the end of beanstalk deployment, we make sure beanstalk is able to rollback to its previous configuration in case of failure.

Copy link
Member

Choose a reason for hiding this comment

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

I added it because I encountered a stuck issue with beanstalk while refreshing my environment. Imagine you are changing from default aws_iam_role to service_role_name but for some reason, beanstalk fail during process.

This sounds like a corner case. Is that right ?

The create_before_destroy lifecycle sounds like it could cause other problems. I'll defer to my teammates to see if they have any issues with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding some insights for this discussion.

The actual default iam role and policy give a lot of rights for launching anything using beanstalk. The goal here is to let the user define a fully new instance profile from scratch.

Considering it's beanstalk, a single missing right can mess easily an environment. Someone who would switch from the module default iam role to a custom one may stuck its environment since we implement too many policies.

Copy link
Member

Choose a reason for hiding this comment

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

A missing right? What do you mean? Do you mean a missing resource?

Why should it matter how many policies we apply? That shouldn't be causing issues

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I'm talking about missing rights, it's in the case where the user use its own instance_profile or service role for beanstalk.

In the module defaults, we already defined basic requirements that ensure beanstalk get health status of applications and have rights for deploying.

But when a user choose to manage its own rights, we should consider the eventuality where he does not define correctly these and miss some rights he thought were not needed. Which can lead to beanstalk failing the deployment and rolling back then.

I'm not sure if I'm clear enough, maybe we could reach through slack if you prefer ?

main.tf Show resolved Hide resolved
@nitrocode
Copy link
Member

The create_before_destroy lifecycle sounds like it could cause other problems. I'll defer to my teammates to see if they have any issues with it.

cc: @aknysh @jamengual

@florian0410
Copy link
Contributor Author

/test all

main.tf Show resolved Hide resolved
variables.tf Outdated Show resolved Hide resolved
variables.tf Outdated Show resolved Hide resolved
@florian0410
Copy link
Contributor Author

/test all

@florian0410
Copy link
Contributor Author

Hello @nitrocode just fixed some things according to your suggestions.

Is the security groups feature still blocking MR in this repository ?

@mergify
Copy link
Contributor

mergify bot commented Dec 16, 2021

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

@aknysh
Copy link
Member

aknysh commented Dec 31, 2021

@florian0410 please resolve the conflicts

1 similar comment
@aknysh
Copy link
Member

aknysh commented Jan 18, 2022

@florian0410 please resolve the conflicts

@lbeltramino-uala
Copy link

@florian0410 please resolve the conflicts!

1 similar comment
@lbeltramino
Copy link

@florian0410 please resolve the conflicts!

@damiromero-uala
Copy link

please resolve the conflicts! we need this

@Gowiem
Copy link
Member

Gowiem commented Nov 27, 2022

@lbeltramino-uala @lbeltramino @damiromero-uala -- At this point, I think @florian0410 is likely too busy and isn't likely to pick this one up. I would highly suggest that one of you take his work and create a new branch, work through the conflicts, and PR that. I would be happy to review, so please add me as a reviewer if you choose to do so. Thanks!

@hans-d hans-d added the stale This PR has gone stale label Mar 2, 2024
@hans-d hans-d closed this Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale This PR has gone stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option to provide instance profile role or role policy
10 participants