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

AWSParameterStore - Support Global Parameters #302

Merged
merged 16 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 13 additions & 0 deletions src/ParameterStoreBuildWrapperPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import static TerraformEnvironmentStage.APPLY

class ParameterStoreBuildWrapperPlugin implements TerraformEnvironmentStagePlugin {
private static globalPathPattern
private static ArrayList globalParameterOptions = []
private static defaultPathPattern = { options -> "/${options['organization']}/${options['repoName']}/${options['environment']}/" }

public static void init() {
Expand All @@ -14,6 +15,11 @@ class ParameterStoreBuildWrapperPlugin implements TerraformEnvironmentStagePlugi
return this
}

public static withGlobalParameter(String path, options=[]) {
globalParameterOptions << [path: path] + options
return this
}

@Override
public void apply(TerraformEnvironmentStage stage) {
def environment = stage.getEnvironment()
Expand All @@ -26,6 +32,11 @@ class ParameterStoreBuildWrapperPlugin implements TerraformEnvironmentStagePlugi

stage.decorate(PLAN, addParameterStoreBuildWrapper(options))
stage.decorate(APPLY, addParameterStoreBuildWrapper(options))

globalParameterOptions.each { gp ->
stage.decorate(PLAN, addParameterStoreBuildWrapper(gp))
stage.decorate(APPLY, addParameterStoreBuildWrapper(gp))
}
codezninja marked this conversation as resolved.
Show resolved Hide resolved
}

String pathForEnvironment(String environment) {
Expand All @@ -48,6 +59,7 @@ class ParameterStoreBuildWrapperPlugin implements TerraformEnvironmentStagePlugi
def parameterStoreOptions = defaultOptions + options

return { closure ->
// sh "echo ${parameterStoreOptions}" //DEBUG
codezninja marked this conversation as resolved.
Show resolved Hide resolved
withAWSParameterStore(parameterStoreOptions) {
closure()
}
Expand All @@ -56,5 +68,6 @@ class ParameterStoreBuildWrapperPlugin implements TerraformEnvironmentStagePlugi

public static reset() {
globalPathPattern = null
globalParameterOptions = []
}
}
14 changes: 14 additions & 0 deletions test/ParameterStoreBuildWrapperPluginTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,19 @@ class ParameterStoreBuildWrapperPluginTest {
assertEquals(ParameterStoreBuildWrapperPlugin.class, result)
}
}

class withGlobalParameter {
codezninja marked this conversation as resolved.
Show resolved Hide resolved
@After
public void reset() {
ParameterStoreBuildWrapperPlugin.reset()
}

@Test
void addsGlobalParameter() {
def result = ParameterStoreBuildWrapperPlugin.withGlobalParameter('/path/', [])

assertEquals(ParameterStoreBuildWrapperPlugin.class, result)
}
}
codezninja marked this conversation as resolved.
Show resolved Hide resolved
}