Skip to content

Commit a8171d4

Browse files
committed
Add additional_project_globs to stack
Signed-off-by: tomasmik <[email protected]>
1 parent 4961bcb commit a8171d4

File tree

9 files changed

+123
-88
lines changed

9 files changed

+123
-88
lines changed

docs/data-sources/stack.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ data "spacelift_stack" "k8s-core" {
2727

2828
### Optional
2929

30+
- `additional_project_globs` (Set of String) Project globs is an optional list of paths to track changes of in addition to the project root.
3031
- `after_apply` (List of String) List of after-apply scripts
3132
- `after_destroy` (List of String) List of after-destroy scripts
3233
- `after_init` (List of String) List of after-init scripts

docs/data-sources/stacks.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ Required:
127127

128128
Read-Only:
129129

130+
- `additional_project_globs` (Set of String)
130131
- `administrative` (Boolean)
131132
- `after_apply` (List of String)
132133
- `after_destroy` (List of String)

docs/resources/stack.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ resource "spacelift_stack" "ansible-stack" {
192192

193193
### Optional
194194

195+
- `additional_project_globs` (Set of String) Project globs is an optional list of paths to track changes of in addition to the project root.
195196
- `administrative` (Boolean) Indicates whether this stack can manage others. Defaults to `false`.
196197
- `after_apply` (List of String) List of after-apply scripts
197198
- `after_destroy` (List of String) List of after-destroy scripts

spacelift/data_stack.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ func dataStack() *schema.Resource {
285285
Description: "Project root is the optional directory relative to the workspace root containing the entrypoint to the Stack.",
286286
Computed: true,
287287
},
288+
"additional_project_globs": {
289+
Type: schema.TypeSet,
290+
Elem: &schema.Schema{Type: schema.TypeString},
291+
Optional: true,
292+
Description: "Project globs is an optional list of paths to track changes of in addition to the project root.",
293+
},
288294
"protect_from_deletion": {
289295
Type: schema.TypeBool,
290296
Description: "Protect this stack from accidental deletion. If set, attempts to delete this stack will fail.",
@@ -451,6 +457,12 @@ func dataStackRead(ctx context.Context, d *schema.ResourceData, meta interface{}
451457
}
452458
d.Set("labels", labels)
453459

460+
globs := schema.NewSet(schema.HashString, []interface{}{})
461+
for _, gb := range stack.AdditionalProjectGlobs {
462+
globs.Add(gb)
463+
}
464+
d.Set("additional_project_globs", globs)
465+
454466
if iacKey, iacSettings := stack.IaCSettings(); iacKey != "" {
455467
if err := d.Set(iacKey, []interface{}{iacSettings}); err != nil {
456468
return diag.Errorf("could not set IaC settings: %v", err)

spacelift/data_stack_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func TestStackData(t *testing.T) {
3636
labels = ["one", "two"]
3737
name = "Test stack %s"
3838
project_root = "root"
39+
additional_project_globs = ["/bacon", "/bacon/eggs/*"]
3940
repository = "demo"
4041
runner_image = "custom_image:runner"
4142
terraform_workspace = "bacon"
@@ -83,6 +84,7 @@ func TestStackData(t *testing.T) {
8384
SetEquals("labels", "one", "two"),
8485
Attribute("name", StartsWith("Test stack")),
8586
Attribute("project_root", Equals("root")),
87+
SetEquals("additional_project_globs", "/bacon", "/bacon/eggs/*"),
8688
Attribute("repository", Equals("demo")),
8789
Attribute("runner_image", Equals("custom_image:runner")),
8890
Attribute("terraform_workspace", Equals("bacon")),

spacelift/internal/structs/stack.go

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,42 @@ const StackConfigVendorKubernetes = "StackConfigVendorKubernetes"
2222

2323
// Stack represents the Stack data relevant to the provider.
2424
type Stack struct {
25-
ID string `graphql:"id"`
26-
Administrative bool `graphql:"administrative"`
27-
AfterApply []string `graphql:"afterApply"`
28-
AfterDestroy []string `graphql:"afterDestroy"`
29-
AfterInit []string `graphql:"afterInit"`
30-
AfterPerform []string `graphql:"afterPerform"`
31-
AfterPlan []string `graphql:"afterPlan"`
32-
AfterRun []string `graphql:"afterRun"`
33-
Autodeploy bool `graphql:"autodeploy"`
34-
Autoretry bool `graphql:"autoretry"`
35-
BeforeApply []string `graphql:"beforeApply"`
36-
BeforeDestroy []string `graphql:"beforeDestroy"`
37-
BeforeInit []string `graphql:"beforeInit"`
38-
BeforePerform []string `graphql:"beforePerform"`
39-
BeforePlan []string `graphql:"beforePlan"`
40-
Branch string `graphql:"branch"`
41-
Deleting bool `graphql:"deleting"`
42-
Description *string `graphql:"description"`
43-
IsDisabled bool `graphql:"isDisabled"`
44-
GitHubActionDeploy bool `graphql:"githubActionDeploy"`
45-
Integrations *Integrations `graphql:"integrations"`
46-
Labels []string `graphql:"labels"`
47-
LocalPreviewEnabled bool `graphql:"localPreviewEnabled"`
48-
ManagesStateFile bool `graphql:"managesStateFile"`
49-
Name string `graphql:"name"`
50-
Namespace string `graphql:"namespace"`
51-
ProjectRoot *string `graphql:"projectRoot"`
52-
ProtectFromDeletion bool `graphql:"protectFromDeletion"`
53-
Provider string `graphql:"provider"`
54-
Repository string `graphql:"repository"`
55-
RepositoryURL *string `graphql:"repositoryURL"`
56-
RunnerImage *string `graphql:"runnerImage"`
57-
Space string `graphql:"space"`
58-
TerraformVersion *string `graphql:"terraformVersion"`
59-
VendorConfig struct {
25+
ID string `graphql:"id"`
26+
Administrative bool `graphql:"administrative"`
27+
AfterApply []string `graphql:"afterApply"`
28+
AfterDestroy []string `graphql:"afterDestroy"`
29+
AfterInit []string `graphql:"afterInit"`
30+
AfterPerform []string `graphql:"afterPerform"`
31+
AfterPlan []string `graphql:"afterPlan"`
32+
AfterRun []string `graphql:"afterRun"`
33+
Autodeploy bool `graphql:"autodeploy"`
34+
Autoretry bool `graphql:"autoretry"`
35+
BeforeApply []string `graphql:"beforeApply"`
36+
BeforeDestroy []string `graphql:"beforeDestroy"`
37+
BeforeInit []string `graphql:"beforeInit"`
38+
BeforePerform []string `graphql:"beforePerform"`
39+
BeforePlan []string `graphql:"beforePlan"`
40+
Branch string `graphql:"branch"`
41+
Deleting bool `graphql:"deleting"`
42+
Description *string `graphql:"description"`
43+
IsDisabled bool `graphql:"isDisabled"`
44+
GitHubActionDeploy bool `graphql:"githubActionDeploy"`
45+
Integrations *Integrations `graphql:"integrations"`
46+
Labels []string `graphql:"labels"`
47+
LocalPreviewEnabled bool `graphql:"localPreviewEnabled"`
48+
ManagesStateFile bool `graphql:"managesStateFile"`
49+
Name string `graphql:"name"`
50+
Namespace string `graphql:"namespace"`
51+
ProjectRoot *string `graphql:"projectRoot"`
52+
AdditionalProjectGlobs []string `graphql:"additionalProjectGlobs"`
53+
ProtectFromDeletion bool `graphql:"protectFromDeletion"`
54+
Provider string `graphql:"provider"`
55+
Repository string `graphql:"repository"`
56+
RepositoryURL *string `graphql:"repositoryURL"`
57+
RunnerImage *string `graphql:"runnerImage"`
58+
Space string `graphql:"space"`
59+
TerraformVersion *string `graphql:"terraformVersion"`
60+
VendorConfig struct {
6061
Typename string `graphql:"__typename"`
6162
Ansible struct {
6263
Playbook string `graphql:"playbook"`

spacelift/internal/structs/stack_input.go

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,37 @@ import "github.com/shurcooL/graphql"
44

55
// StackInput represents the input required to create or update a Stack.
66
type StackInput struct {
7-
Administrative graphql.Boolean `json:"administrative"`
8-
AfterApply *[]graphql.String `json:"afterApply"`
9-
AfterDestroy *[]graphql.String `json:"afterDestroy"`
10-
AfterInit *[]graphql.String `json:"afterInit"`
11-
AfterPerform *[]graphql.String `json:"afterPerform"`
12-
AfterPlan *[]graphql.String `json:"afterPlan"`
13-
AfterRun *[]graphql.String `json:"afterRun"`
14-
Autodeploy graphql.Boolean `json:"autodeploy"`
15-
Autoretry graphql.Boolean `json:"autoretry"`
16-
BeforeApply *[]graphql.String `json:"beforeApply"`
17-
BeforeDestroy *[]graphql.String `json:"beforeDestroy"`
18-
BeforeInit *[]graphql.String `json:"beforeInit"`
19-
BeforePerform *[]graphql.String `json:"beforePerform"`
20-
BeforePlan *[]graphql.String `json:"beforePlan"`
21-
Branch graphql.String `json:"branch"`
22-
Description *graphql.String `json:"description"`
23-
GitHubActionDeploy graphql.Boolean `json:"githubActionDeploy"`
24-
Labels *[]graphql.String `json:"labels"`
25-
LocalPreviewEnabled graphql.Boolean `json:"localPreviewEnabled"`
26-
Name graphql.String `json:"name"`
27-
Namespace *graphql.String `json:"namespace"`
28-
ProjectRoot *graphql.String `json:"projectRoot"`
29-
ProtectFromDeletion graphql.Boolean `json:"protectFromDeletion"`
30-
Provider *graphql.String `json:"provider"`
31-
Repository graphql.String `json:"repository"`
32-
RepositoryURL *graphql.String `json:"repositoryURL"`
33-
RunnerImage *graphql.String `json:"runnerImage"`
34-
Space *graphql.String `json:"space"`
35-
VendorConfig *VendorConfigInput `json:"vendorConfig"`
36-
WorkerPool *graphql.ID `json:"workerPool"`
7+
Administrative graphql.Boolean `json:"administrative"`
8+
AfterApply *[]graphql.String `json:"afterApply"`
9+
AfterDestroy *[]graphql.String `json:"afterDestroy"`
10+
AfterInit *[]graphql.String `json:"afterInit"`
11+
AfterPerform *[]graphql.String `json:"afterPerform"`
12+
AfterPlan *[]graphql.String `json:"afterPlan"`
13+
AfterRun *[]graphql.String `json:"afterRun"`
14+
Autodeploy graphql.Boolean `json:"autodeploy"`
15+
Autoretry graphql.Boolean `json:"autoretry"`
16+
BeforeApply *[]graphql.String `json:"beforeApply"`
17+
BeforeDestroy *[]graphql.String `json:"beforeDestroy"`
18+
BeforeInit *[]graphql.String `json:"beforeInit"`
19+
BeforePerform *[]graphql.String `json:"beforePerform"`
20+
BeforePlan *[]graphql.String `json:"beforePlan"`
21+
Branch graphql.String `json:"branch"`
22+
Description *graphql.String `json:"description"`
23+
GitHubActionDeploy graphql.Boolean `json:"githubActionDeploy"`
24+
Labels *[]graphql.String `json:"labels"`
25+
LocalPreviewEnabled graphql.Boolean `json:"localPreviewEnabled"`
26+
Name graphql.String `json:"name"`
27+
Namespace *graphql.String `json:"namespace"`
28+
ProjectRoot *graphql.String `json:"projectRoot"`
29+
AddditionalProjectGlobs *[]graphql.String `json:"additionalProjectGlobs"`
30+
ProtectFromDeletion graphql.Boolean `json:"protectFromDeletion"`
31+
Provider *graphql.String `json:"provider"`
32+
Repository graphql.String `json:"repository"`
33+
RepositoryURL *graphql.String `json:"repositoryURL"`
34+
RunnerImage *graphql.String `json:"runnerImage"`
35+
Space *graphql.String `json:"space"`
36+
VendorConfig *VendorConfigInput `json:"vendorConfig"`
37+
WorkerPool *graphql.ID `json:"workerPool"`
3738
}
3839

3940
// VendorConfigInput represents vendor-specific configuration.

spacelift/resource_stack.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,12 @@ func resourceStack() *schema.Resource {
379379
Description: "Project root is the optional directory relative to the workspace root containing the entrypoint to the Stack.",
380380
Optional: true,
381381
},
382+
"additional_project_globs": {
383+
Type: schema.TypeSet,
384+
Elem: &schema.Schema{Type: schema.TypeString},
385+
Optional: true,
386+
Description: "Project globs is an optional list of paths to track changes of in addition to the project root.",
387+
},
382388
"protect_from_deletion": {
383389
Type: schema.TypeBool,
384390
Description: "Protect this stack from accidental deletion. If set, attempts to delete this stack will fail. Defaults to `false`.",
@@ -777,6 +783,14 @@ func stackInput(d *schema.ResourceData) structs.StackInput {
777783
ret.ProjectRoot = toOptionalString(projectRoot)
778784
}
779785

786+
if globsSet, ok := d.Get("additional_project_globs").(*schema.Set); ok {
787+
var gbs []graphql.String
788+
for _, gb := range globsSet.List() {
789+
gbs = append(gbs, graphql.String(gb.(string)))
790+
}
791+
ret.AddditionalProjectGlobs = &gbs
792+
}
793+
780794
if runnerImage, ok := d.GetOk("runner_image"); ok {
781795
ret.RunnerImage = toOptionalString(runnerImage)
782796
}

spacelift/resource_stack_test.go

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,30 @@ func TestStackResource(t *testing.T) {
2020
config := func(description string, protectFromDeletion bool) string {
2121
return fmt.Sprintf(`
2222
resource "spacelift_stack" "test" {
23-
administrative = true
24-
after_apply = ["ls -la", "rm -rf /"]
25-
after_destroy = ["echo 'after_destroy'"]
26-
after_init = ["terraform fmt -check", "tflint"]
27-
after_perform = ["echo 'after_perform'"]
28-
after_plan = ["echo 'after_plan'"]
29-
after_run = ["echo 'after_run'"]
30-
autodeploy = true
31-
autoretry = false
32-
before_apply = ["ls -la", "rm -rf /"]
33-
before_destroy = ["echo 'before_destroy'"]
34-
before_init = ["terraform fmt -check", "tflint"]
35-
before_perform = ["echo 'before_perform'"]
36-
before_plan = ["echo 'before_plan'"]
37-
branch = "master"
38-
description = "%s"
39-
import_state = "{}"
40-
labels = ["one", "two"]
41-
name = "Provider test stack %s"
42-
project_root = "root"
43-
protect_from_deletion = %t
44-
repository = "demo"
45-
runner_image = "custom_image:runner"
23+
administrative = true
24+
after_apply = ["ls -la", "rm -rf /"]
25+
after_destroy = ["echo 'after_destroy'"]
26+
after_init = ["terraform fmt -check", "tflint"]
27+
after_perform = ["echo 'after_perform'"]
28+
after_plan = ["echo 'after_plan'"]
29+
after_run = ["echo 'after_run'"]
30+
autodeploy = true
31+
autoretry = false
32+
before_apply = ["ls -la", "rm -rf /"]
33+
before_destroy = ["echo 'before_destroy'"]
34+
before_init = ["terraform fmt -check", "tflint"]
35+
before_perform = ["echo 'before_perform'"]
36+
before_plan = ["echo 'before_plan'"]
37+
branch = "master"
38+
description = "%s"
39+
import_state = "{}"
40+
labels = ["one", "two"]
41+
name = "Provider test stack %s"
42+
project_root = "root"
43+
additional_project_globs = ["/bacon", "/bacon/eggs/*"]
44+
protect_from_deletion = %t
45+
repository = "demo"
46+
runner_image = "custom_image:runner"
4647
}
4748
`, description, randomID, protectFromDeletion)
4849
}
@@ -90,6 +91,7 @@ func TestStackResource(t *testing.T) {
9091
SetEquals("labels", "one", "two"),
9192
Attribute("name", StartsWith("Provider test stack")),
9293
Attribute("project_root", Equals("root")),
94+
SetEquals("additional_project_globs", "/bacon", "/bacon/eggs/*"),
9395
Attribute("protect_from_deletion", Equals("true")),
9496
Attribute("repository", Equals("demo")),
9597
Attribute("runner_image", Equals("custom_image:runner")),

0 commit comments

Comments
 (0)