env0 / terraform-provider-env0

Terraform Provider for env0

Home Page:https://env0.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`env0_environment.configuration` cannot coexist with `env0_configuration_variable` on the same environment

ronnyorot opened this issue · comments

Describe the bug
The resources env0_environment.configuration and env0_configuration_variable cannot coexist on the same environment, they keep updating and destroying each other, causing constant drift.

To Reproduce
Using the following code:

data "env0_project" "sub_project" {
  name="sub-project"
}

data "env0_template" "template" {
  name="noop"
}

resource "env0_environment" "example" {
  name        = "environment"
  project_id  = data.env0_project.sub_project.id
  template_id = data.env0_template.template.id
  configuration {
    name  = "env2"
    value = "on env0_environment.configuration"
  }
}

resource "env0_configuration_variable" "env" {
  name          = "env"
  value         = "on env0_configuration_variable"
  environment_id = env0_environment.example.id
}
  1. On first Apply:
    The environment with both variables is created correctly.

  2. On second Apply:
    The following change is detected:

  # env0_environment.example will be updated in-place
  ~ resource "env0_environment" "example" {
      - auto_deploy_on_path_changes_only = true -> null
      - deploy_on_push                   = true -> null
        id                               = "68eeb085-ae6e-439e-9ab5-676cce128530"
        name                             = "environment3"
      - run_plan_on_pull_requests        = true -> null
        # (7 unchanged attributes hidden)

      - configuration {
          - is_read_only = false -> null
          - is_required  = false -> null
          - is_sensitive = false -> null
          - name         = "env" -> null
          - schema_enum  = [] -> null
          - schema_type  = "string" -> null
          - type         = "environment" -> null
          - value        = "on env0_configuration_variable" -> null
        }

        # (1 unchanged block hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

After the apply the env variable (from env0_configuration_variable) is deleted.

  1. On the third apply:
    The following change is detected:
  # env0_configuration_variable.env will be created
  + resource "env0_configuration_variable" "env" {
      + environment_id = "68eeb085-ae6e-439e-9ab5-676cce128530"
      + id             = (known after apply)
      + is_read_only   = false
      + is_required    = false
      + is_sensitive   = false
      + name           = "env"
      + type           = "environment"
      + value          = (sensitive value)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

After the apply both variables exist.

And it keeps on and on like that - on the next apply we see scenario 2, and on the following apply scenario 3, etc...

Expected behavior
Both resources should be able to coexist without trying to update one another.

Provider Version
latest

aws provider has a note on some resources that can cause a conflict
image

@chpl agreed. It's an issue to fix it from the provider other than documentation.
@ronnyorot - is documentation missing for this limitation?