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

Please add a feature to show the module or resource addresses which is failed to import existing ID #35138

Open
SudharsaneSivamany opened this issue May 8, 2024 · 3 comments
Labels
enhancement new new issue not yet triaged

Comments

@SudharsaneSivamany
Copy link

Terraform Version

1.8.2

Use Cases

While trying to import an non existing resource, We get only errored variable is set to "true" in plan.json, but not the actual modules or resources addresses which will import the id is not listed in plan.json. Though the Error outputs message as below text . Could you please add the resources or modules addresses which are failing in import as part of the plan.json.

│ Error: Cannot import non-existent remote object

│ While attempting to import an existing object to
│ "module.spoke-network.azurerm_resource_group.spoke["rg-spoke"]",
│ the provider detected that no object exists with the given id. Only
│ pre-existing objects can be imported; check that the id is correct and that
│ it is associated with the provider's configured region or endpoint, or use
│ "terraform apply" to create a new remote object for this resource.

Sample plan.json
{
"timestamp": "2024-05-08T13:34:31Z",
"applyable": false,
"complete": false,
"errored": true
}

Attempted Solutions

Expected plan.json

{
"timestamp": "2024-05-08T13:34:31Z",
"applyable": false,
"complete": false,
"errored": true
"cannot_import_non_existent_remote_object": [
"module.spoke-network.azurerm_resource_group.spoke["rg-spoke"]"
]
}

Proposal

No response

References

No response

@SudharsaneSivamany SudharsaneSivamany added enhancement new new issue not yet triaged labels May 8, 2024
@apparentlymart
Copy link
Member

Hi @SudharsaneSivamany! Thanks for this feature request.

Can you say more about what you are intending to do with this information if it were added? That will help both to understand the value of adding this new information and to make sure that what is added would actually meet your goal.

Thanks!

@SudharsaneSivamany
Copy link
Author

SudharsaneSivamany commented May 8, 2024

Hi @apparentlymart . Greetings.

I published a tool as a MVP, which is helpful to create import block for the terraform modules or resources. Please have a look at "https://github.com/SudharsaneSivamany/tfimport" .

https://www.youtube.com/watch?v=yS5mZrBPdKc&t=385s

Working procedure :

Step 1: This tool will create import blocks from running a terraform plan towards modules/resources and generate the id and to address
Step 2: After generating the import blocks again it will run plan to check it is an existing resources or not. and remove the import block if it is a non-existing resources.

NEED FOR THE FEATURE:
Terraform plan shows only error output rather than showing it in plan.json. If the non-existing resources import blocks are displayed as part of plan.json, then it will be easy to pick the list from plan.json and it can remove those import blocks.

Currently i'm picking the errored import block address(modules/resource) from standard errors and redefining it to get the module/resource address.

So if this feature added , then i could pick it from plan.json which is pretty straight forward and easy to implement.

Thanking You!!!

@apparentlymart
Copy link
Member

Thanks for those extra details, @SudharsaneSivamany!

The Terraform team will consider what it would take to achieve what you've proposed, and also consider other possible ways to achieve the same effect that might be more straightforward to implement. This isn't an area of immediate focus right now, so I want to be explicit that you might not get a further response immediately, but we'll leave this issue open to represent the use-case.

In the meantime, if others find this issue and have a similar use-case it would help if you could leave a comment with some similar context about what you are trying to achieve, and to add a 👍 reaction to the original issue comment (not to this comment) which the Terraform team uses as one signal for prioritizing which areas to consider next. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement new new issue not yet triaged
Projects
None yet
Development

No branches or pull requests

2 participants