dikhan / terraform-provider-openapi

OpenAPI Terraform Provider that configures itself at runtime with the resources exposed by the service provider (defined in a swagger file)
Apache License 2.0
275 stars 48 forks source link

Allow configuring the openapi.ProviderOpenAPI struct with the service providers OpenAPI URL #299

Closed dikhan closed 3 years ago

dikhan commented 3 years ago

Is your feature request related to a problem?

As Service provider I want to use the OpenAPI Terraform provider as a library and be able to configure it directly through code. Currently the provider is only configurable either via environments variables or an external config file as described in Using the OpenAPI Terraform provider So that I can create my own custom terraform provider (powered by the OpenAPI Terraform library) and be able to register it with the Terraform Registry

Describe the solution you'd like

I would like to be able to create a openapi.ProviderOpenAPI{} struct passing in the providerName and the OpenAPIURL and have the provider returned a Terraform *schema.Provider that then I can use in my custom terraform provider but instead of writing an entire provider to my API I just delegate that responsibility to the OpenAPI Terraform provider and as a service provider I only need to take care of the API and its documentation and make sure it's compliant with the OpenAPI Terraform provider requirements.

Acceptance criteria

What's required to consider this feature request complete?

Example:

Scenario: The OpenAPI Terraform provider swagger url can be configured when creating the openapi.ProviderOpenAPI{} struct
Given a custom terraform provider 
When I import the OpenAPI Terraform library (import "github.com/dikhan/terraform-provider-openapi/v2/openapi") in my provider's main.go file
Then I should be able to configure the openapi.ProviderOpenAPI{} struct with the URL where the service provider openapi doc is hosted. 

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context or screenshots about the feature request here.

Checklist (for admin only)

Don't forget to go through the checklist to make sure the issue is created properly:

dikhan commented 3 years ago

This is already supported using the ProviderOpenAPI struct CreateSchemaProviderFromServiceConfiguration function which accepts any struct that implements the ServiceConfiguration interface such as the ServiceConfigV1 struct. Hence, closing this issue.