pulumi/pkg/engine/config_set.go
Matt Ellis d29f6fc4e5 Use tokens.QName instead of string as the type for environment
Internally, the engine deals with tokens.QName and not raw
strings. Push that up to the API boundary
2017-10-02 15:14:55 -07:00

52 lines
1.4 KiB
Go

// Copyright 2017, Pulumi Corporation. All rights reserved.
package engine
import (
"github.com/pkg/errors"
"github.com/pulumi/pulumi/pkg/tokens"
)
func (eng *Engine) SetConfig(envName tokens.QName, key tokens.ModuleMember, value string) error {
info, err := eng.initEnvCmdName(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 tokens.QName, newConfig map[tokens.ModuleMember]string) error {
info, err := eng.initEnvCmdName(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
}