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

Can I skip a component from being applied if the before_hook fails? #3825

Open
flixman opened this issue Jan 31, 2025 · 1 comment
Open

Can I skip a component from being applied if the before_hook fails? #3825

flixman opened this issue Jan 31, 2025 · 1 comment

Comments

@flixman
Copy link

flixman commented Jan 31, 2025

I have a terragrunt repository that deploys a web app, and in that component I have a before_hook checking the image of the app on a container registry exists. Is there any way to skip the application of this component if the before_hook fails, but letting the application of the rest of the infrastructure continue?

@yhakbar
Copy link
Collaborator

yhakbar commented Jan 31, 2025

Ya, this is an example of how you'd do that:

# ./foo/main.tf
# ./foo/terragrunt.hcl
terraform {
	source = "."
	before_hook "flaky" {
                commands = ["plan", "apply"]
		execute = ["bash", "-c", "echo 'ERROR: Flaky hook!'; exit 1"]
	}
}

errors {
    ignore "flaky_hook" {
        ignorable_errors = [
            ".*ERROR: Flaky hook!.*",
        ]
        message = "Excluding unit from queue because of flaky hook"
    }
}
# ./bar/terragrunt.hcl
dependency "foo" {
	config_path = "../foo"

	mock_outputs = {
		"foo" = "mock foo"
	}
}
# ./bar/main.tf

Basically, use the errors configuration block to detect the error from your before hook, suppress the error, then proceed with the rest of the run queue.

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

No branches or pull requests

2 participants