Skip to content

Commit

Permalink
Fix: env0_environment resource - cannot re-enable vcs (#963)
Browse files Browse the repository at this point in the history
* Fix: env0_environment resource - cannot re-enable vcs

* add harness test

* add harness test

* add harness test
  • Loading branch information
TomerHeber authored Oct 27, 2024
1 parent 34e6b6d commit 4e6e7c1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
12 changes: 6 additions & 6 deletions env0/resource_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,12 @@ func resourceEnvironmentUpdate(ctx context.Context, d *schema.ResourceData, meta
}
}

if shouldUpdateTemplate(d) {
if err := updateTemplate(d, apiClient); err != nil {
return err
}
}

if shouldUpdate(d) {
if err := update(d, apiClient); err != nil {
return err
Expand All @@ -702,12 +708,6 @@ func resourceEnvironmentUpdate(ctx context.Context, d *schema.ResourceData, meta
}
}

if shouldUpdateTemplate(d) {
if err := updateTemplate(d, apiClient); err != nil {
return err
}
}

if shouldDeploy(d) {
if err := deploy(d, apiClient); err != nil {
return err
Expand Down
23 changes: 23 additions & 0 deletions tests/integration/012_environment/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,29 @@ resource "env0_environment" "environment-without-template" {
}
}

data "env0_template" "gitlab_template" {
name = "Gitlab Integrated Template"
}

resource "env0_environment" "environment-without-template-start-with-no-vcs" {
name = "start-with-non-vsc-${random_string.random.result}"
project_id = env0_project.test_project.id
force_destroy = true

auto_deploy_on_path_changes_only = var.second_run ? true : false
deploy_on_push = var.second_run ? true : false
run_plan_on_pull_requests = var.second_run ? true : false

without_template_settings {
type = "opentofu"
is_gitlab = var.second_run ? true : false
repository = data.env0_template.gitlab_template.repository
token_id = data.env0_template.gitlab_template.token_id
token_name = data.env0_template.gitlab_template.token_name
opentofu_version = "latest"
}
}

resource "env0_environment" "inactive" {
depends_on = [env0_template_project_assignment.assignment]
force_destroy = true
Expand Down

0 comments on commit 4e6e7c1

Please sign in to comment.