-
Notifications
You must be signed in to change notification settings - Fork 47
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
refactor: Moving utility code to internal/
#420
Conversation
@@ -1,4 +1,4 @@ | |||
package equinix | |||
package internal |
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.
I wouldn't categorize resource specific schema mapping helpers as utility code. I think we should attempt to migrate these types of functions with the schemas, resources, and datasources.
internal/fabric/{resourcename}/{resource,datasource,schema}.go
Utility code prime for this refactor would be generic and suite many resources. These should be split into packages specific to the type of data that it manipulates, algorithms it provides, or protocols it communicates in.
https://go.dev/blog/package-names
I don't believe we'll benefit from a singular internal
package anymore than a singular equinix
package (beyond making not sharing the exports globally: https://go.dev/doc/go1.4#internalpackages)
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.
Looking at the AWS structure (which is not adapted to Framework), we see they chose the paths: internal/service/foo/: https://github.com/hashicorp/terraform-provider-aws/tree/main/internal/service/ec2/ec2_instance.go
Linode took another approach. they didn't use internal/
and they didn't create namespaces for the resources: https://github.com/linode/terraform-provider-linode/tree/dev/linode/instance
In my old PR, I went weith internal/resources/{service:metal}/{resource:device}/resource.go
Namespaces (metal, fabric, ne) will be important for how we collaborate with peer teams on these resources.
We'll also want per resource directories/packages -- https://developer.hashicorp.com/terraform/plugin/framework-benefits#separate-packages-for-each-type
We'll also want to use internal/
to keep the resources from becoming the dependency of other projects.
Notably, the equinix/Provider can be exported since its Go signature remains consistent and doesn't break compatibility. This package has been a dependency for Crossplane and was previously relied upon by Pulumi before Pulumi transitioned to a git submodule pattern.
8bc528f
to
eeed008
Compare
internal/
internal/
To move code for resource
Then I wanted to run tests in the subdir I found out yesterday (after 6 years of Golang programming) that it's possible to have packages There is a lot of shared functionality for acceptance tests, and that utility code can't live in I had a feedback from @ctreatma not to touch the We do all this in order to migrate to framework plugin eventually [0]. Let's discuss the format! I will keep this up to date (rebasing) with main. [0] #406 (comment) |
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.
We have a big ball of mud right now, so it probably won't be possible to avoid touching NE / Fabric stuff at all during the refactor. So far, this looks targeted enough in terms of those changes; I did comment on a couple places where the changes aren't strictly needed for refactoring.
We should add more package isolation as part of this refactor so that we don't end up with a new ball of mud in a different directory: config in a config
package, errors in an error
package, etc..
fc0074d
to
065f50e
Compare
@ctreatma thanks for your review. I went through There's
Not sure if we have any need or |
a1dd3f7
to
ac90fb0
Compare
@@ -1,4 +1,4 @@ | |||
package equinix | |||
package metal_project_ssh_key_test |
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 isolate some of these changes and introduce them one at a time in separate PRs: internal/config, internal/errors etc (in #142 there was some suggestion in the packages proposed on how to reorganize these helpers) Then we can move the resources around - again separate PRs, first with Metal, then NE, then Fabric. From there it may be easy to convert a single resource to Framework and continue from there. |
ac90fb0
to
5054745
Compare
@t0mk when you have a moment, could you rebase this PR on the latest from |
Closing this since we are breaking the PR up into smaller pieces |
7300b22
to
d8b8506
Compare
@@ -0,0 +1,28 @@ | |||
package internal |
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.
It looks like the functions in this file aren't used by anything related to the Metal SSH key refactor; we should still break this change out into a separate refactor, but if it's not necessary for the Metal SSH key refactor, we can remove these changes from the PR now with no impact.
@@ -1,4 +1,4 @@ | |||
package equinix | |||
package internal |
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.
This move also seems to not impact the SSH key refactor and could be removed from this PR without waiting for a separate mutexkv refactor PR to be merged.
d8b8506
to
831b48a
Compare
@@ -1,4 +1,4 @@ | |||
package equinix | |||
package internal |
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.
This one also seems to not be needed to support the SSH key changes
@@ -28,11 +28,6 @@ import ( | |||
xoauth2 "golang.org/x/oauth2" | |||
) | |||
|
|||
var ( | |||
UuidRE = regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$") |
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.
This, too, looks like it's not technically required in order to move the Metal SSH key code.
Closing again since the resources affected here were covered in #479 and the unrelated refactorings will be covered in separate PRs. |
Fixes #106