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 8 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
23 changes: 22 additions & 1 deletion src/ParameterStoreBuildWrapperPlugin.groovy
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
import static TerraformValidateStage.ALL
import static TerraformEnvironmentStage.PLAN
import static TerraformEnvironmentStage.APPLY

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

public static void init() {
TerraformEnvironmentStage.addPlugin(new ParameterStoreBuildWrapperPlugin())
TerraformValidateStage.addPlugin(new ParameterStoreBuildWrapperPlugin())
}

public static withPathPattern(Closure newPathPattern) {
globalPathPattern = newPathPattern
return this
}

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

@Override
public void apply(TerraformValidateStage stage) {
globalParameterOptions.each { gp ->
stage.decorate(ALL, addParameterStoreBuildWrapper(gp))
}
}

@Override
public void apply(TerraformEnvironmentStage stage) {
def environment = stage.getEnvironment()
Expand All @@ -26,6 +41,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 Down Expand Up @@ -56,5 +76,6 @@ class ParameterStoreBuildWrapperPlugin implements TerraformEnvironmentStagePlugi

public static reset() {
globalPathPattern = null
globalParameterOptions = []
}
}
74 changes: 74 additions & 0 deletions test/ParameterStoreBuildWrapperPluginTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ParameterStoreBuildWrapperPluginTest {
public class Init {
@After
void resetPlugins() {
TerraformValidateStage.resetPlugins()
TerraformEnvironmentStage.reset()
}

Expand All @@ -25,6 +26,46 @@ class ParameterStoreBuildWrapperPluginTest {
Collection actualPlugins = TerraformEnvironmentStage.getPlugins()
assertThat(actualPlugins, hasItem(instanceOf(ParameterStoreBuildWrapperPlugin.class)))
}

@Test
void modifiesTerraformEnvironmentStageCommandWithGlobalParameter() {
ParameterStoreBuildWrapperPlugin.withGlobalParameter('/somePath/').init()

Collection actualPlugins = TerraformEnvironmentStage.getPlugins()
assertThat(actualPlugins, hasItem(instanceOf(ParameterStoreBuildWrapperPlugin.class)))
}
codezninja marked this conversation as resolved.
Show resolved Hide resolved

@Test
void modifiesTerraformEnvironmentStageCommandWithGlobalParameterAndOptions() {
ParameterStoreBuildWrapperPlugin.withGlobalParameter('/somePath/', [someKey: true, anotherKey: 'someValue']).init()

Collection actualPlugins = TerraformEnvironmentStage.getPlugins()
assertThat(actualPlugins, hasItem(instanceOf(ParameterStoreBuildWrapperPlugin.class)))
}
codezninja marked this conversation as resolved.
Show resolved Hide resolved
kmanning marked this conversation as resolved.
Show resolved Hide resolved

@Test
void modifiesTerraformValidateStageCommand() {
ParameterStoreBuildWrapperPlugin.init()

Collection actualPlugins = TerraformValidateStage.getPlugins()
assertThat(actualPlugins, hasItem(instanceOf(ParameterStoreBuildWrapperPlugin.class)))
}

@Test
void modifiesTerraformValidateStageCommandWithGlobalParameter() {
ParameterStoreBuildWrapperPlugin.withGlobalParameter('/somePath/').init()

Collection actualPlugins = TerraformValidateStage.getPlugins()
assertThat(actualPlugins, hasItem(instanceOf(ParameterStoreBuildWrapperPlugin.class)))
}
codezninja marked this conversation as resolved.
Show resolved Hide resolved
codezninja marked this conversation as resolved.
Show resolved Hide resolved

@Test
void modifiesTerraformValidateStageCommandWithGlobalParameterAndOptions() {
ParameterStoreBuildWrapperPlugin.withGlobalParameter('/somePath/', [someKey: true, anotherKey: 'someValue']).init()

Collection actualPlugins = TerraformValidateStage.getPlugins()
assertThat(actualPlugins, hasItem(instanceOf(ParameterStoreBuildWrapperPlugin.class)))
}
codezninja marked this conversation as resolved.
Show resolved Hide resolved
codezninja marked this conversation as resolved.
Show resolved Hide resolved
}

public class PathForEnvironment {
Expand Down Expand Up @@ -84,5 +125,38 @@ 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 addGlobalParameter() {
def result = ParameterStoreBuildWrapperPlugin.withGlobalParameter('/path/', [])

assertEquals([[path: '/path/']], result.globalParameterOptions)
}
codezninja marked this conversation as resolved.
Show resolved Hide resolved

@Test
void addGlobalParameterWithOptions() {
def result = ParameterStoreBuildWrapperPlugin.withGlobalParameter('/path/', [recursive: true, basename: 'relative'])

assertEquals([[path: '/path/', recursive: true, basename: 'relative']], result.globalParameterOptions)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this test. It shows that you can call addGlobalParameters with or without options.


@Test
void addMulitpleGlobalParameters() {
ArrayList expected = []
def result = ParameterStoreBuildWrapperPlugin.withGlobalParameter('/path/', [])
.withGlobalParameter('/path2/', [recursive: true])
.withGlobalParameter('/path3/', [basename: 'something'])
expected << [path:'/path/']
expected << [path: '/path2/', recursive: true]
expected << [path: '/path3/', basename: 'something']
assertEquals(expected, result.globalParameterOptions)
}
}
codezninja marked this conversation as resolved.
Show resolved Hide resolved
}