feat(autoapi): expose EnvVars LocalWorkspaceOption to set in ctor
This commit is contained in:
parent
9d5a4d742a
commit
08c8848375
|
@ -6,6 +6,9 @@ _(none)_
|
|||
|
||||
## 2.11.2 (2020-10-01)
|
||||
|
||||
- feat(autoapi): expose EnvVars LocalWorkspaceOption to set in ctor
|
||||
[#5499](https://github.com/pulumi/pulumi/pull/5499)
|
||||
|
||||
- [sdk/python] Fix secret regression: ensure unwrapped secrets during deserialization
|
||||
are rewrapped before being returned.
|
||||
[#5496](https://github.com/pulumi/pulumi/pull/5496)
|
||||
|
|
|
@ -389,7 +389,12 @@ func ExampleLocalWorkspace_secretsProvider() {
|
|||
// workspace and the stacks created from it. Supported secrets providers are:
|
||||
// `awskms`, `azurekeyvault`, `gcpkms`, `hashivault` and `passphrase`
|
||||
secretsProvider := SecretsProvider("awskms://alias/mysecretkeyalias")
|
||||
_, _ = NewLocalWorkspace(ctx, wd, ph, proj, secretsProvider)
|
||||
// EnvVars is a map of environment values scoped to the workspace.
|
||||
// These values will be passed to all Workspace and Stack level commands.
|
||||
envvars := EnvVars(map[string]string{
|
||||
"PULUMI_CONFIG_PASSPHRASE": "password",
|
||||
})
|
||||
_, _ = NewLocalWorkspace(ctx, wd, ph, proj, secretsProvider, envvars)
|
||||
}
|
||||
|
||||
func ExampleLocalWorkspace_ListPlugins() {
|
||||
|
|
|
@ -253,6 +253,10 @@ func (l *LocalWorkspace) GetEnvVars() map[string]string {
|
|||
// SetEnvVars sets the specified map of environment values scoped to the current workspace.
|
||||
// These values will be passed to all Workspace and Stack level commands.
|
||||
func (l *LocalWorkspace) SetEnvVars(envvars map[string]string) error {
|
||||
return setEnvVars(l, envvars)
|
||||
}
|
||||
|
||||
func setEnvVars(l *LocalWorkspace, envvars map[string]string) error {
|
||||
if envvars == nil {
|
||||
return errors.New("unable to set nil environment values")
|
||||
}
|
||||
|
@ -555,6 +559,13 @@ func NewLocalWorkspace(ctx context.Context, opts ...LocalWorkspaceOption) (Works
|
|||
l.secretsProvider = lwOpts.SecretsProvider
|
||||
}
|
||||
|
||||
// Environment values
|
||||
if lwOpts.EnvVars != nil {
|
||||
if err := setEnvVars(l, lwOpts.EnvVars); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to set environment values")
|
||||
}
|
||||
}
|
||||
|
||||
return l, nil
|
||||
}
|
||||
|
||||
|
@ -576,6 +587,9 @@ type localWorkspaceOptions struct {
|
|||
Repo *GitRepo
|
||||
// Secrets Provider to use with the current Stack
|
||||
SecretsProvider string
|
||||
// EnvVars is a map of environment values scoped to the workspace.
|
||||
// These values will be passed to all Workspace and Stack level commands.
|
||||
EnvVars map[string]string
|
||||
}
|
||||
|
||||
// LocalWorkspaceOption is used to customize and configure a LocalWorkspace at initialization time.
|
||||
|
@ -682,6 +696,14 @@ func SecretsProvider(secretsProvider string) LocalWorkspaceOption {
|
|||
})
|
||||
}
|
||||
|
||||
// EnvVars is a map of environment values scoped to the workspace.
|
||||
// These values will be passed to all Workspace and Stack level commands.
|
||||
func EnvVars(envvars map[string]string) LocalWorkspaceOption {
|
||||
return localWorkspaceOption(func(lo *localWorkspaceOptions) {
|
||||
lo.EnvVars = envvars
|
||||
})
|
||||
}
|
||||
|
||||
// NewStackLocalSource creates a Stack backed by a LocalWorkspace created on behalf of the user,
|
||||
// from the specified WorkDir. This Workspace will pick up
|
||||
// any available Settings files (Pulumi.yaml, Pulumi.<stack>.yaml).
|
||||
|
|
|
@ -45,10 +45,12 @@ func TestWorkspaceSecretsProvider(t *testing.T) {
|
|||
sName := fmt.Sprintf("int_test%d", rangeIn(10000000, 99999999))
|
||||
stackName := FullyQualifiedStackName(pulumiOrg, pName, sName)
|
||||
|
||||
// We can't use Workspace EnvVars as the Workspace uses the secrets provider to
|
||||
// create the Stack
|
||||
err := os.Setenv("PULUMI_CONFIG_PASSPHRASE", "password")
|
||||
assert.Nil(t, err, "failed to set EnvVar.")
|
||||
opts := []LocalWorkspaceOption{
|
||||
SecretsProvider("passphrase"),
|
||||
EnvVars(map[string]string{
|
||||
"PULUMI_CONFIG_PASSPHRASE": "password",
|
||||
}),
|
||||
}
|
||||
|
||||
// initialize
|
||||
s, err := NewStackInlineSource(ctx, stackName, pName, func(ctx *pulumi.Context) error {
|
||||
|
@ -57,7 +59,7 @@ func TestWorkspaceSecretsProvider(t *testing.T) {
|
|||
ctx.Export("exp_cfg", pulumi.String(c.Get("bar")))
|
||||
ctx.Export("exp_secret", c.GetSecret("buzz"))
|
||||
return nil
|
||||
}, SecretsProvider("passphrase"))
|
||||
}, opts...)
|
||||
if err != nil {
|
||||
t.Errorf("failed to initialize stack, err: %v", err)
|
||||
t.FailNow()
|
||||
|
|
Loading…
Reference in a new issue