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

AMI will always upgrade #68

Closed
razorsedge opened this issue Mar 19, 2021 · 2 comments
Closed

AMI will always upgrade #68

razorsedge opened this issue Mar 19, 2021 · 2 comments
Labels
bug 🐛 An issue with the system

Comments

@razorsedge
Copy link

Describe the Bug

As of version 0.25.0, AMIs are dynamically sourced and will force redeployment of this EC2 instance resource whenever the AMI is found to be updated.

data "aws_ami" "default" {
  most_recent = "true"
...

Expected Behavior

Bastion host should be redeployed when I determine and not the AMI creator.

Additional Context

Perhaps use an optional ignore_changes?

  lifecycle {
    ignore_changes = [
      ami,
    ]
  }
@razorsedge razorsedge added the bug 🐛 An issue with the system label Mar 19, 2021
@nitrocode
Copy link
Member

nitrocode commented Aug 22, 2021

The easy fix is to ignore ami. I think the best method is to use an asg and a launch template to define the ami. If the ami updates, then we can update the launch template which would prevent updating the existing ec2 instance.

See #25

@nitrocode
Copy link
Member

actually you can use a filter to pin the ami

dynamic "filter" {
for_each = var.ami_filter
content {
name = filter.key
values = filter.value
}
}

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami#filter

https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-images.html#options

image-id - The ID of the image.

module "ec2_bastion" {
  source  = "cloudposse/ec2-bastion-server/aws"
  version = "0.27.0"

  ami_filters = {
    "image-id" = "ami-1234567890"
  }

  instance_type               = var.instance_type
  security_groups             = compact(concat([module.vpc.vpc_default_security_group_id], var.security_groups))
  subnets                     = module.subnets.public_subnet_ids
  key_name                    = module.aws_key_pair.key_name
  user_data                   = var.user_data
  vpc_id                      = module.vpc.vpc_id
  associate_public_ip_address = var.associate_public_ip_address

  context = module.this.context
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An issue with the system
Projects
None yet
Development

No branches or pull requests

2 participants