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

refactor: move device resource and datasource to separate package #574

Closed
wants to merge 1 commit into from

Conversation

ctreatma
Copy link
Contributor

@ctreatma ctreatma commented Feb 15, 2024

Part of #106

@ctreatma ctreatma force-pushed the metal-device-package branch 2 times, most recently from 845508e to ead5d20 Compare February 15, 2024 18:45
@codecov-commenter
Copy link

codecov-commenter commented Feb 15, 2024

Codecov Report

Attention: Patch coverage is 62.50000% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 41.67%. Comparing base (5173ee0) to head (24d9d96).

Files Patch % Lines
internal/resources/metal/device/resource.go 33.33% 6 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #574      +/-   ##
==========================================
- Coverage   41.80%   41.67%   -0.14%     
==========================================
  Files         102      103       +1     
  Lines       18533    18591      +58     
==========================================
  Hits         7747     7747              
- Misses      10580    10638      +58     
  Partials      206      206              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ctreatma ctreatma changed the title [WIP] move device resource and datasource to separate package refactor: move device resource and datasource to separate package Feb 15, 2024
@ctreatma ctreatma marked this pull request as ready for review February 15, 2024 20:10
@ctreatma ctreatma requested review from t0mk and a team as code owners February 15, 2024 20:10
Comment on lines -14 to +15
func dataSourceMetalDevices() *schema.Resource {
dsmd := dataSourceMetalDevice()
func ListDataSource() *schema.Resource {
dsmd := DataSource()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I opted to move the metal_devices data source into the same directory as the metal_device resource and datasource, because I think that's better than putting it in a separate internal/resources/metal/devices directory.

If that is agreed to be a good approach, then that raises the question: should metal_device_bgp_neighbors also go in this directory, or does it still go in a separate internal/resources/metal/device_bgp_neighbors directory?

Copy link
Member

@displague displague Feb 28, 2024

Choose a reason for hiding this comment

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

The pluralization of the resource names, as in multi-response datasources, was a subtle point that I missed on first glance of this comment.

The AWS provider followed this pattern. Seems fine to me.
https://github.com/hashicorp/terraform-provider-aws/blob/main/internal/service/ec2/ec2_instances_data_source.go

@@ -22,6 +23,10 @@ import (
"github.com/packethost/packngo"
)

var (
matchIPXEScript = regexp.MustCompile(`(?i)^#![i]?pxe`)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Chose to duplicate this matcher instead of finding a place to put it. IMO we can clean that up after framework and equinix-sdk-go migrations are done.

Copy link
Member

@displague displague Feb 22, 2024

Choose a reason for hiding this comment

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

I don't think the validation this enforces is necessary in the Terraform provider.

if matchIPXEScript.MatchString(params.UserData) {
return diag.Errorf("\"user_data\" should not be an iPXE " +
"script when \"ipxe_script_url\" is also provided.")
}

Perhaps this block would be better as a warning or left to the API to enforce. It's well enough to leave this validation alone since there are no known edge cases where the combination of an IPXE URL and a Custom IPXE Userdata are necessary.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps the regexp could be moved closer to where it is used since it is not used elsewhere.

return &schema.Resource{
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(30 * time.Minute),
Update: schema.DefaultTimeout(30 * time.Minute),
Delete: schema.DefaultTimeout(30 * time.Minute),
},
CreateContext: resourceMetalDeviceCreate,
ReadWithoutTimeout: resourceMetalDeviceRead,
ReadWithoutTimeout: Read,
Copy link
Member

@displague displague Feb 22, 2024

Choose a reason for hiding this comment

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

Why not ReadContext? (especially after #581)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ReadWithoutTimeout and ReadContext are both context-aware lifecycle methods: the first argument to the function specified for either of those hooks must be a context.Context. The difference between the two hooks is that ReadContext enforces a 20-minute default timeout that can be overridden in a timeout block and ReadWithoutTimeout doesn't enforce any timeout. When this is migrated to framework (probably in this PR at some point), we might be forced to revisit timeouts anyway since SDKv2 and framework model/implement them differently.

@displague
Copy link
Member

Should be rebased after #586

@displague
Copy link
Member

I'm curious what this looks like after a rebase (and again after #593 and perhaps other open general PRs); whether we've reached a point in refactoring where we can move all remaining metal resources to internal/resources/metal/* with little more than git mv, import list changes, and function exporting?

@ctreatma
Copy link
Contributor Author

Closing this for now; it can be reopened or reimplemented later if needed.

@ctreatma ctreatma closed this Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants