Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to target resources when running local-preview #268

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading