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

Provide a hook for arbitrary scripts after 'apply' #250

Closed
kmanning opened this issue Jul 16, 2020 · 5 comments · Fixed by #319
Closed

Provide a hook for arbitrary scripts after 'apply' #250

kmanning opened this issue Jul 16, 2020 · 5 comments · Fixed by #319
Labels
enhancement New feature or request
Milestone

Comments

@kmanning
Copy link
Collaborator

kmanning commented Jul 16, 2020

UseCase: Healthcheck

  • I've deployed infrastructure to an environment, using terraform-pipeline
  • I want to confirm that the infrastructure "works as expected"
  • If I had a "hook" that allowed me to run an arbitrary shell script, my shell script could validate the my infrastructure "works as expected"
  • If my shell script returns a zero-status, I assume "it works" (based on unix return code conventions)
  • If my shell script returns a non-zero status, I assume that "it did not work as expected", and marks the "apply" stage of my environment as failed. I'm not allowed to continue.
  • My shell script should get all the "goodness" of pipelines that operate during "apply". Eg: I can access the IAM role and EnvironmentVariables provided by plugins like ParameterStorePlugin.
@kmanning kmanning added the enhancement New feature or request label Jul 16, 2020
@kmanning kmanning changed the title Provide a hook for health-checks Provide a hook for arbitrary scripts after 'apply' Jul 16, 2020
@kmanning
Copy link
Collaborator Author

UseCase: Database migrations

  • I've deployed a database using terraform-pipeline
  • I'd like to run a database migration, to ensure that my database schema is altered in an automated fashion, and all my environments are kept in-sync.
  • If my shell script returns a zero-status, I assume "it works" (based on unix return code conventions)
  • If my shell script returns a non-zero status, I assume that "it did not work as expected", and marks the "apply" stage of my environment as failed. I'm not allowed to continue.
  • My shell script should get all the "goodness" of pipelines that operate during "apply". Eg: I can access the IAM role and EnvironmentVariables provided by plugins like ParameterStorePlugin.

@kmanning
Copy link
Collaborator Author

kmanning commented Jul 16, 2020

Other thoughts:

  • This could potentially be a hook for ChangeMangement tasks
  • This could potentially be a hook for PR Postings

@kmanning kmanning added this to the v5.10 milestone Aug 5, 2020
@kmanning
Copy link
Collaborator Author

kmanning commented Aug 7, 2020

HealthCheck Script

@Library(['terraform-pipeline@v5.1']) _

Jenkinsfile.init(this)
PostApplyPlugin.run('./bin/healthcheck.sh')

def validate = new TerraformValidateStage()
// After `terraform apply`, run `./bin/healthcheck.sh'
def deployQa = new TerraformEnvironmentStage('qa')
// After `terraform apply`, run `./bin/healthcheck.sh'
def deployUat = new TerraformEnvironmentStage('uat')
// After `terraform apply`, run `./bin/healthcheck.sh'
def deployProd = new TerraformEnvironmentStage('prod')

validate.then(deployQa)
        .then(deployUat)
        .then(deployProd)
        .build()

DatabaseMigrate Script

@Library(['terraform-pipeline@v5.1']) _

Jenkinsfile.init(this)
PostApplyPlugin.run('./bin/run_migrations.sh')

def validate = new TerraformValidateStage()
// After `terraform apply`, run `./bin/run_migrations.sh'
def deployQa = new TerraformEnvironmentStage('qa')
// After `terraform apply`, run `./bin/run_migrations.sh'
def deployUat = new TerraformEnvironmentStage('uat')
// After `terraform apply`, run `./bin/run_migrations.sh'
def deployProd = new TerraformEnvironmentStage('prod')

validate.then(deployQa)
        .then(deployUat)
        .then(deployProd)
        .build()

@kmanning kmanning modified the milestones: v5.10, v5.11 Aug 17, 2020
@kmanning
Copy link
Collaborator Author

bumping to a future release

@jantman
Copy link
Contributor

jantman commented Dec 18, 2020

I've taken a crack at an implementation for this in #319

jantman added a commit to jantman/terraform-pipeline that referenced this issue Jan 4, 2021
jantman added a commit to jantman/terraform-pipeline that referenced this issue Jan 4, 2021
@kmanning kmanning linked a pull request Jan 5, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants