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(aws_instance): add ignore_ami_changes option #209

Closed
wants to merge 1 commit into from

Conversation

Lawstorant
Copy link

what

Allow ignoring AMI image ID changes. EC2 instance won't be recreated If the AMI image id is provided from a data source changes.

why

We use an aws_ami data Blocks that always provides the most recent version of selected image but that will cause the EC2 to recreate if the image is updated. We want to be able to upgrade only when we see fit.

@Lawstorant Lawstorant requested review from a team as code owners September 6, 2024 10:39
@mergify mergify bot added the triage Needs triage label Sep 6, 2024
@@ -171,6 +171,10 @@ resource "aws_instance" "default" {
tags = module.this.tags

volume_tags = var.volume_tags_enabled ? module.this.tags : {}

lifecycle {
ignore_changes = var.ignore_ami_changes ? [ami] : []
Copy link
Member

Choose a reason for hiding this comment

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

I don't believe variables are supported in lifecycle blocks in terraform

Copy link
Author

@Lawstorant Lawstorant Oct 1, 2024

Choose a reason for hiding this comment

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

You're right. Well, that's what I get by not testing things properly

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.

See comments

@nitrocode
Copy link
Member

nitrocode commented Sep 6, 2024

Thanks for the pr @Lawstorant. Instead of updating the module, have you considered simply setting the ami input of the module? That should prevent your ec2 from getting recreated.

Also have you folks considered using an autoscaling group of 1 instance to have more control over the EC2s ? It might be better for your purposes.

@Lawstorant
Copy link
Author

My problem is that I'm setting the ami input already, but the input data comes from a filter in a data source. Well, I'm going to filter it better and close this for now.

@Lawstorant Lawstorant closed this Oct 1, 2024
@mergify mergify bot removed the triage Needs triage label Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants