Skip to content

Conversation

@jantman
Copy link
Contributor

@jantman jantman commented Dec 11, 2020

This PR adds some more-granular decorators around the shell commands run in TerraformEnvironmentStage (init, plan, and apply). This provides an extension point for a future plugin to allow executing shell commands (hooks) before and/or after each of these commands.

Please note that I have not (yet?) added unit tests for this. As far as I can tell the current code does not have tests for anything in the closure, aside from it not blowing up, and I'm not entirely sure how to test this...

@kmanning
Copy link
Collaborator

kmanning commented Dec 11, 2020

Being able to inject behavior with Closures is delegated down to the StageDecoration class. And that behavior is exercised - https://github.com/manheim/terraform-pipeline/blob/master/test/StageDecorationsTest.groovy

Initially, the pipelineConfiguration methods were not tested at all, because that's the section that integrates with Jenkinsfile DSL. A method that integrates with a lot of external classes is difficult to test in a unit test. That said, since this library was initially published, a DummyJenkinsfile was since added, which now allows you to stub out and assert on DSL methods.

To directly answer your question about how to test this - we could try to spy the StageDecorations, and could assert that apply is called for the new points of code which can now be decorated. To me, this is feeling outside the bounds of a unit test, and feels like something that would be better tested through an integrated test (which doesn't currently exist)

@kmanning
Copy link
Collaborator

Thoughts on whether or not INIT_COMMAND for plan should be separate from INIT_COMMAND for apply?

@kmanning kmanning linked an issue Dec 11, 2020 that may be closed by this pull request
@kmanning kmanning added this to the v5.13 milestone Dec 11, 2020
@jantman
Copy link
Contributor Author

jantman commented Dec 11, 2020

Ok, that makes sense about testing. Thanks.

Thoughts on whether or not INIT_COMMAND for plan should be separate from INIT_COMMAND for apply?

Personally I don't think so. In fact, I think that specifically shouldn't be done, because it would make it easier to do the wrong thing, and have undesirable differences between the plan and the apply. By keeping the INIT_COMMAND the same across all init's, we make it easy to add in something that should be done everywhere terraform init is run.

@kmanning kmanning merged commit a3d6922 into manheim:master Dec 11, 2020
@kmanning
Copy link
Collaborator

Looks good, merging.

@jantman jantman deleted the issues/316 branch December 14, 2020 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow more granular decorations around terraform init/plan/apply

2 participants