terraform-provider-cloudflare
terraform-provider-cloudflare copied to clipboard
Error message for failed importing is a bit missleading
Confirmation
- [X] My issue isn't already found on the issue tracker.
- [X] I have replicated my issue using the latest version of the provider and it is still present.
Terraform and Cloudflare provider version
terraform -v Terraform v1.6.6 on darwin_amd64
- provider registry.terraform.io/cloudflare/cloudflare v4.20.0
Affected resource(s)
cloudflare_list cloudflare_list_item
Terraform configuration files
resource "cloudflare_list" "example_list" {
name = "example"
account_id = var.account_id
kind = "redirect"
}
resource "cloudflare_list_item" "example_list_item" {
account_id = var.account_id
list_id = "cxxxxxxxxxxxxxxxxxxxxxxxx4ad6e26"
}
Link to debug output
https://gist.github.com/ztNIE/ae5456c503b66e544becb7ee0ffb7c05
Panic output
No response
Expected output
It should import the resource successfully.
Actual output
╷ │ Error: The provider returned a resource missing an identifier during ImportResourceState. This is generally a bug in the resource implementation for import. Resource import code should not call d.SetId("") or create an empty ResourceData. If the resource is missing, instead return an error. Please report this to the provider developers. │ │ ╵
Steps to reproduce
- Create a bulk redirect list in cloudflare
- Get the id of cloudflare redirect list id and list item id through cloudflare API. ref https://developers.cloudflare.com/api/operations/lists-get-a-list, https://developers.cloudflare.com/api/operations/lists-get-list-items
- Use the id of list and list item to try import the resource to your terraform config https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/list_item
Additional factoids
No response
References
No response
Community Note
Voting for Prioritization
- Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
- Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
Volunteering to Work on This Issue
- If you are interested in working on this issue, please leave a comment.
- If this would be your first contribution, please review the contribution guide.
I'm keen to work on this issue
this doesn't look like a bug but user error with the wrong ID?
filters.api.not_found: could not find list cc491d9e7bea493fa3a056ab83e03fb9
thanks for your timely reply jacob, I just confirmed that it's because of the wrong list ID. Perhaps the error message can be improved tho?
in most cases, what is happening here is normal behaviour. the end user provides the Import
string, we trust it and set the identifier, client makes a call to the API, the response is a HTTP 404 so we assume that it has been removed and should be cleaned up from state. the tricky bit is working out whether we can trust the identifier from the end user (which i don't have a good answer for other than making extra API calls before the Read
operation) 🤔
Yeah it's very tricky I agree and an extra API call probably doesn't worth it.
How about just make the error message provides a little bit more context?
I only created this issue because the error message said that "This is generally a bug in the resource implementation for import. ... Please report this to the provider developers." Since this error is expected when a wrong identifier is provided, could this error message contains something like "This could be caused by a wrong resource id is provided." I could fix the import command in seconds if I knew it's the id problem from the error message.
Just tried the error message for cloudflare_account_member importing is quite good
% terraform import cloudflare_account_member.tmp f09bcc1d3d02f25a6c68c2e781470b59/123908541902380984501
Acquiring state lock. This may take a few moments...
╷
│ Error: unable to find account member with ID "123908541902380984501": Member not found for account (1003)
the cloudflare_account_member
resource gives you a nicer message because it takes the route of making an additional API call before setting the identifier.
https://github.com/cloudflare/terraform-provider-cloudflare/blob/7c5bbad741530bf65f16dbcf5385f540505b551b/internal/sdkv2provider/resource_cloudflare_account_member.go#L137-L140
while this works, it basically makes you have an additional API call per import operation (which in some cases, is doubling the API calls made).
I am wondering if maybe we encounter errors, we can turn on a debug mode somehow? I am encountering this issue with importing worker script and was very worried that something was wrong on provider side.
terraform has the ability through logging to view the internals - https://developer.hashicorp.com/terraform/internals/debugging