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

Adding support for Terraform Destroy. Adding ConfirmApply customization #251

Merged
merged 106 commits into from
Jul 24, 2020
Merged

Adding support for Terraform Destroy. Adding ConfirmApply customization #251

merged 106 commits into from
Jul 24, 2020

Conversation

jleopold28
Copy link
Contributor

@jleopold28 jleopold28 commented Jul 16, 2020

Support for TF destroy (#88)

Also adding support to customize the ConfirmApply messages. (#24)

src/ConditionalApplyPlugin.groovy Show resolved Hide resolved
src/ConfirmApplyPlugin.groovy Outdated Show resolved Hide resolved
src/TargetPlugin.groovy Outdated Show resolved Hide resolved
src/TerraformDestroyCommand.groovy Outdated Show resolved Hide resolved
src/TerraformDestroyStage.groovy Outdated Show resolved Hide resolved
src/TerraformEnvironmentStage.groovy Outdated Show resolved Hide resolved
@vincentclee
Copy link
Contributor

This is some great work @jleopold28 ! Thoughts on adding -refresh=false to the default options for destroy?

Common Scenario
hashicorp/terraform#15386 (comment)

@kmanning

@jleopold28
Copy link
Contributor Author

@vincentclee thanks for testing! I don't think -refresh=false should be a default option, but I am in favor of allowing it to be configured.

docs/DestroyPlugin.md Outdated Show resolved Hide resolved
@kmanning
Copy link
Collaborator

@vincentclee @jleopold28 ?

In regards to the -refresh=false, does anything need to be done from a code perspective? Would TerraformApply.withArgument('-refresh=false') work?

@kmanning
Copy link
Collaborator

Oh! I also finally published the new Contributor instructions. Let's do away with long-lived dev branches, and queue work in master instead. It's simpler that way. (Ie: you can make your PR against master, and I'll delete v5.9-dev - there's nothing in there at the moment). https://github.com/manheim/terraform-pipeline#how-to-contribute

@jleopold28 jleopold28 changed the base branch from v5.9-dev to master July 24, 2020 12:41
@jleopold28
Copy link
Contributor Author

@kmanning I updated the base to master. I also removed the section in the docs talking about "Destroy after Deploy". We can discuss that as a future piece of work.

@jleopold28
Copy link
Contributor Author

@vincentclee @jleopold28 ?

In regards to the -refresh=false, does anything need to be done from a code perspective? Would TerraformApply.withArgument('-refresh=false') work?

That would work. However, I don't think that should be the default behavior...

@kmanning
Copy link
Collaborator

You don't think "-refresh=false" should be the default behavior, or you don't think users should need to use .withArgument in order to get this to work?

@jleopold28
Copy link
Contributor Author

You don't think "-refresh=false" should be the default behavior, or you don't think users should need to use .withArgument in order to get this to work?

@kmanning I think users should have to use withArgument or something similar to add that option.

When doing a destroy, I think we should always refresh the state before executing a destroy. If users are hitting a bug that requires them to add refresh=false, they should specify that with arguments during the plugin init.

@@ -14,6 +12,7 @@ class TerraformEnvironmentStage implements Stage {
public static final String PLAN = 'plan'
public static final String CONFIRM = 'confirm'
public static final String APPLY = 'apply'
public static final String DESTROY = 'destroy'
Copy link
Collaborator

@kmanning kmanning Jul 24, 2020

Choose a reason for hiding this comment

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

This new state of TerraformEnvironmentStage.DESTROY. How will this behavior with the existing plugins that are part of the library (or worse, plugins that are in completely external libraries?)

eg:

  • public void apply(TerraformEnvironmentStage stage) {
    def environment = stage.getEnvironment()
    def parameterStorePath = pathForEnvironment(environment)
    stage.decorate(PLAN, addEnvVariables(parameterStorePath))
    stage.decorate(APPLY, addEnvVariables(parameterStorePath))
    }
  • public void apply(TerraformEnvironmentStage stage) {
    stage.decorate(PLAN, addColor())
    stage.decorate(APPLY, addColor())
    }
  • @Override
    public void apply(TerraformEnvironmentStage stage) {
    def environment = stage.getEnvironment()
    def parameterStorePath = pathForEnvironment(environment)
    def options = [
    path: parameterStorePath,
    credentialsId: "${environment.toUpperCase()}_PARAMETER_STORE_ACCESS"
    ]
    stage.decorate(PLAN, addParameterStoreBuildWrapper(options))
    stage.decorate(APPLY, addParameterStoreBuildWrapper(options))
    }
  • @Override
    public void apply(TerraformEnvironmentStage stage) {
    def environment = stage.getEnvironment()
    stage.decorate(TerraformEnvironmentStage.APPLY, addCrq(environment))
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kmanning I am making some changes now. I will have to add stage.decorate(DESTROY, someMethod(options)) to the above plugins. This will add functionality if DESTROY is enabled. Otherwise this will not change the existing functionality.

When using this plugin, your pipeline will look something like this:

![DestroyPluginPipeline](../images/destroy-pipeline.png)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice touch on the screenshot - thank you for that.

@kmanning
Copy link
Collaborator

kmanning commented Jul 24, 2020

Thanks for accounting for the other plugins. I'm still concerned about the maintainability of the existing PLAN/APPLY hooks, and I'm concerned about introducing more problems with the new DESTROY hook. But I think that can be tackled in a separate PR/refactor.

I'd like to track and tackle that refactor before the Destroy functionality gets released. #255

@kmanning
Copy link
Collaborator

:shipit:

@jleopold28 jleopold28 merged commit 88bff65 into manheim:master Jul 24, 2020
@jleopold28 jleopold28 deleted the tf_destroy branch July 24, 2020 18:53
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.

None yet

3 participants