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

Migrate from SDKv2 => Framework #142

Merged
merged 14 commits into from Jul 1, 2022
Merged

Migrate from SDKv2 => Framework #142

merged 14 commits into from Jul 1, 2022

Conversation

bendbennett
Copy link
Contributor

@bendbennett bendbennett commented Jun 14, 2022

This PR contains breaking changes for:

Closes: #140
Closes: #114
Closes: #107
Closes: #93
Closes: #41

@bendbennett bendbennett added this to the v3.0.0 milestone Jun 14, 2022
@bendbennett bendbennett changed the title Migrating from SDKv2 => Framework Migrate from SDKv2 => Framework Jun 14, 2022
Copy link
Contributor

@detro detro left a comment

Choose a reason for hiding this comment

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

This is looking extremely good already. Just left some advices around declaring explicitly the interfaces you intend to implement, so the compiler can help you down the line.

"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
)

Copy link
Contributor

Choose a reason for hiding this comment

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

One thing that I picked up is to make sure I declare top of the file what interfaces each type is expected to implement.

For example, in the TLS FW PR I have this pretty much everywhere:

type (
	privateKeyResourceType struct{}
	privateKeyResource     struct{}
)

var (
	_ tfsdk.ResourceType = (*privateKeyResourceType)(nil)
	_ tfsdk.Resource     = (*privateKeyResource)(nil)
)

This ensures that a) all the interfaces are enforced at compile time b) notice that I'm forcing receivers to be pointers, to avoid any surprise down the line where a call to a mutating method, doesn't apply the change to the struct in the expected way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good shout. Have added in the relevant interface implementations.

func New() *schema.Provider {
return &schema.Provider{
Schema: map[string]*schema.Schema{},
type provider struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above here, about enforcing interfaces at compile time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@bendbennett bendbennett marked this pull request as ready for review June 28, 2022 13:16
@bendbennett bendbennett requested a review from a team as a code owner June 28, 2022 13:16
@bendbennett bendbennett requested a review from detro June 28, 2022 13:16
Comment on lines 11 to 13
"http": func() (tfprotov6.ProviderServer, error) {
return providerserver.NewProtocol6(New())(), nil
},
Copy link
Member

Choose a reason for hiding this comment

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

Drive-by question: Can this use providerserver.NewProtocol6WithError(New()) instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing! Done.

Copy link
Member

@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.

Looks good to me 🚀 Excellent work

@bendbennett bendbennett merged commit 0c64a2c into main Jul 1, 2022
@bendbennett bendbennett deleted the bendbennett/issues-93 branch July 1, 2022 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants