Skip to content

Commit

Permalink
Fix: second apply of environment 'without_template_settings' causes r…
Browse files Browse the repository at this point in the history
…ecreation (#510)
  • Loading branch information
TomerHeber committed Sep 30, 2022
1 parent 3c3799e commit aec4de6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion env0/resource_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/env0/terraform-provider-env0/client"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand Down Expand Up @@ -49,7 +50,6 @@ func resourceEnvironment() *schema.Resource {
Type: schema.TypeString,
Description: "the template id the environment is to be created from.\nImportant note: the template must first be assigned to the same project as the environment (project_id). Use 'env0_template_project_assignment' to assign the template to the project. In addition, be sure to leverage 'depends_on' if applicable.",
Optional: true,
ForceNew: true,
ExactlyOneOf: []string{"without_template_settings", "template_id"},
},
"workspace": {
Expand Down Expand Up @@ -228,6 +228,15 @@ func resourceEnvironment() *schema.Resource {
},
},
},

CustomizeDiff: customdiff.ForceNewIf("template_id", func(ctx context.Context, d *schema.ResourceDiff, meta interface{}) bool {
// For templateless: any changes in template_id, no need to do anything (template id can't change).
// This is done due to historical bugs/issues.
if _, ok := d.GetOk("without_template_settings.0"); ok {
return false
}
return true
}),
}
}

Expand Down

0 comments on commit aec4de6

Please sign in to comment.