Permissions to run a one time tasksAd hoc tasks allow you to run any command on the deployment container, so by default only organization administrators may run these tasks. You can use Custom roles to grant this permission to other users.
Executing a Run Task

Run a Task.It will prompt you to enter the commands you desire to execute.
Enter the commands, as you would in a bash script. Separate commands with new lines.
When you are ready to run your task - click the
RUN A TASK button below.

During the task execution, all the variables that are defined in the environment will be available for you to use. Tasks also support custom flows. You can read more about the available hooks here.
Common Tasks
- Migrate state:
terraform init -migrate-state -force-copyorecho "yes" | terraform init -migrate-state - Release state lock:
terraform force-unlock -force LOCK_ID [DIR] - Retrieve output:
terraform output [options] [NAME] - Taint a resource
terraform taint [options] <address> - Move state:
terraform state mv [options] SOURCE DESTINATION
The tools available for executing commands are the same ones that were available during your last deployment.
If you require additional tools, make sure to update the ENV0_INSTALLED_TOOLS variable and run the deployment again.
Tasks and Terraform Init
Tasks do not clone your source code. When the environment has a working directory archive from a previous deployment, env zero restores it and runs your script against it, and that archive does not include Terraform provider binaries (.terraform/providers).
For Terraform, OpenTofu, and Terragrunt environments, env zero runs an init step before your task script whenever the restored working directory is missing its provider cache. Your script still runs exactly as you wrote it, and you do not need to add terraform init yourself.
The init step does not run when:
- The provider binaries are already in the working directory, for example after an agent version that still archived them.
- The environment uses a tool with no init step, such as Pulumi, Helm, Kubernetes, Ansible, or CloudFormation.
ENV0_ARCHIVE_TF_PROVIDERS=trueis set, because the archive still carries the providers.- There is no working directory to restore, which is covered in the next section.
Tasks on Environments With No Working Directory
You can run a task on an environment that has never been deployed, and on one whose working directory archive has expired. A task is often how you inspect or repair an environment before it has ever run, so it does not require a deployment first. env zero notes what it found in the deployment log and runs your script either way: against the state files alone when those are still available, or in an empty working directory when they are not. Nothing is initialized in that case, so a task that needs Terraform providers or modules has to runterraform init itself before anything else.
Task Comments
You can add a comment, to let your teammates know why the task was run.Add a comment, by filling in the “Comment” input down below the
bash input.

Markdown syntax is supported.

Markdown SupportThe comment supports Markdown, so you would be able to generate even more context.
Next steps
- Custom flows overview - Commit reusable command hooks to your git repository.
- Managing variables - Access and manage the variables available during task execution.
- Environment overview - Review the deployment container and state lifecycle.