Skip to content

Commit

Permalink
Allow to target resources when running local-preview (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasmik authored Nov 12, 2024
1 parent d3f47f1 commit 4bb59fe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/cmd/stack/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ var flagNoFindRepositoryRoot = &cli.BoolFlag{
Value: false,
}

var flagTarget = &cli.StringSliceFlag{
Name: "target",
Usage: "List of targets to use during local preview, read more here: https://spacelift.io/blog/terraform-target",
}

var flagProjectRootOnly = &cli.BoolFlag{
Name: "project-root-only",
Usage: "Indicate if spacelift should only package files inside this stacks project_root",
Expand Down
12 changes: 12 additions & 0 deletions internal/cmd/stack/local_preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ func localPreview() cli.ActionFunc {
return err
}

if got := cliCtx.StringSlice(flagTarget.Name); len(got) > 0 {
var val string
for _, v := range got {
val = strings.Join([]string{val, "-target=" + v}, " ")
}

envVars = append(envVars, EnvironmentVariable{
Key: "TF_CLI_ARGS_plan",
Value: graphql.String(strings.TrimSpace(val)),
})
}

stack, err := getStack(cliCtx)
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/stack/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func Command() *cli.Command {
flagOverrideEnvVarsTF,
flagDisregardGitignore,
flagPrioritizeRun,
flagTarget,
},
Action: localPreview(),
Before: authenticated.Ensure,
Expand Down

0 comments on commit 4bb59fe

Please sign in to comment.