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

Can't import github_branch_protection using repository node_id:branch pattern #671

Closed
faultylee opened this issue Jan 25, 2021 · 5 comments · Fixed by #713
Closed

Can't import github_branch_protection using repository node_id:branch pattern #671

faultylee opened this issue Jan 25, 2021 · 5 comments · Fixed by #713
Labels
Good first issue Good for newcomers r/branch_protection Type: Bug Something isn't working as documented

Comments

@faultylee
Copy link

faultylee commented Jan 25, 2021

Terraform Version

  • v0.14.3
  • terraform-provider-github_v4.2.0

Affected Resource(s)

  • branch_protection

Debug Output

I had to masked the org
https://gist.github.com/faultylee/0fa1a34cade6ee047f9e81967fd93993

Expected Behavior

Import of branch_protection works with node_id

Actual Behavior

node_id use during import was interpreted as repo_name

Steps to Reproduce

  • terraform init
  • terraform import github_branch_protection.repo_branch_protection 'MDEwOlJlcG9zaXRvcnkzMzI2ODM4OTc=:main'

References

@jcudit jcudit added Type: Bug Something isn't working as documented r/branch_protection Good first issue Good for newcomers labels Jan 26, 2021
tibbes added a commit to tibbes/terraform-provider-github that referenced this issue Feb 28, 2021
Importing a branch protection rule by an ID of the form
<repo-node-id>:<pattern> was broken.

Closes: integrations#671
jcudit pushed a commit that referenced this issue Mar 1, 2021
* Add test for importing github_branch_protection

There was an existing test for importing by <repo-name>:<pattern>,
but not a test for <repo-node-id>:<pattern>.

* Fix importing github_branch_protection

Importing a branch protection rule by an ID of the form
<repo-node-id>:<pattern> was broken.

Closes: #671
@tibbes
Copy link
Contributor

tibbes commented Mar 1, 2021

Thanks for the bug report @faultylee. The fix has been merged, so it will be in the next release.

@bateller
Copy link

bateller commented Mar 8, 2021

Thanks for the bug report @faultylee. The fix has been merged, so it will be in the next release.

@tibbes Are we sure this is resolved? I'm still having issues importing with node_id

Initializing the backend...

Initializing provider plugins...
- Finding integrations/github versions matching "~> 4.0"...
- Installing integrations/github v4.5.1...
- Installed integrations/github v4.5.1 (signed by a HashiCorp partner, key ID 38027F80D7FD5FB2)
$ terraform import github_branch_protection.some_repo 'MDEwOlJlcG9zaXRvcnkxMTE1NjgzNTQ=:master'
github_branch_protection.some_repo: Importing from ID "MDEwOlJlcG9zaXRvcnkxMTE1NjgzNTQ=:master"...

Error: nil entry in ImportState results. This is always a bug with
the resource that is being imported. Please report this as
a bug to Terraform.

@tibbes
Copy link
Contributor

tibbes commented Mar 8, 2021

@bateller, it looks like there is some missing error checking. Apologies.

I can reproduce that message, but only when the branch protection rule does not exist. I will open a pull request to fix that. Please can you verify that the master branch is actually protected on that repository?

@bateller
Copy link

bateller commented Mar 8, 2021

@tibbes Yes, I can confirm master didn't have branch protection.

Sorry about that (I didn't have Admin permission on the repo I was importing)

Tried on another repo within the same org (and with the same Terraform setup) with a repo I had Admin access on and imported branch protection for master successfully.

It appears this issue (and #597) are failing for me due to not checking if the imported resource exists on Github (which would be a nice check for those of us using Terraform to manage Github when we don't have direct Admin access)

@tibbes
Copy link
Contributor

tibbes commented Mar 8, 2021

I've opened #721 to fix the error message. Thanks for reporting.

kfcampbell pushed a commit to kfcampbell/terraform-provider-github that referenced this issue Jul 26, 2022
…rations#713)

* Add test for importing github_branch_protection

There was an existing test for importing by <repo-name>:<pattern>,
but not a test for <repo-node-id>:<pattern>.

* Fix importing github_branch_protection

Importing a branch protection rule by an ID of the form
<repo-node-id>:<pattern> was broken.

Closes: integrations#671
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good first issue Good for newcomers r/branch_protection Type: Bug Something isn't working as documented
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants