Skip to content

env0_environment_discovery_configuration: perpetual drift on retries_on_deploy #1099

Description

@ggkr

Describe the bug

env0_environment_discovery_configuration shows perpetual drift on retries_on_deploy (and related retry fields): every terraform plan / tofu plan reports an in-place update such as retries_on_deploy = 0 -> 2 even immediately after a successful apply.

The value does not appear to stick in Terraform state because the provider read path sets retries_on_deploy to 0 when the Env0 API returns no retry.onDeploy object, while the configured value remains 2 (or whatever was set in HCL).

This looks like a mismatch between write and read for the environment discovery API: the provider sends retry.onDeploy on PUT, but GET (and/or the PUT response) often omits it, so templateReadRetryOnHelper maps nil0 in state.

Note: 0 is not a valid configured retry count per ValidateRetries (allowed range is 1–3); it appears to be a sentinel for “unset from API,” not the actual remote value.

To Reproduce

Steps to reproduce the behavior.

  1. Configure environment discovery with retries_on_deploy set (e.g. 2).
  2. Run terraform apply (or tofu apply) and confirm the update succeeds.
  3. Run terraform plan again with no config changes.
  4. Observe the same diff on retries_on_deploy every time.

Optional verification after apply:

terraform state show 'env0_environment_discovery_configuration.example'
# retries_on_deploy = 0  (even though HCL has 2)

Minimal Terraform snippet:

terraform {
  required_providers {
    env0 = {
      source  = "env0/env0"
      version = "~> 1.0" # e.g. 1.29.x — fill in your exact version below
    }
  }
}

resource "env0_project" "example" {
  name = "example-project"
}

resource "env0_environment_discovery_configuration" "example" {
  project_id   = env0_project.example.id
  glob_pattern = "**/terragrunt.hcl"
  repository   = "https://github.com/org/repo"
  type         = "terragrunt"

  terragrunt_version    = "0.54.0"
  opentofu_version      = "1.6.0"
  terragrunt_tf_binary  = "opentofu"
  is_terragrunt_run_all = true

  retries_on_deploy = 2
}

Expected behavior

After a successful apply:

  • Terraform state should reflect retries_on_deploy = 2.
  • A subsequent plan should show no change for retries_on_deploy.
  • The Env0 API GET for /environment-discovery/projects/{projectId} should return retry.onDeploy.times (or equivalent) matching what was sent on PUT.

Alternatively, if the environment discovery API does not support deploy/destroy retries, the provider should not expose those attributes on env0_environment_discovery_configuration, or should document that they are write-only / unsupported so users can avoid perpetual drift.

Provider Version

1.31.1

# terraform plan (after successful apply)
  # env0_environment_discovery_configuration.example will be updated in-place
  ~ resource "env0_environment_discovery_configuration" "example" {
        id                = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
      ~ retries_on_deploy = 0 -> 2
        # (N unchanged attributes hidden)
    }

Additional context

  • Suspected read-path behavior in templateReadRetryOnHelper (env0/resource_template.go): when retryOn == nil, the provider calls d.Set("retries_on_deploy", 0).
  • env0_environment_discovery_configuration uses this helper in setResourceEnvironmentDiscoveryConfiguration after GetEnvironmentDiscovery / PutEnvironmentDiscovery.
  • Client model: EnvironmentDiscoveryPayload.Retry is TemplateRetry with json:"retry"; deploy retries are under retry.onDeploy.times.
  • API endpoint: PUT / GET /environment-discovery/projects/{projectId}.
  • The same retries_on_deploy setting on env0_template may work correctly; drift appears specific to environment discovery configuration.
  • Workaround today: lifecycle { ignore_changes = [retries_on_deploy, ...] } on the discovery resource, or only set retries on the template.

Related code references (provider repo):

  • env0/resource_environment_discovery_configuration.gotemplateReadRetryOnHelper / templateCreatePayloadRetryOnHelper on read/write
  • env0/resource_template.gotemplateReadRetryOnHelper sets 0 when API returns nil
  • client/environment_discovery.goEnvironmentDiscoveryPutPayload.Retry / EnvironmentDiscoveryPayload.Retry

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions