Skip to content

Commit 7354064

Browse files
committed
feat: auto plan when .terraform.lock.hcl changed
1 parent 773fb0c commit 7354064

File tree

6 files changed

+50
-44
lines changed

6 files changed

+50
-44
lines changed

server/core/config/parser_validator_test.go

+20-19
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/hashicorp/go-version"
1212
"github.com/runatlantis/atlantis/server/core/config"
13+
"github.com/runatlantis/atlantis/server/core/config/raw"
1314
"github.com/runatlantis/atlantis/server/core/config/valid"
1415
. "github.com/runatlantis/atlantis/testing"
1516
)
@@ -217,7 +218,7 @@ projects:
217218
WorkflowName: nil,
218219
TerraformVersion: nil,
219220
Autoplan: valid.Autoplan{
220-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
221+
WhenModified: raw.DefaultAutoPlanWhenModified,
221222
Enabled: true,
222223
},
223224
ApplyRequirements: nil,
@@ -240,7 +241,7 @@ projects:
240241
Dir: ".",
241242
Workspace: "default",
242243
Autoplan: valid.Autoplan{
243-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
244+
WhenModified: raw.DefaultAutoPlanWhenModified,
244245
Enabled: true,
245246
},
246247
},
@@ -286,7 +287,7 @@ projects:
286287
Dir: ".",
287288
Workspace: "default",
288289
Autoplan: valid.Autoplan{
289-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
290+
WhenModified: raw.DefaultAutoPlanWhenModified,
290291
Enabled: true,
291292
},
292293
},
@@ -309,7 +310,7 @@ workflows: ~
309310
Dir: ".",
310311
Workspace: "default",
311312
Autoplan: valid.Autoplan{
312-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
313+
WhenModified: raw.DefaultAutoPlanWhenModified,
313314
Enabled: true,
314315
},
315316
},
@@ -337,7 +338,7 @@ workflows:
337338
Dir: ".",
338339
Workspace: "default",
339340
Autoplan: valid.Autoplan{
340-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
341+
WhenModified: raw.DefaultAutoPlanWhenModified,
341342
Enabled: true,
342343
},
343344
},
@@ -368,7 +369,7 @@ workflows:
368369
WorkflowName: String("myworkflow"),
369370
TerraformVersion: tfVersion,
370371
Autoplan: valid.Autoplan{
371-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
372+
WhenModified: raw.DefaultAutoPlanWhenModified,
372373
Enabled: true,
373374
},
374375
ApplyRequirements: []string{"approved"},
@@ -402,7 +403,7 @@ workflows:
402403
WorkflowName: String("myworkflow"),
403404
TerraformVersion: tfVersion,
404405
Autoplan: valid.Autoplan{
405-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
406+
WhenModified: raw.DefaultAutoPlanWhenModified,
406407
Enabled: false,
407408
},
408409
ApplyRequirements: []string{"approved"},
@@ -436,7 +437,7 @@ workflows:
436437
WorkflowName: String("myworkflow"),
437438
TerraformVersion: tfVersion,
438439
Autoplan: valid.Autoplan{
439-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
440+
WhenModified: raw.DefaultAutoPlanWhenModified,
440441
Enabled: false,
441442
},
442443
ApplyRequirements: []string{"mergeable"},
@@ -470,7 +471,7 @@ workflows:
470471
WorkflowName: String("myworkflow"),
471472
TerraformVersion: tfVersion,
472473
Autoplan: valid.Autoplan{
473-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
474+
WhenModified: raw.DefaultAutoPlanWhenModified,
474475
Enabled: false,
475476
},
476477
ApplyRequirements: []string{"undiverged"},
@@ -504,7 +505,7 @@ workflows:
504505
WorkflowName: String("myworkflow"),
505506
TerraformVersion: tfVersion,
506507
Autoplan: valid.Autoplan{
507-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
508+
WhenModified: raw.DefaultAutoPlanWhenModified,
508509
Enabled: false,
509510
},
510511
ApplyRequirements: []string{"mergeable", "approved"},
@@ -538,7 +539,7 @@ workflows:
538539
WorkflowName: String("myworkflow"),
539540
TerraformVersion: tfVersion,
540541
Autoplan: valid.Autoplan{
541-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
542+
WhenModified: raw.DefaultAutoPlanWhenModified,
542543
Enabled: false,
543544
},
544545
ApplyRequirements: []string{"undiverged", "approved"},
@@ -572,7 +573,7 @@ workflows:
572573
WorkflowName: String("myworkflow"),
573574
TerraformVersion: tfVersion,
574575
Autoplan: valid.Autoplan{
575-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
576+
WhenModified: raw.DefaultAutoPlanWhenModified,
576577
Enabled: false,
577578
},
578579
ApplyRequirements: []string{"undiverged", "mergeable"},
@@ -606,7 +607,7 @@ workflows:
606607
WorkflowName: String("myworkflow"),
607608
TerraformVersion: tfVersion,
608609
Autoplan: valid.Autoplan{
609-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
610+
WhenModified: raw.DefaultAutoPlanWhenModified,
610611
Enabled: false,
611612
},
612613
ApplyRequirements: []string{"undiverged", "mergeable", "approved"},
@@ -716,7 +717,7 @@ projects:
716717
Dir: ".",
717718
Workspace: "workspace",
718719
Autoplan: valid.Autoplan{
719-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
720+
WhenModified: raw.DefaultAutoPlanWhenModified,
720721
Enabled: true,
721722
},
722723
},
@@ -725,7 +726,7 @@ projects:
725726
Dir: ".",
726727
Workspace: "workspace",
727728
Autoplan: valid.Autoplan{
728-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
729+
WhenModified: raw.DefaultAutoPlanWhenModified,
729730
Enabled: true,
730731
},
731732
},
@@ -767,7 +768,7 @@ workflows:
767768
Dir: ".",
768769
Workspace: "default",
769770
Autoplan: valid.Autoplan{
770-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
771+
WhenModified: raw.DefaultAutoPlanWhenModified,
771772
Enabled: true,
772773
},
773774
},
@@ -866,7 +867,7 @@ workflows:
866867
Dir: ".",
867868
Workspace: "default",
868869
Autoplan: valid.Autoplan{
869-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
870+
WhenModified: raw.DefaultAutoPlanWhenModified,
870871
Enabled: true,
871872
},
872873
},
@@ -957,7 +958,7 @@ workflows:
957958
Dir: ".",
958959
Workspace: "default",
959960
Autoplan: valid.Autoplan{
960-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
961+
WhenModified: raw.DefaultAutoPlanWhenModified,
961962
Enabled: true,
962963
},
963964
},
@@ -1050,7 +1051,7 @@ workflows:
10501051
Dir: ".",
10511052
Workspace: "default",
10521053
Autoplan: valid.Autoplan{
1053-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
1054+
WhenModified: raw.DefaultAutoPlanWhenModified,
10541055
Enabled: true,
10551056
},
10561057
},

server/core/config/raw/autoplan.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import (
66

77
// DefaultAutoPlanWhenModified is the default element in the when_modified
88
// list if none is defined.
9-
var DefaultAutoPlanWhenModified = []string{"**/*.tf*", "**/terragrunt.hcl"}
9+
var DefaultAutoPlanWhenModified = []string{
10+
"**/*.tf*",
11+
"**/terragrunt.hcl",
12+
"**/.terraform.lock.hcl",
13+
}
1014

1115
type Autoplan struct {
1216
WhenModified []string `yaml:"when_modified,omitempty"`

server/core/config/raw/autoplan_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func TestAutoplan_ToValid(t *testing.T) {
109109
input: raw.Autoplan{},
110110
exp: valid.Autoplan{
111111
Enabled: true,
112-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
112+
WhenModified: raw.DefaultAutoPlanWhenModified,
113113
},
114114
},
115115
{
@@ -129,7 +129,7 @@ func TestAutoplan_ToValid(t *testing.T) {
129129
},
130130
exp: valid.Autoplan{
131131
Enabled: false,
132-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
132+
WhenModified: raw.DefaultAutoPlanWhenModified,
133133
},
134134
},
135135
{
@@ -139,7 +139,7 @@ func TestAutoplan_ToValid(t *testing.T) {
139139
},
140140
exp: valid.Autoplan{
141141
Enabled: true,
142-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
142+
WhenModified: raw.DefaultAutoPlanWhenModified,
143143
},
144144
},
145145
}

server/core/config/raw/project_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ func TestProject_ToValid(t *testing.T) {
349349
WorkflowName: nil,
350350
TerraformVersion: nil,
351351
Autoplan: valid.Autoplan{
352-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
352+
WhenModified: raw.DefaultAutoPlanWhenModified,
353353
Enabled: true,
354354
},
355355
ApplyRequirements: nil,
@@ -396,7 +396,7 @@ func TestProject_ToValid(t *testing.T) {
396396
Workspace: "default",
397397
TerraformVersion: tfVersionPointEleven,
398398
Autoplan: valid.Autoplan{
399-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
399+
WhenModified: raw.DefaultAutoPlanWhenModified,
400400
Enabled: true,
401401
},
402402
},
@@ -411,7 +411,7 @@ func TestProject_ToValid(t *testing.T) {
411411
Dir: ".",
412412
Workspace: "default",
413413
Autoplan: valid.Autoplan{
414-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
414+
WhenModified: raw.DefaultAutoPlanWhenModified,
415415
Enabled: true,
416416
},
417417
},
@@ -425,7 +425,7 @@ func TestProject_ToValid(t *testing.T) {
425425
Dir: "a/b/c",
426426
Workspace: "default",
427427
Autoplan: valid.Autoplan{
428-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
428+
WhenModified: raw.DefaultAutoPlanWhenModified,
429429
Enabled: true,
430430
},
431431
},
@@ -439,7 +439,7 @@ func TestProject_ToValid(t *testing.T) {
439439
Dir: "mydir",
440440
Workspace: "default",
441441
Autoplan: valid.Autoplan{
442-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
442+
WhenModified: raw.DefaultAutoPlanWhenModified,
443443
Enabled: true,
444444
},
445445
},
@@ -454,7 +454,7 @@ func TestProject_ToValid(t *testing.T) {
454454
Dir: "mydir",
455455
Workspace: "default",
456456
Autoplan: valid.Autoplan{
457-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
457+
WhenModified: raw.DefaultAutoPlanWhenModified,
458458
Enabled: true,
459459
},
460460
},
@@ -468,7 +468,7 @@ func TestProject_ToValid(t *testing.T) {
468468
Dir: ".",
469469
Workspace: "default",
470470
Autoplan: valid.Autoplan{
471-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
471+
WhenModified: raw.DefaultAutoPlanWhenModified,
472472
Enabled: true,
473473
},
474474
},
@@ -482,7 +482,7 @@ func TestProject_ToValid(t *testing.T) {
482482
Dir: ".",
483483
Workspace: "default",
484484
Autoplan: valid.Autoplan{
485-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
485+
WhenModified: raw.DefaultAutoPlanWhenModified,
486486
Enabled: true,
487487
},
488488
},
@@ -496,7 +496,7 @@ func TestProject_ToValid(t *testing.T) {
496496
Dir: ".",
497497
Workspace: "default",
498498
Autoplan: valid.Autoplan{
499-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
499+
WhenModified: raw.DefaultAutoPlanWhenModified,
500500
Enabled: true,
501501
},
502502
},
@@ -512,7 +512,7 @@ func TestProject_ToValid(t *testing.T) {
512512
Dir: ".",
513513
Workspace: "default",
514514
Autoplan: valid.Autoplan{
515-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
515+
WhenModified: raw.DefaultAutoPlanWhenModified,
516516
Enabled: true,
517517
},
518518
},

server/core/config/raw/repo_cfg_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ func TestConfig_ToValid(t *testing.T) {
433433
Dir: "mydir",
434434
Workspace: "default",
435435
Autoplan: valid.Autoplan{
436-
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
436+
WhenModified: raw.DefaultAutoPlanWhenModified,
437437
Enabled: true,
438438
},
439439
},

0 commit comments

Comments
 (0)