[cli] Handle providers field for RegisterResourceRequest
Update the RegisterResource method in the ResourceMonitor
to unmarshal the providers field added in and then resolve
any provider references so that they can be set on the Construct call.
@@ -773,22 +773,26 @@ func (rm *resmon) RegisterResource(ctx context.Context,
label := fmt.Sprintf("ResourceMonitor.RegisterResource(%s,%s)", t, name)
var providerRef providers.Reference
+ var providerRefs map[string]string
+
if custom && !providers.IsProviderType(t) || remote {
- provider := req.GetProvider()
- if provider == "" {
providerReq, err := parseProviderRequest(t.Package(), req.GetVersion())
if err != nil {
return nil, err
}
- providerRef, err = rm.defaultProviders.getDefaultProviderRef(providerReq)
+
+ providerRef, err = getProviderReference(rm.defaultProviders, providerReq, req.GetProvider())
if err != nil {
return nil, err
}
- } else {
- providerRef, err = providers.ParseReference(provider)
+
+ providerRefs = make(map[string]string, len(req.GetProviders()))
+ for name, provider := range req.GetProviders() {
+ ref, err := getProviderReference(rm.defaultProviders, providerReq, provider)
if err != nil {
- return nil, errors.Errorf("could not parse provider reference '%v': %v", provider, err)
+ return nil, err
}
+ providerRefs[name] = ref.String()
}
}
@@ -872,9 +876,10 @@ func (rm *resmon) RegisterResource(ctx context.Context,
logging.V(5).Infof(
"ResourceMonitor.RegisterResource received: t=%v, name=%v, custom=%v, #props=%v, parent=%v, protect=%v, "+
- "provider=%v, deps=%v, deleteBeforeReplace=%v, ignoreChanges=%v, aliases=%v, customTimeouts=%v",
+ "provider=%v, deps=%v, deleteBeforeReplace=%v, ignoreChanges=%v, aliases=%v, customTimeouts=%v, "+
+ "providers=%v",
t, name, custom, len(props), parent, protect, providerRef, dependencies, deleteBeforeReplace, ignoreChanges,
- aliases, timeouts)
+ aliases, timeouts, providerRefs)
// If this is a remote component, fetch its provider and issue the construct call. Otherwise, register the resource.
var result *RegisterResult
@@ -890,6 +895,7 @@ func (rm *resmon) RegisterResource(ctx context.Context,
Aliases: aliases,
Protect: protect,
PropertyDependencies: propertyDependencies,
+ Providers: providerRefs,
}
constructResult, err := provider.Construct(rm.constructInfo, t, name, parent, props, options)
if err != nil {
