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.86k stars 9.21k forks source link

[Enhancement]: provide import command when resource already exists #29929

Open Omarimcblack opened 1 year ago

Omarimcblack commented 1 year ago

Description

When a resource already exists, introduce functionality that auto reports in the error message the correct way said resource can be imported. A read operation should therefore be performed when the EntityAlreadyExists error occurs. The resultant information can be used to populate import input.

- Error creating [resource-type] [resource-name]: EntityAlreadyExists: [resource-type] with [resource-name] already exists. status code: 409, request id:
+ Error creating [resource-type] [resource-name]: EntityAlreadyExists: [resource-type] with [resource-name] already exists. status code: 409, request id:...
+ import using $ terraform import [resource-type].[resource-name] [resource-id]

example:

terraform import aws_ec2_transit_gateway_peering_attachment.example tgw-attach-12345678

where the ID tgw-attach-12345678 would have been computed having tried to create an already present peering.

Affected Resource(s) and/or Data Source(s)

No response

Potential Terraform Configuration

No response

References

No response

Would you like to implement a fix?

No

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue