As explained in pulumi/pulumi-fabric#293, we were a little ad-hoc in how configuration was "applied" to resource providers. In fact, config wasn't ever communicated directly to providers; instead, the resource providers would simply ask the engine to read random heap locations (via tokens). Now that we're on a plan where configuration gets handed to the program at startup, and that's that, and where generally speaking resource providers never communicate directly with the language runtime, we need to take a different approach. As such, the resource provider interface now offers a Configure RPC method that the resource planning engine will invoke at the right times with the right subset of configuration variables filtered to just that provider's package. This fixes pulumi/pulumi#293.
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
// Copyright 2017, Pulumi Corporation. All rights reserved.
|
|
|
|
package engine
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
"github.com/pulumi/pulumi-fabric/pkg/tokens"
|
|
)
|
|
|
|
func (eng *Engine) SetConfig(envName string, key tokens.ModuleMember, value string) error {
|
|
info, err := eng.initEnvCmdName(tokens.QName(envName), "")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
config := info.Target.Config
|
|
if config == nil {
|
|
config = make(map[tokens.ModuleMember]string)
|
|
info.Target.Config = config
|
|
}
|
|
|
|
config[key] = value
|
|
|
|
if err = eng.Environment.SaveEnvironment(info.Target, info.Snapshot); err != nil {
|
|
return errors.Wrap(err, "could not save configuration value")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// ReplaceConfig sets the config for an environment to match `newConfig` and then saves
|
|
// the environment. Note that config values that were present in the old environment but are
|
|
// not present in `newConfig` will be removed from the environment
|
|
func (eng *Engine) ReplaceConfig(envName string, newConfig map[tokens.ModuleMember]string) error {
|
|
info, err := eng.initEnvCmdName(tokens.QName(envName), "")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
config := make(map[tokens.ModuleMember]string)
|
|
for key, v := range newConfig {
|
|
config[key] = v
|
|
}
|
|
|
|
info.Target.Config = config
|
|
|
|
if err = eng.Environment.SaveEnvironment(info.Target, info.Snapshot); err != nil {
|
|
return errors.Wrap(err, "could not save configuration value")
|
|
}
|
|
|
|
return nil
|
|
}
|