env0 / terraform-provider-env0

Terraform Provider for env0
https://env0.com
Mozilla Public License 2.0
39 stars 14 forks source link

bug - configuration variable that overrides a template variable in env0_environment shows drift #894

Open away168 opened 1 month ago

away168 commented 1 month ago

Describe the bug A variable defined in the env0_template is being overwritten | specified in env0_environment that uses the template.

the plan shows drift of parameters that are not meant to be re-configured (e.g. regex, is_required, description

  ~ resource "env0_environment" "default_projects" {
        id                               = "f29bfdca-1a77-49dd-b197-f2f0c4913a99"
        name                             = "Skunkworks Project"
      ~ variable_sets                    = [
          - "69cfcac0-5135-4967-a9d5-c6166f216f4c",
        ]
        # (13 unchanged attributes hidden)

      ~ configuration {
          - description  = "main project name for team" -> null
          ~ is_required  = true -> false
            name         = "team_name"
          - regex        = "[a-zA-Z0-9-_]*" -> null
            # (6 unchanged attributes hidden)
        }
    }

To Reproduce

  1. Create an env0_template and env0_configuration_variable attached to template.
  2. Create an env0_environment that is deployed from template with a configuration variable that overrides the template variable.

Expected behavior the env0_environment should not show drift.

Provider Version v1.19.1

Screenshots

Additional context Sample code:

resource "env0_template" "projects" {
  name                   = "Team Projects"
  type                   = "opentofu"
  description            = "Project Factory for onboarding new teams"
  opentofu_version       = "latest"
  repository             = data.env0_template.this.repository
  path                   = "env0/projects"
  github_installation_id = data.env0_template.this.github_installation_id
}

resource "env0_template_project_assignment" "projects" {
  template_id = env0_template.projects.id
  project_id  = data.env0_environment.this.project_id
}

resource "env0_configuration_variable" "team_name" {
  template_id = env0_template.projects.id
  name        = "team_name"
  description = "main project name for team"
  is_required = true
  regex       = "[a-zA-Z0-9-_]*"
  type        = "terraform"
}

resource "env0_environment" "default_projects" {
  count = var.create_projects ? 1 : 0

  name                       = "${var.default_team_name} Project"
  project_id                 = data.env0_environment.this.project_id
  template_id                = env0_template.projects.id
  approve_plan_automatically = true
  is_remote_backend          = true
  removal_strategy           = "mark_as_archived"
  workspace                  = "${var.default_team_name}_project"

  configuration {
    name        = "team_name"
    value       = var.default_team_name
    type        = "terraform"
  }

  depends_on = [env0_configuration_variable.team_name]
}
TomerHeber commented 1 month ago

re-opened. This is a different issue than the variable set issue. Will reviewe.