Skip to content

Commit a3d6922

Browse files
authored
Merge pull request #317 from jantman/issues/316
Fixes #316 - implement more granular decorations in TerraformEnvironmentStage
2 parents 76239bb + 2f9d9d4 commit a3d6922

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Unreleased
22

33
* [Issue #311](https://github.com/manheim/terraform-pipeline/issues/311) Fix non-deterministic test failures
4+
* [Issue #316](https://github.com/manheim/terraform-pipeline/issues/316) Implement more granular decorations in TerraformEnvironmentStage.
45

56
# v5.12
67

docs/TerraformEnvironmentStage.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,10 @@ def deployProd = new TerraformEnvironmentStage('prod').withEnv('KEY_03', 'VALUE_
4141
validate.then(deployQA)
4242
.then(deployProd)
4343
.build()
44-
```
44+
```
45+
46+
### For Plugin Developers
47+
48+
#### Decorate Stages/Commands or Hook before/after command execution
49+
50+
TerraformEnvironmentStage has support for numerous decorators, to allow wrapping the various stages, steps, and individual commands. Please see the [source code](../src/TerraformEnvironmentStage.groovy) for details.

src/TerraformEnvironmentStage.groovy

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ class TerraformEnvironmentStage implements Stage, DecoratableStage {
99
private static Closure stageNamePattern
1010

1111
public static final String ALL = 'all'
12+
public static final String INIT_COMMAND = 'init-command'
1213
public static final String PLAN = 'plan'
14+
public static final String PLAN_COMMAND = 'plan-command'
1315
public static final String CONFIRM = 'confirm'
1416
public static final String APPLY = 'apply'
17+
public static final String APPLY_COMMAND = 'apply-command'
1518

1619
TerraformEnvironmentStage(String environment) {
1720
this.environment = environment
@@ -60,8 +63,12 @@ class TerraformEnvironmentStage implements Stage, DecoratableStage {
6063
decorations.apply(ALL) {
6164
stage(getStageNameFor(PLAN)) {
6265
decorations.apply(PLAN) {
63-
sh initCommand.toString()
64-
sh planCommand.toString()
66+
decorations.apply(INIT_COMMAND) {
67+
sh initCommand.toString()
68+
}
69+
decorations.apply(PLAN_COMMAND) {
70+
sh planCommand.toString()
71+
}
6572
}
6673
}
6774

@@ -78,8 +85,12 @@ class TerraformEnvironmentStage implements Stage, DecoratableStage {
7885
// The stage name needs to be editable
7986
stage(getStageNameFor(APPLY)) {
8087
decorations.apply(APPLY) {
81-
sh initCommand.toString()
82-
sh applyCommand.toString()
88+
decorations.apply(INIT_COMMAND) {
89+
sh initCommand.toString()
90+
}
91+
decorations.apply(APPLY_COMMAND) {
92+
sh applyCommand.toString()
93+
}
8394
}
8495
}
8596
}

0 commit comments

Comments
 (0)