Fix: implement prevent_auto_deploy flag to allow configuration updates without triggering deployments#1103
Conversation
…es without triggering deployments
There was a problem hiding this comment.
Pull request overview
Implements support for prevent_auto_deploy during environment updates, allowing certain changes to be persisted in env0 without triggering a deployment/run (addressing APO-96).
Changes:
- Updates environment update flow to persist changes without calling
deploy()whenprevent_auto_deploy = true. - Adds helper functions to compute/apply configuration + variable set changes directly via API calls.
- Expands unit test coverage and updates resource documentation for
prevent_auto_deploy.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
env0/resource_environment.go |
Adds updateWithoutDeploy flow, helper functions for configuration scopes/changes, and updates prevent_auto_deploy behavior on read/update. |
env0/resource_environment_test.go |
Adds unit tests ensuring configuration, variable sets, and sub-environment configuration can persist without triggering deployments when prevent_auto_deploy is enabled. |
docs/resources/environment.md |
Updates the resource docs description for the prevent_auto_deploy flag. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
yarivg
left a comment
There was a problem hiding this comment.
@jackcloudquery how did you QA it? mind sharing the example to the PR desc
…tion updates without deployment
Added to the PR description |
liranfarage89
left a comment
There was a problem hiding this comment.
LGTM. All comments addressed — verified the WORKFLOW-scope create against the backend + live round-trip, the per-sub-env guard, and the new create/delete test. CI green. 🙏
Issue & Steps to Reproduce / Feature Request
prevent_auto_deployis respected when anenv0_environmentis created, but isignored on update. Changing
configuration,revision,variable_sets,template_id,or
sub_environment_configurationon an existing environment triggers a deployment (run) -even though the environment is explicitly flagged not to auto-deploy. Teams that manage the
shape of their environments with Terraform but run deployments themselves (CI/CD, behind
review gates) get runs kicked off outside their pipeline including production.
Minimal repro
After changing
valueto"baz",terraform applyqueues a new deployment on theenvironment (env0 → Activity) instead of just updating the variable.
Root cause:
shouldDeploydecides whether to deploy on update purely from which fieldschanged and never consults
prevent_auto_deploy, so the update path always hits the deployendpoint.
Solution
On update, when
prevent_auto_deployis set, the provider no longer queues a deployment.Instead it persists what env0 can apply without a run, directly:
configurationandsub_environment_configuration.*.configuration- written via theconfiguration endpoints (create / update / delete per variable).
variable_sets- assigned / unassigned via the configuration-set assignment endpoints.revision/template_id- these only take effect as part of a deployment, so underprevent_auto_deploythey're kept declaratively in state and applied by the user's owndeploy. The read no longer overwrites them from the latest deployment log, avoiding
perpetual drift.
This mirrors what the env0 backend already does at create time (
createWithoutDeploy):on create the provider just sends
preventAutoDeployin the payload and the backend forks;on update there's no equivalent endpoint, so the provider makes the same decision client-side.
Notes (by design):
revisionchange underprevent_auto_deployis recorded in state but is a no-op until thenext deployment; external changes to
revision/template_idare not surfaced as drift(documented on the field).
endpoint); a mid-loop failure leaves a partial apply that Terraform reconciles next run -
same behavior as the standalone
env0_configuration_variableresource.After the fix the repro updates
FOOtobazwith no deployment queued, andterraform planafterwards reportsNo changes.Manual E2E verification:
dev_overrides, ran against the env0 dev stackenv0_environmentwithprevent_auto_deploy = trueand aconfigurationvariable (self-contained config: project + template + assignment + environment)
revision, thenterraform apply→ no newdeployment on the environment (env0 → Activity) and the variable value is updated
(env0 → Variables)
terraform planafter the apply →No changes. Your infrastructure matches the configuration.(no drift on the variable or revision)prevent_auto_deploy(asserting
ConfigurationVariableUpdate/Create/Deletefire andEnvironmentDeploydoesnot), variable-set assign/unassign, sub-environment configuration, and
revision/template_id drift suppression
Closes https://linear.app/env-zero/issue/APO-96/preventautodeploy-is-ignored-on-certain-environment-updates