MCPcopy
hub / github.com/opentofu/opentofu / NewConfiguredProvider

Method NewConfiguredProvider

internal/plugins/provider.go:153–205  ·  view source on GitHub ↗
(ctx context.Context, addr addrs.Provider, configVal cty.Value)

Source from the content-addressed store, hash-verified

151}
152
153func (p *providerManager) NewConfiguredProvider(ctx context.Context, addr addrs.Provider, configVal cty.Value) (providers.Configured, tfdiags.Diagnostics) {
154 var diags tfdiags.Diagnostics
155
156 p.instancesLock.Lock()
157 defer p.instancesLock.Unlock()
158 if p.isShutdown.Load() {
159 return nil, diags.Append(fmt.Errorf("bug: unable to start provider %s, manager is shutdown", addr))
160 }
161
162 provider, err := p.providerFactories.NewInstance(addr)
163 if err != nil {
164 return nil, diags.Append(err)
165 }
166
167 p.instances = append(p.instances, provider)
168
169 // If our config value contains any marked values, ensure those are
170 // stripped out before sending this to the provider
171 unmarkedConfigVal, _ := configVal.UnmarkDeep()
172
173 // Allow the provider to validate and insert any defaults into the full
174 // configuration.
175 req := providers.ValidateProviderConfigRequest{
176 Config: unmarkedConfigVal,
177 }
178
179 // ValidateProviderConfig is only used for validation. We are intentionally
180 // ignoring the PreparedConfig field to maintain existing behavior.
181 validateResp := provider.ValidateProviderConfig(ctx, req)
182 diags = diags.Append(validateResp.Diagnostics)
183 if diags.HasErrors() {
184 return nil, diags
185 }
186
187 // If the provider returns something different, log a warning to help
188 // indicate to provider developers that the value is not used.
189 preparedCfg := validateResp.PreparedConfig
190 if preparedCfg != cty.NilVal && !preparedCfg.IsNull() && !preparedCfg.RawEquals(unmarkedConfigVal) {
191 log.Printf("[WARN] ValidateProviderConfig from %q changed the config value, but that value is unused", addr)
192 }
193
194 configResp := provider.ConfigureProvider(ctx, providers.ConfigureProviderRequest{
195 // We aren't actually Terraform, so we'll just pretend to be a
196 // Terraform version that has roughly the same functionality that
197 // OpenTofu currently has, since providers are permitted to use this to
198 // adapt their behavior for older versions of Terraform.
199 TerraformVersion: version.VersionToImpersonateForProviders,
200 Config: unmarkedConfigVal,
201 })
202 diags = diags.Append(configResp.Diagnostics)
203
204 return provider, diags
205}
206
207func (p *providerManager) StopAll(ctx context.Context) error {
208 p.instancesLock.Lock()

Callers

nothing calls this directly

Calls 8

AppendMethod · 0.95
HasErrorsMethod · 0.95
PrintfMethod · 0.80
LockMethod · 0.65
UnlockMethod · 0.65
ConfigureProviderMethod · 0.65
NewInstanceMethod · 0.45

Tested by

no test coverage detected