Set conditions for deployment plans
Orchestration rules allow you to automate aspects of your Stack deployments, such as auto-approving plans when those plans meet certain conditions. By setting orchestration rules, you can help streamline managing many deployments.
Create orchestration rules
Add orchestrate
blocks to define rules for handling deployment plans in your deployment configuration file (tfdeploy.hcl
).
The orchestrate
block uses a check
block to determine if a condition has passed or not, and every condition must pass for the orchestrate
rule to take effect. For details on the syntax of an orchestrate
block, refer to the Deployment configuration file reference.
Orchestrate rule types
There are two orchestration rule types to choose from:
- The
auto_approve
rule executes after a Stack creates a plan and automatically approves a plan if all checks pass. - The
replan
rule executes after a Stack applies a plan, automatically triggering a replan if all the checks pass.
The auto_approve
rule is helpful when you know you want a certain type of plan to go ahead without manual intervention. For example, Stacks have a default auto_approve
rule named empty_plan
, which automatically approves a plan if it has no changes.
As another example, you could create a rule that automatically approves deployments if a component has not changed.
The above orchestrate
block automatically approves plans if they do not include any changes for the pet
component.
The replan
rule is helpful when you need your Stack to perform another plan after it applies the last one. You could create a rule to automatically replan a deployment if the production deployment errors out.
The above orchestrate
block triggers a replan if the production development of a Stack errors out and if HCP Terraform hasn't already attempted to replan.
Leverage orchestration context
The orchestrate
block can use the context
variable, which provides access to detailed information about the deployment plan, such as the number of changes, the specific components involved, and the deployment’s status.
Use context
to create more sophisticated checks and conditions. For example, you can automatically approve all planning operations.
Another example of using context
is automatically approving plans that do not remove resources in non-production deployments.
For more information on the information available in the context variable, refer to the Deployment configuration file reference.
Next steps
With your Stack and deployment configurations complete, your Stack is ready to be deployed by HCP Terraform. To learn more about creating a Stack in HCP Terraform, refer to Create a Stack.