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

launch_config fails trying to refresh ami id rotated/deleted by AWS #10772

Closed
ssunkari opened this issue Nov 6, 2019 · 4 comments
Closed

launch_config fails trying to refresh ami id rotated/deleted by AWS #10772

ssunkari opened this issue Nov 6, 2019 · 4 comments
Labels
service/autoscaling Issues and PRs that pertain to the autoscaling service. service/ec2 Issues and PRs that pertain to the ec2 service.

Comments

@ssunkari
Copy link

ssunkari commented Nov 6, 2019

Terraform plan fails to run when AWS deleted any images associated to ami-id.
AWS confirmed that they only keep last 4 revisions and its possible to delete any images associated with any ami-id if they find exposed to any security risks.

Terraform is attempting to get ami details (deleted by AWS) to show the diff to the latest ami using below data filter and hence AWS returns [] for the below query
aws ec2 describe-images --image-ids ami-0e539f1b7d4260eec --profile infra-dev --region eu-west-2
{
"Images": []
}

Terraform fails with below error
aws_launch_configuration.as_launch_cfg: No images found for AMI ami-0e539f1b7d4260eec

Terraform Version

Terraform v0.12.13

Affected Resource(s)

data "aws_ami" "ami" {
most_recent = true
owners = ["${var.ami_owner}"]

filter {
name = "name"
values = ["${var.ami_name_filter}"]
}

filter {
name = "virtualization-type"
values = ["hvm"]
}
}

resource "aws_launch_configuration" "as_launch_cfg" {
name_prefix = "${var.app_name}-${var.app_environment}-lc"
image_id = "${data.aws_ami.ami.id}"
instance_type = "${var.instance_type}"
key_name = "${var.ec2_keypair}"
security_groups = ["${concat(list(data.aws_security_group.rdp_security_group.id,data.aws_security_group.http_security_group.id), var.extra_security_groups)}"]
iam_instance_profile = "${var.iam_instance_profile}"
user_data = "${data.template_file.user_data.rendered}"

root_block_device {
volume_type = "${var.root_block_device_volume_type}"
volume_size = "${var.root_block_device_volume_size}"
}

lifecycle {
create_before_destroy = true
}
}

resource "aws_autoscaling_group" "asg" {
name = "${var.app_name}-asg-${var.app_environment}"
launch_configuration = "${aws_launch_configuration.as_launch_cfg.name}"
min_size = "${var.asg_min_instances}"
max_size = "${var.asg_max_instances}"
desired_capacity = "${var.asg_desired_capacity}"
vpc_zone_identifier = ["${data.aws_subnet_ids.ec2_pvt_subnets.ids}"]
depends_on = ["aws_launch_configuration.as_launch_cfg"]

tags = ["${concat(
list(
map("key", "Provisioner", "value", "CodeDeploy", "propagate_at_launch", true),
),
var.extra_tags)
}"]

lifecycle {
create_before_destroy = true
}
}

Expected Behavior

In this case terraform should handle the fact that no images have been found for the ami_id for existing lc and should update the lc with the new ami specified.

Actual Behavior

terraform fails to run the plan when no images have been found for the ami_id for existing lc and a new ami is detected to update the launch config.

Steps to Reproduce

Create a launch Config with a ami-0e539f1b7d4260eec apply to lc to asg
Try updating the launch config with latest ami and run plan, you will get
below error
aws_launch_configuration.as_launch_cfg: No images found for AMI ami-0e539f1b7d4260eec

  1. terraform plan
@ghost ghost added service/autoscaling Issues and PRs that pertain to the autoscaling service. service/ec2 Issues and PRs that pertain to the ec2 service. labels Nov 6, 2019
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Nov 6, 2019
@iancward
Copy link
Contributor

iancward commented Nov 6, 2019

This may be a duplicate of #10182.

@andydix
Copy link

andydix commented Jul 20, 2020

Yes, this was fixed via ticket #10182. Update the version of the AWS provider being used and that should fix this.

@ssunkari as this is quite an old post and has been resolved, are you able to close it?

@ssunkari
Copy link
Author

@andydix cheers Andy, I haven't tested it myself but I have not seen this error most recently, guess must have been fixed. Thanks for the update. I will close the issue.

@ghost
Copy link

ghost commented Aug 19, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Aug 19, 2020
@breathingdust breathingdust removed the needs-triage Waiting for first response or review from a maintainer. label Sep 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/autoscaling Issues and PRs that pertain to the autoscaling service. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
Development

No branches or pull requests

4 participants