Add provider configuration fetching to Configure since it will be a very common use case
This commit is contained in:
parent
322c453bdf
commit
d1b343faed
@ -12,6 +12,13 @@ import (
|
|||||||
// provider satisfies the tfsdk.Provider interface and usually is included
|
// provider satisfies the tfsdk.Provider interface and usually is included
|
||||||
// with all Resource and DataSource implementations.
|
// with all Resource and DataSource implementations.
|
||||||
type provider struct {
|
type provider struct {
|
||||||
|
// client can contain the upstream provider SDK or HTTP client used to
|
||||||
|
// communicate with the upstream service. Resource and DataSource
|
||||||
|
// implementations can then make calls using this client.
|
||||||
|
//
|
||||||
|
// TODO: If appropriate, implement upstream provider SDK or HTTP client.
|
||||||
|
// client vendorsdk.ExampleClient
|
||||||
|
|
||||||
// configured is set to true at the end of the Configure method.
|
// configured is set to true at the end of the Configure method.
|
||||||
// This can be used in Resource and DataSource implementations to verify
|
// This can be used in Resource and DataSource implementations to verify
|
||||||
// that the provider was previously configured.
|
// that the provider was previously configured.
|
||||||
@ -21,16 +28,25 @@ type provider struct {
|
|||||||
// provider is built and ran locally, and "test" when running acceptance
|
// provider is built and ran locally, and "test" when running acceptance
|
||||||
// testing.
|
// testing.
|
||||||
version string
|
version string
|
||||||
|
}
|
||||||
|
|
||||||
// client can contain the upstream provider SDK or HTTP client used to
|
// providerData can be used to store data from the Terraform configuration.
|
||||||
// communicate with the upstream service. Resource and DataSource
|
type providerData struct {
|
||||||
// implementations can then make calls using this client.
|
Example types.String `tfsdk:"example"`
|
||||||
//
|
|
||||||
// TODO: If appropriate, implement upstream provider SDK or HTTP client.
|
|
||||||
// client vendorsdk.ExampleClient
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *provider) Configure(ctx context.Context, req tfsdk.ConfigureProviderRequest, resp *tfsdk.ConfigureProviderResponse) {
|
func (p *provider) Configure(ctx context.Context, req tfsdk.ConfigureProviderRequest, resp *tfsdk.ConfigureProviderResponse) {
|
||||||
|
var data providerData
|
||||||
|
diags := req.Config.Get(ctx, &data)
|
||||||
|
resp.Diagnostics.Append(diags...)
|
||||||
|
|
||||||
|
if resp.Diagnostics.HasError() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configuration values are now available.
|
||||||
|
// if data.Example.Null { /* ... */ }
|
||||||
|
|
||||||
// If the upstream provider SDK or HTTP client requires configuration, such
|
// If the upstream provider SDK or HTTP client requires configuration, such
|
||||||
// as authentication or logging, this is a great opportunity to do so.
|
// as authentication or logging, this is a great opportunity to do so.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user