hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.74k stars 9.1k forks source link

error collecting instance settings: empty result when running terraform apply after terraform state rm #26163

Open paololazzari opened 2 years ago

paololazzari commented 2 years ago

I had deployed an EC2 instance with terraform. I then removed the EC2 instance from terraform with:

$ terraform state rm aws_instance.instance_1

now, when I try to re-create the instance I see an error:

$ terraform apply -auto-approve

Error: error collecting instance settings: empty result

with aws_instance.instance_1,
on instances.tf line 17, in resource "aws_instance" "instance1":
17: resource "aws_instance" "instance1" {

Note that terraform plan works as expected and shows the instance to be created:

Terraform Version

v.1.2.4

paololazzari commented 2 years ago

Apparently this was caused by an attempt to launch an instance from an AMI that was no longer available.

Can the error message be improved?

michelangelo136 commented 7 months ago

Just wasted 30' on an obscure error message, this still hasn't been improved.

saulfm08 commented 6 months ago

It is really impressive how this error message is useless. This happens if the AMI was deleted or made private; if your account has no longer access to the ami, this error is show.

EugenKon commented 5 months ago

I think this could happen when TF expects images "Owned by Me", but the user does not have such images. 2024-04-11_14-44

In my case I have only "Private snapshots/Private images" which were shared with me.

If I enable TF_LOG=debug terraform apply, I can see that TF receives empty response:

2024-04-11T14:39:10.813-0400 [DEBUG] provider.terraform-provider-aws_v5.44.0_x5: HTTP Response Received: http.response.header.content_type=text/xml;charset=UTF-8 rpc.service=EC2 tf_aws.sdk=aws-sdk-go http.duration=440 tf_mux_provider="*schema.GRPCProviderServer" @module=aws http.status_code=200
  http.response.body=
  | <?xml version="1.0" encoding="UTF-8"?>
  | <DescribeImagesResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
  |     <requestId>34f5c8d2-5736-4dc2-8137-b76494adf399</requestId>
  |     <imagesSet/>
  | </DescribeImagesResponse>
   http.response.header.cache_control="no-cache, no-store" http.response.header.date="Thu, 11 Apr 2024 18:39:10 GMT" http.response.header.server=AmazonEC2 rpc.system=aws-api tf_rpc=ApplyResourceChange aws.region=us-east-1 tf_resource_type=aws_instance http.response.header.x_amzn_requestid=34f5c8d2-5736-4dc2-8137-b76494adf399 http.response_content_length=219 tf_provider_addr=registry.terraform.io/hashicorp/aws tf_req_id=53bb7eea-ce90-26fc-6730-86cbabbb6d9c @caller=github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2@v2.0.0-beta.52/logger.go:157 http.response.header.strict_transport_security="max-age=31536000; includeSubDomains" rpc.method=DescribeImages timestamp=2024-04-11T14:39:10.812-0400