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

Add support for the hahicorp mux library #121

Merged
merged 1 commit into from
Jul 12, 2024
Merged

Add support for the hahicorp mux library #121

merged 1 commit into from
Jul 12, 2024

Conversation

eamonnotoole
Copy link
Contributor

Hashicorp has a new "framework" for provider development that replaces SDK v2.0. We can combine "framework" provider code which can still be in separate repos with SDK v2.0 provider code using the Hashicorp "mux" library. In this PR we adapt the existing pkg/provider code to allow us to use "mux" with "legacy" provider code that uses the framework that we put together for SDK v2.0.

To do this instead of creating one combined provider instance we create separate provider instances one for each service. There are a couple of restrictions on providers that are passed to the mux library:

  • the ProviderSchema (i.e. the schema that determines the provider stanza) must be same for each sub-provider
  • you cannot repeat any data-source or resource definitions in any of the sub-providers

We've implemented a NewProviderMux function in pkg/provider which creates sub-providers that satisfy the above restrictions. The inputs to this function are the same as those to NewProviderFunc. SDK v2.0 provider repos that use the framework don't need any changes. However we will need to add registration.ServiceRegistration implementations for all new "framework" providers that implement just the ProviderSchemaEntry and pass those down to NewProviderMux.

@eamonnotoole eamonnotoole force-pushed the mux-support branch 2 times, most recently from 0afe368 to 183af6a Compare July 11, 2024 10:21
panic(fmt.Sprintf("resource name %s is repeated in service %s", k, service.Name()))
}
resources[k] = v
}
Copy link

@stuart-mclaren-hpe stuart-mclaren-hpe Jul 11, 2024

Choose a reason for hiding this comment

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

Are the two ranges' panic checks needed still? Previously dataSources/resources spanned multiple providers so they could clash, is a clash still possible?

Would it be possible to pass service.SupportedResources / service.SupportedDataSources straight to lines 77/78?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No and yes. I'll push-up the change.

Hashicorp has a new "framework" for provider development that replaces
SDK v2.0.  We can combine "framework" provider code which can still be
in separate repos with SDK v2.0 provider code using the Hashicorp "mux"
library.  In this PR we adapt the existing pkg/provider code to allow us
to use "mux" with "legacy" provider code that uses the framework that we
put together for SDK v2.0.

To do this instead of creating one combined provider instance we create
separate provider instances one for each service.  There are a couple of
restrictions on providers that are passed to the mux library:
- the ProviderSchema (i.e. the schema that determines the provider
  stanza) must be same for each sub-provider
- you cannot repeat any data-source or resource definitions in any of
  the sub-providers

We've implemented a NewProviderMux function in pkg/provider which
creates sub-providers that satisfy the above restrictions.  The inputs
to this function are the same as those to NewProviderFunc.  SDK v2.0
provider repos that use the framework don't need any changes.  However
we will need to add registration.ServiceRegistration implementations for
all new "framework" providers that implement just the
ProviderSchemaEntry and pass those down to NewProviderMux.

Signed-off-by: Eamonn O'Toole <[email protected]>
@eamonnotoole eamonnotoole merged commit b8c4e76 into main Jul 12, 2024
4 checks passed
@eamonnotoole eamonnotoole deleted the mux-support branch July 12, 2024 09:40
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.

2 participants