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

lifecycle hook to wait until all terraform processes are completed #258

Open
nitrocode opened this issue Jan 27, 2023 · 5 comments
Open
Labels
enhancement New feature or request

Comments

@nitrocode
Copy link
Member

Lifecycle hooks are supported but it would be nice to add

  • either a default lifecycle to prevent terraform from being killed in the middle of an apply or plan
    • otherwise we could have resources created and the information is not saved into the tfstate
    • otherwise we could have stale dynamodb locks
  • or document the lifecycle hook to be optionally added

cc: @Balsir since you added the lifecycle feature to this repo, have you figured out a good preStop lifecycle ?

References

@Balsir
Copy link
Contributor

Balsir commented Jan 30, 2023

hi @nitrocode, unfortunately haven't had the time for it yet.

The initial idea was to trap SIGTERM via preStop and wait for a configurable amount of time to attempt to let Terraform finish. Atlantis could then proceed with graceful termination (runatlantis/atlantis#1051).

A little food for thought: since the server already handles graceful termination to an extent, wouldn't it be better to implement the use case on the server rather than in the Helm chart?

@nitrocode
Copy link
Member Author

Yes, graceful termination should be implemented in the server. I was thinking this lifecycle method could be a nice workaround for now. 😄

@GenPage
Copy link
Member

GenPage commented Jan 31, 2023

@nitrocode Should we close this issue and create one on the Atlantis repo?

@GenPage GenPage added the enhancement New feature or request label Jan 31, 2023
@nitrocode
Copy link
Member Author

I think we can have both issues. One here for lifecycle method and one for graceful termination in the server.

@mubarak-j
Copy link
Contributor

This is what I came up with, let me know if seems okay and I will create a PR.

statefulSet:
  terminationGracePeriodSeconds: 180

lifecycle:
  preStop:
    exec:
      command:
        - /bin/bash
        - -c
        - while [ "$(pgrep -f terraform)" ]; do sleep 1; done

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

No branches or pull requests

4 participants