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 push deploy keys #1009

Merged
merged 6 commits into from
Apr 24, 2022
Merged

Conversation

Shocktrooper
Copy link
Collaborator

Continuation of #608 that got stale

@Shocktrooper
Copy link
Collaborator Author

@timofurrer After looking at the initial proposed changes the only thing I can think that might need changing from a cursory check is to implement some of the things from #1008 but that is up to you if you want to proceed with the current code or have me do those changes.

@Shocktrooper
Copy link
Collaborator Author

@timofurrer I might have to rewrite part of this as the docs seem off to what the capabilities of the resource are on top of I had import failures when trying to implement things from #1008 . Also is there a reason to use a custom importer function for the deploy_key/deploy_key_enable resource vs just using schema.ImportStatePassthroughContext with a 2 part ID like in resource_gitlab_project_environment.go?

@timofurrer
Copy link
Member

@Shocktrooper I don't know what the initial reason to implement it like that was. What I can say is that we should whenever possible use the passthru importer - which would have been possible in this case. The reason for not changing it is to preserve backwards compatibility. (Which apparently has gone unnoticed for the slack resource, see #1012).

We could implement some logic to handle the break "gracefully", but since it's "only" a tech debt in this case I'd leave it as is and concentrate on other things and change it in the provider v4 :)

@pdecat
Copy link
Contributor

pdecat commented Apr 5, 2022

The reason for not changing it is to preserve backwards compatibility. (Which apparently has gone unnoticed for the slack resource, see #1012).

I found a way to maintain backward compatibility when changing IDs, see #1013

@Shocktrooper
Copy link
Collaborator Author

@timofurrer & @pdecat & @armsnyder Is there a preferred ID we are going with going forward for integrations or even generally? Are we going straight for the project Id as also the integration ID or a 2 part ID like projectId:integrationId

@timofurrer
Copy link
Member

Well, since we want to use the passthru importer the id must contain all necessary information to read the resource at minimum. Sometimes more information is valuable (can't point to any example since my connectivity is very limited ...)

@github-actions github-actions bot added size/L and removed size/M labels Apr 11, 2022
@Shocktrooper
Copy link
Collaborator Author

@timofurrer and @pdecat I was looking at the resource and it looks a bit janky to me as I do not see a need for a custom import at all. Form what I can tell we can use the passthru importer without any changes to the ID because it contains all the necessary information already and does not need to be changed. Can I remove the custom importer functions or am I missing something?

@Shocktrooper Shocktrooper marked this pull request as ready for review April 11, 2022 04:12
@Shocktrooper
Copy link
Collaborator Author

Also if it seems appropriate whomever reviews this please add it to the v3.14.0 milestone

@timofurrer
Copy link
Member

@timofurrer and @pdecat I was looking at the resource and it looks a bit janky to me as I do not see a need for a custom import at all. Form what I can tell we can use the passthru importer without any changes to the ID because it contains all the necessary information already and does not need to be changed. Can I remove the custom importer functions or am I missing something?

The currently used resource id only contains the deploy key id, but you need the project id, too. Thus, without breaking the id (or using some migration strategy) it's not possible to use the passthru importer ...

@Shocktrooper
Copy link
Collaborator Author

@timofurrer I made some refactors to move the deploy token to a 2 part ID which is consistent with how the resource is imported. One thing I want to test and not sure how to do it so I am open to suggestions is to make an acceptance test for testing the ID migration path where someone might have had a 1 part legacy ID, then the next terraform run migrates that to the 2 part ID.

@timofurrer
Copy link
Member

I've played around a bit and turns out it's actually possible to use state migrations for resource ids 😮 I've submitted a draft PR of my scratch:

Unless I'm missing something IMHO this should be the way to go - also for the slack integration resource we've done this ...

WDYT?

cc @armsnyder

@timofurrer
Copy link
Member

However, I'm still not a fan of changing the id without releasing a new major.

It's also against the terraform provider development best practices, see: https://www.terraform.io/plugin/sdkv2/best-practices/versioning#:~:text=Changing%20resource%20import,resource%20ID%20format

IMHO: this should be part of the v4 milestone ...

@Shocktrooper
Copy link
Collaborator Author

@timofurrer Alright I can revert it and we can wait till v4

@timofurrer
Copy link
Member

Yes, I suggest to focus here on the can_push attribute and do the id change later.

@Shocktrooper
Copy link
Collaborator Author

@timofurrer I reverted the deploy key id changes but left the changes I made to deploy key enable id because that already had a 2 part id but instead of using the passthrough importer it had a custom importer that I believe was not necessary. Let me know what you think

@timofurrer timofurrer self-requested a review April 20, 2022 15:32
@Shocktrooper Shocktrooper requested a review from timofurrer April 20, 2022 22:28
…ing project namespaces (+7 squashed commit)

Squashed commit:

[3e3f44e] Fixed capitalization on an acceptance test and remove the project attribute check on deploy key enable tests

[a0db074] Fixing up string conversion, fixing a lint error, refactoring the check destroy function for deploy key enable resource, fixing up check destroy in deploy key enable test

[153342e] Reverting deploy key id to original + refactoring deploy key enable a tad

[3f62ca1] Linter fixes I missed

[50c408c] Linter Fixes

[db9de1a] refactoring deploy key resources to remove the custom importers

[db6ebdb] Refactored Deploy Keys acceptance tests and made logging more helpful
@Shocktrooper Shocktrooper force-pushed the can-push-deploy-keys branch from 4d27cf5 to febeaf4 Compare April 24, 2022 14:17
Copy link
Member

@timofurrer timofurrer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

@timofurrer timofurrer merged commit 61d908e into gitlabhq:main Apr 24, 2022
@timofurrer timofurrer added this to the v3.14.0 milestone Apr 24, 2022
@Shocktrooper Shocktrooper deleted the can-push-deploy-keys branch April 24, 2022 15:12
@github-actions
Copy link

github-actions bot commented May 2, 2022

This functionality has been released in v3.14.0 of the Terraform GitLab Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue. Thank you!

@github-actions github-actions bot locked and limited conversation to collaborators Nov 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

4 participants