Skip to content

Massive refactor #237

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

Closed
wants to merge 4 commits into from
Closed

Massive refactor #237

wants to merge 4 commits into from

Conversation

paddycarver
Copy link
Contributor

A massive refactoring effort to:

and clean up a few other things along the way. It turns out when you start poking at one of these, the whole ball of yarn starts unraveling. Especially since this is an offshoot of the work I was doing in #52.

Try and make our provider serving code a little bit more atomic. A first
step, unfinished.
Refactor the reflect code, continue refactoring serving.
@paddycarver
Copy link
Contributor Author

Oh, also, this refactors Plan/Config/State to use new types, hopefully cutting down on the amount of code needed. I deleted the plan/state/config tests, but they'll be replaced with non-duplicated tests for the ReadOnlyData and *Data types. I largely lumped this in because the thought of updating those 10,000 lines of tests made me sad.

Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

Just leaving some drive-by notes while this is in draft. 👍 It'd be super helpful to understand the desired end state (of course a little difficult while prototyping 🙁 ) and which pieces we can potentially be split out to reduce design review burden.

Comment on lines +377 to +378
// Schema is the schema for the Attribute
AttributeSchema Attribute
Copy link
Contributor

Choose a reason for hiding this comment

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

Drive-by note: I believe ModifyAttributePlanRequest is also used during block plan modification.

return nil
}

func (d *Data) RemoveResource(ctx context.Context) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Drive-by note: In principle, these new "data" handling types feel appropriate to centralize the data logic of the Config/Plan/State handling. However, I'm not sure that we should necessarily get away from having Config, Plan, and State types. This RemoveResource method is a good example of something that should only be implemented with State and not Plan.

I'm wondering if Config, Plan, and State should still exist with encapsulating the underlying data types, e.g. briefly

type Config struct {
  ReadOnlyData
}

type Plan struct {
  *Data
}

type State struct {
  *Data
}

func (s State) RemoveResource(ctx context.Context) {/* ... */}

I'm also wondering if this particular change could be done outside the larger refactoring.

Comment on lines +10 to +11
// parseConfig turns a *tfprotov6.DynamicValue and a Schema into a Config.
func parseConfig(ctx context.Context, dv *tfprotov6.DynamicValue, schema Schema) (ReadOnlyData, diag.Diagnostics) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Drive-by nit: I'd be tempted to name this newReadOnlyData for clarity, unless its updated to return a Config (which I'd still opt for the new/New prefix).

"github.com/hashicorp/terraform-plugin-framework/diag"
)

func serveGetResourceType(ctx context.Context, provider Provider, typ string) (ResourceType, diag.Diagnostics) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Drive-by question: Is there a particular reason these aren't unexported methods on Provider? e.g.

func (p Provider) getResourceType(ctx context.Context, typ string) (ResourceType, diag.Diagnostics) {/* ... */}

)

// IsCreate returns true if the request is creating a resource.
func serveResourceApplyIsCreate(ctx context.Context, state *Data) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Drive-by question: Should this be functionality in terraform-plugin-go?

@hashicorp-cla
Copy link

hashicorp-cla commented Mar 12, 2022

CLA assistant check
All committers have signed the CLA.

@bflad
Copy link
Contributor

bflad commented Jun 22, 2022

There's been dozens of pull requests to accomplish even part of this. 😛 This has really served as a valuable reference for various ideas though, so thank you.

@bflad bflad closed this Jun 22, 2022
@bflad bflad deleted the paddy_massive_refactor branch June 22, 2022 19:11
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants