-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathParameterStoreExecPlugin.groovy
46 lines (37 loc) · 1.56 KB
/
ParameterStoreExecPlugin.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import static TerraformEnvironmentStage.PLAN
import static TerraformEnvironmentStage.APPLY
class ParameterStoreExecPlugin implements TerraformEnvironmentStagePlugin, TerraformPlanCommandPlugin, TerraformApplyCommandPlugin {
public static void init() {
ParameterStoreExecPlugin plugin = new ParameterStoreExecPlugin()
TerraformEnvironmentStage.addPlugin(plugin)
TerraformPlanCommand.addPlugin(plugin)
TerraformApplyCommand.addPlugin(plugin)
}
@Override
public void apply(TerraformEnvironmentStage stage) {
def environment = stage.getEnvironment()
def parameterStorePath = pathForEnvironment(environment)
stage.decorate(PLAN, addEnvVariables(parameterStorePath))
stage.decorate(APPLY, addEnvVariables(parameterStorePath))
}
public String pathForEnvironment(String environment) {
String organization = Jenkinsfile.instance.getOrganization()
String repoName = Jenkinsfile.instance.getRepoName()
return "/${organization}/${repoName}/${environment}/"
}
public static Closure addEnvVariables(String path) {
return { closure ->
withEnv(["PARAMETER_STORE_EXEC_PATH=${path}", "PARAMETER_STORE_EXEC_DISABLE_TRANSLATION=true", "AWS_REGION=us-east-1"]) {
closure()
}
}
}
@Override
public void apply(TerraformPlanCommand command) {
command.withPrefix('parameter-store-exec')
}
@Override
public void apply(TerraformApplyCommand command) {
command.withPrefix('parameter-store-exec')
}
}