Additional Controls

๐Ÿšง

Disclaimer

Additional Controls are features that arenโ€™t available through the user interface, but can be used by setting the appropriate environment variables, at the Organization, Template, Project, or Environment level.

๐Ÿ“˜

OpenTofu Support

All controls that relate to Terraform should control OpenTofu the same way.

Terraform Targeted Apply

Using the ENV0_TERRAFORM_TARGET environment variable, you can allocate specific resources that will be targeted for apply. The variableโ€™s value will be passed to Terraform via the '-target` flag.
Read more here.

Specify Terraform/Terragrunt Versions

Using the ENV0_TF_VERSION environment variable, you can specify the Terraform version you would like your environment to use. You can read more here.

You can also use the ENV0_TERRAGRUNT_VERSION environment variable to specify the Terragrunt version for your applicable Terragrunt deployments.

Another way to determine the version for both Terraform and Terragrunt is a version file. When a file with a name. {type}-version (type being either "terraform" or "terragrunt") exists in the project's root directory the version is resolved based on the content of the file. The sole content of the file should be the version you wish to use.

The order of precedence whenever the version is specified using more than one option is as follows: env0 environment variable, version file, version selected when creating/updating the template.

๐Ÿ“˜

Specifying version in Terraform code

You can also set the version in your Terraform code and env0 will automatically install the correct version for using tfenv

Custom Terraform Variables File

Using the ENV0_TERRAFORM_CONFIG_FILE_PATH environment variable, you can select multiple Terraform variable files to pass on to Terraform. The list of filenames should be comma delimited.

Terraform Backend Config

Using the ENV0_TERRAFORM_BACKEND_CONFIG environment variable, you can pick a custom backend config to be used in terraform init. The value of the variable will be passed to the -backend-config flag.
If you would like to have multiple -backend-config declarations, you can pass the multiple values in the ENV0_TERRAFORM_BACKEND_CONFIG environment variable as a comma-delimited string. For example, a value of /path/to/config/file,key=value will result in the flags -backend-config="/path/to/config/file" -backend-config="key=value".
Read more here.

Enable Cost Tagging Per Environment

Cost tagging works on the project level and once enabled, env0 will tag every environment under that project. Sometimes (mainly for debugging purposes) you might wish to turn on cost tagging only for a specific environment and not for the whole project.
You can do that using the ENV0_ENABLE_COST_TAG environment variable.

Adding Custom Resource Tagging

When cost tagging is enabled for an environment, using the ENV0_CUSTOM_TAGS environment variable will enable custom resource tags to be applied using terratag (for Terraform and Terragrunt) or natively for other IaCs.
The variable value should be supplied in the form of: {"aTagName": "aTagValue", ...}.
This would apply the tags to all taggable resources in the environment.
You can use other environment variables in the tags, for example {"created_by": "$ENV0_ENVIRONMENT_CREATOR_NAME"}. See this list for the environment variables that env0 exposes.

Skip Workspace Commands

For each environment, select the existing terraform workspace or create one if necessary. The workspace will be deleted upon destroying the environment.
If you wish not to execute these commands you can skip them by using theENV0_SKIP_WORKSPACE environment variable and set its value to true. Please remove the environment variable altogether or set its value to empty to run the workspace commands.

Custom Git Clone Arguments

By default, your repository will be cloned with the arguments --depth=1 --single-branch.
You can override this by supplying the environment variable ENV0_GIT_CLONE_ARGS, the value of which will be sanitized and appended to the Git clone command instead of the default arguments.

Skip Git Submodules

By default, if you have Git submodules configured in your repository, env0 clones them with a depth of 1.
If you do not wish to clone your Git submodules, you can manage that via the ENV0_SKIP_SUBMODULE_GIT_CLONE environment variable and set its value to true.
If you remove the environment variable altogether or set its value to be empty, env0 will clone your Git submodules.

Skip Get Working Directory

If you do not want to use the current working directory, set ENV0_IGNORE_STATE=true

Omit Plan Files in Terragrunt Run-All

If run-all apply is failing, you can try omitting plan files from the plan and apply steps by setting ENV0_OMIT_TERRAGRUNT_RUN_ALL_PLAN_FILE=true. Read more here

Ansible Flags and Variables

You can set any environment variable prefixed by ANSIBLE_CLI_ to set any flag for ansible-playbook.

Additionally - you can set any environment variable prefixed by ANSIBLE_VAR_ to set any extra variable to be added under the --extra-vars flag.

Read more here.

Ansible Custom Playbook File

By default, env0 will try to run ansible-playbook on playbook.y[a]ml.

You can control that file's name by setting the ENV0_ANSIBLE_PLAYBOOK variable.

Skip Ansible Check Playbook Step

If you like to skip the Ansible check step, add an environment variable named ENV0_SKIP_ANSIBLE_CHECK and set the value to true. Read more here.

โœ๏ธ Suggested Blog Content

Terraform Modules Guide

Terraform Plan Examples

Managing Terraform Variable Hierarchy

Manage Terraform Remote State with a Remote Backend