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

Error message for failed importing is a bit missleading #3023

Open
2 tasks done
ztNIE opened this issue Dec 21, 2023 · 9 comments
Open
2 tasks done

Error message for failed importing is a bit missleading #3023

ztNIE opened this issue Dec 21, 2023 · 9 comments
Labels
kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. triage/debug-log-attached Indicates an issue or PR has a complete Terraform debug log.

Comments

@ztNIE
Copy link

ztNIE commented Dec 21, 2023

Confirmation

  • My issue isn't already found on the issue tracker.
  • 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

  1. Create a bulk redirect list in cloudflare
  2. 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
  3. 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

@ztNIE ztNIE added kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Dec 21, 2023
Copy link
Contributor

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.

@ztNIE
Copy link
Author

ztNIE commented Dec 21, 2023

I'm keen to work on this issue

@github-actions github-actions bot added the triage/debug-log-attached Indicates an issue or PR has a complete Terraform debug log. label Dec 21, 2023
@jacobbednarz
Copy link
Member

this doesn't look like a bug but user error with the wrong ID?

filters.api.not_found: could not find list cc491d9e7bea493fa3a056ab83e03fb9

@ztNIE
Copy link
Author

ztNIE commented Dec 21, 2023

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?

@ztNIE ztNIE changed the title Failed to import cloudflare_list and cloudflare_list_item resources Error message for failed importing is a bit missleading Dec 21, 2023
@jacobbednarz
Copy link
Member

jacobbednarz commented Dec 21, 2023

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) 🤔

@ztNIE
Copy link
Author

ztNIE commented Dec 21, 2023

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)

@jacobbednarz
Copy link
Member

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.

member, err := client.AccountMember(ctx, accountID, accountMemberID)
if err != nil {
return nil, fmt.Errorf("unable to find account member with ID %q: %w", accountMemberID, err)
}

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).

@xav-ie
Copy link

xav-ie commented Jan 2, 2024

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.

@jacobbednarz
Copy link
Member

terraform has the ability through logging to view the internals - https://developer.hashicorp.com/terraform/internals/debugging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. triage/debug-log-attached Indicates an issue or PR has a complete Terraform debug log.
Projects
None yet
Development

No branches or pull requests

3 participants