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

Allow the before and after hooks to be skipped #3824

Open
2 tasks done
spowser opened this issue Jan 30, 2025 · 1 comment
Open
2 tasks done

Allow the before and after hooks to be skipped #3824

spowser opened this issue Jan 30, 2025 · 1 comment
Labels
contributions-requested Requesting contributions from the community enhancement New feature or request preserved Preserved issues never go stale

Comments

@spowser
Copy link

spowser commented Jan 30, 2025

Describe the enhancement

Add a new property to the before_hook and after_hook to allow it to be skipped. Suggested name is if

Additional context

The current method I am using for getting a similar outcome is to add a ternary to the execute and run the commands or a set of "do nothing" commands. It would be nice to save the execution time and just completely avoid having to run anything if the condition is false

Default it to true to preserve current behavior

PoC (Proof of Concept)

terraform {
  after_hook X {
    commands  = ["init"]
    execute   = ["terraform", "workspace", "select", "-or-create", "${local.someValue}"]
    if        = local.isValidForUnitX
  }

  before_hook X {
    commands  = ["plan", "state", "apply", "destroy", "refresh"]
    execute   = ["terraform", "workspace", "select", "-or-create", "${local.someValue}"]
    if        = local.isValidForUnitX
  }

  after_hook Y {
    commands  = ["init"]
    execute   = ["terraform", "workspace", "select", "-or-create", "${local.someValue}"]
    if        = local.isValidForUnitY
  }

  before_hook Y {
    commands  = ["plan", "state", "apply", "destroy", "refresh"]
    execute   = ["terraform", "workspace", "select", "-or-create", "${local.someValue}"]
    if        = local.isValidForUnitY
  }
}

Including a PoC can help others understand the feature better and implement it faster.

RFC Not Needed

  • I have evaluated the complexity of this enhancement, and I believe it does not require an RFC.
@spowser spowser added the enhancement New feature or request label Jan 30, 2025
@yhakbar yhakbar added contributions-requested Requesting contributions from the community preserved Preserved issues never go stale labels Jan 30, 2025 — with Linear
@yhakbar
Copy link
Collaborator

yhakbar commented Jan 30, 2025

The pattern that we typically use for this kind of thing is to use an if attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributions-requested Requesting contributions from the community enhancement New feature or request preserved Preserved issues never go stale
Projects
None yet
Development

No branches or pull requests

2 participants