-
Notifications
You must be signed in to change notification settings - Fork 784
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
feat: allow emtpy invitation IDs #1488
feat: allow emtpy invitation IDs #1488
Conversation
With this, for_each can be used with github_user_invitation_accepter resources without producing errors for an empty invitation_id attribute.
When attempting to run the new integration test you've added, I get a panic: Can you reproduce this or does it succeed for you? |
@kfcampbell I was under the assumption that the tests ran automatically on PR. Running it locally gave me the same result and I fixed the bug you encountered. I had to however comment out the If you could enlighten me what I need to do for the tests to work there, I'd be happy about it 😊 |
Unfortunately only our unit tests run on PR, and the vast majority of our tests are integration tests. I run the relevant tests manually before merging any PRs, but it would be great for us to do this in an automated fashion. There's a previous attempt here that's been broken for quite some time now. In #1414 we've outlined work to start approaching this problem, though we've been unable to prioritize it unfortunately. It's probably the single biggest issue I have with the provider right now. Apologies!
You're correct; it is needed.
I'm sorry this isn't ideal! It bothers me as well (see again #1414). Here are some thoughts about what I do:
I tend to prefer to run integration tests in VSCode using a launch.json file of the kind below: {
// for information on how to debug the provider, see the CONTRIBUTING.md file
"version": "0.2.0",
"configurations": [
{
"name": "Launch test function",
"type": "go",
"request": "launch",
"mode": "test",
"program": "/home/kfcampbell/github/dev/terraform-provider-github/github/resource_github_team_members_test.go", // any Go file in the github package works here
"args": [
"-test.v",
"-test.run",
"^TestAccGithubUserInvitationAccepterAllowEmptyId$"
],
"env": {
"GITHUB_TEST_COLLABORATOR": "kfcampbell-terraform-test-user",
"GITHUB_TEST_COLLABORATOR_TOKEN": "REDACTED",
"GITHUB_TEST_USER": "kfcampbell",
"GITHUB_TOKEN": "REDACTED",
"GITHUB_TEMPLATE_REPOSITORY": "terraform-template-module",
"GITHUB_TEMPLATE_REPOSITORY_RELEASE_ID": "REDACTED",
//"GITHUB_OWNER": "kfcampbell-terraform-provider",
"GITHUB_ORGANIZATION": "kfcampbell-terraform-provider", // GITHUB_ORGANIZATION is required for organization integration tests
"TF_ACC": "1",
"TF_LOG": "DEBUG",
"APP_INSTALLATION_ID": "REDACTED"
}
}
]
} If you read that and think, "wow, that's way too much work", you'd be absolutely correct. For what it's worth, when running the tests above, I'm no longer seeing a panic but I do see an error:
In the above error message, I would normally expect to see the second sentence read something like "...produced an unexpected value for {someField}: was {previousValue}, but now absent." This makes me hypothesize that it might be related to the nil return value here without setting any form of ID like we do here. I'm not positive though! |
@kfcampbell Thanks for the detailed explanation. I now have a working setup for the tests 🎉 I pushed e99eca0 to fix the failing test.
You were correct about this. The problem here is that we only determine on resource creation that we actually don't want to do anything. But there is no way to use We want to create the resource, we just don't want the provider to do anything with it. We also don't have any kind of unique identifier to use as ID for the resource. I'd be very happy about a review here now 😊 |
@morremeyer have you validated this behavior manually? I'm reading this doc about Terraform provider development and it includes this snippet:
This made me think using a random UUID could have unintended consequences, though it sounds like a reasonable thing to do and your tests look good. If you'd like this merged and released, I can do so and we can iterate in the future if necessary! |
I validated it by running the test with the code setting I think we'll be fine with a UUID since the resources are never read later - the read operation is noop, see
As far as I understand it, with the current code it will save the resource to the state with the UUID an ID. When it comes to reading it, nothing happens. When it comes to deleting it, it's just removed from the state. Which is why I think the UUIDs are fine. If it turns out they are not, yes, let's iterate. I'd be very happy about this being released as it will unblock us 😊 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do it! I'll release this shortly.
We updated to v5.17.0 earlier and it works like a charm so far. Thanks for your review and all the input before! |
* feat: allow emtpy invitation IDs With this, for_each can be used with github_user_invitation_accepter resources without producing errors for an empty invitation_id attribute. * docs: improve documentation for current error states * fix: set ForceNew * fixup! feat: allow emtpy invitation IDs * fix: allow resource to be saved --------- Co-authored-by: Keegan Campbell <[email protected]>
* feat: allow emtpy invitation IDs With this, for_each can be used with github_user_invitation_accepter resources without producing errors for an empty invitation_id attribute. * docs: improve documentation for current error states * fix: set ForceNew * fixup! feat: allow emtpy invitation IDs * fix: allow resource to be saved --------- Co-authored-by: Keegan Campbell <[email protected]>
Part of #1157.
Behavior
Before the change?
github_user_invitation_accepter
required aninvitation_id
to be set.This made it impossible to use a
github_user_invitation_accepter
withfor_each
sincea
github_repository_collaborator.invitation_id
will be empty after a state refresh whenthe invitation has been accepted.
After the change?
The new argument
allow_empty_id
can be set totrue
, allowing theinvitation_id
to be empty.In that case, the resource does nothing.
If the
invitation_id
is set, the behavior is the same as before.This allows for automated adding of a collaborator to a changing list of repositories (e.g. with
the
github_repositories
datasource) without the plan to fail after a state refresh.Other information
Note that as reported in #1157, when an invitation is accepted between the state refresh and the apply,
this will still result in a 404 error for the invitation in the API.
Additional info
Pull request checklist
Does this introduce a breaking change?
Please see our docs on breaking changes to help!
Type: Breaking change
label)Pull request type
Type: Feature