Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3136 from hashicorp/deprecate-env-vars
Browse files Browse the repository at this point in the history
Deprecate `-env-vars` flag in `runner profile set`, replace with `-env-var`
  • Loading branch information
xiaolin-ninja authored Mar 25, 2022
2 parents 924e571 + 087c999 commit d069b6b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .changelog/3136.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
cli: `runner profile set` deprecates the `-env-vars` flag in favor of the `-env-var` flag instead.
```
32 changes: 24 additions & 8 deletions internal/cli/runner_profile_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import (

type RunnerProfileSetCommand struct {
*baseCommand

//TODO(XX): after `-env-vars` as a slice is deprecated, rename flagEnvVar to flagEnvVars
flagName string
flagOCIUrl string
flagEnvVar map[string]string
flagEnvVars []string
flagPluginType string
flagPluginConfig string
Expand Down Expand Up @@ -175,11 +176,20 @@ func (c *RunnerProfileSetCommand) Run(args []string) int {
od.EnvironmentVariables = map[string]string{}
od.Default = c.flagDefault

for _, kv := range c.flagEnvVars {
idx := strings.IndexByte(kv, '=')
if idx != -1 {
od.EnvironmentVariables[kv[:idx]] = kv[idx+1:]
if c.flagEnvVars != nil {
//TODO(XX): Deprecate -env-vars and this logic
c.ui.Output(
"Flag '-env-vars' is deprecated, please use flag `-env-var=k=v`",
terminal.WithWarningStyle(),
)
for _, kv := range c.flagEnvVars {
idx := strings.IndexByte(kv, '=')
if idx != -1 {
od.EnvironmentVariables[kv[:idx]] = kv[idx+1:]
}
}
} else {
od.EnvironmentVariables = c.flagEnvVar
}

if c.flagPluginType == "" {
Expand All @@ -188,7 +198,6 @@ func (c *RunnerProfileSetCommand) Run(args []string) int {
c.Help(),
terminal.WithErrorStyle(),
)

return 1
}

Expand Down Expand Up @@ -234,11 +243,18 @@ func (c *RunnerProfileSetCommand) Flags() *flag.Sets {
Usage: "The url for the OCI image to launch for the on-demand runner.",
})

f.StringMapVar(&flag.StringMapVar{
Name: "env-var",
Target: &c.flagEnvVar,
Usage: "Environment variable to expose to the on-demand runner set in 'k=v' format. Typically used to " +
"introduce configuration for the plugins that the runner will execute. Can be specified multiple times.",
})

//TODO(XX): deprecate and remove this
f.StringSliceVar(&flag.StringSliceVar{
Name: "env-vars",
Target: &c.flagEnvVars,
Usage: "Environment variable to expose to the on-demand runner. Typically used to " +
"introduce configuration for the plugins that the runner will execute. Can be specified multiple times.",
Usage: "DEPRECATED. Please see `-env-var`.",
})

f.StringVar(&flag.StringVar{
Expand Down
3 changes: 2 additions & 1 deletion website/content/commands/runner-profile-set.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ lifecycle operation.

- `-name=<string>` - The name of an existing runner profile to update.
- `-oci-url=<string>` - The url for the OCI image to launch for the on-demand runner.
- `-env-vars=<string>` - Environment variable to expose to the on-demand runner. Typically used to introduce configuration for the plugins that the runner will execute. Can be specified multiple times.
- `-env-var=<key=value>` - Environment variable to expose to the on-demand runner set in 'k=v' format. Typically used to introduce configuration for the plugins that the runner will execute. Can be specified multiple times.
- `-env-vars=<string>` - DEPRECATED. Please see `-env-var`.
- `-plugin-type=<string>` - The type of the plugin to launch for the on-demand runner, such as aws-ecs, kubernetes, etc.
- `-plugin-config=<string>` - Path to an hcl file that contains the configuration for the plugin. This is only necessary when the plugin's defaults need to be adjusted for the environment the plugin will launch the on-demand runner in.
- `-default` - Indicates that this remote runner profile should be the default for any project that doesn't otherwise specify its own remote runner.
Expand Down

0 comments on commit d069b6b

Please sign in to comment.