From 9581439e54e9fd44958f03177bb7661c7da49cdf Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Thu, 25 Jul 2024 16:24:28 -0500 Subject: [PATCH] Fix: env0_environment does not redeploy when revision is changed in without_template_settings (#907) --- env0/resource_environment.go | 13 +++++++++++-- env0/resource_environment_test.go | 7 +++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/env0/resource_environment.go b/env0/resource_environment.go index 696b2d03..71cc9ccf 100644 --- a/env0/resource_environment.go +++ b/env0/resource_environment.go @@ -732,6 +732,12 @@ func shouldUpdateTemplate(d *schema.ResourceData) bool { } func shouldDeploy(d *schema.ResourceData) bool { + if _, ok := d.GetOk("without_template_settings.0"); ok { + if d.HasChange("without_template_settings.0.revision") { + return true + } + } + return d.HasChanges("revision", "configuration", "sub_environment_configuration", "variable_sets") } @@ -1126,8 +1132,7 @@ func getDeployPayload(d *schema.ResourceData, apiClient client.ApiClientInterfac var err error if isTemplateless(d) { - templateId, ok := d.GetOk("without_template_settings.0.id") - if ok { + if templateId, ok := d.GetOk("without_template_settings.0.id"); ok { payload.BlueprintId = templateId.(string) } } else { @@ -1139,6 +1144,10 @@ func getDeployPayload(d *schema.ResourceData, apiClient client.ApiClientInterfac } if isRedeploy { + if revision, ok := d.GetOk("without_template_settings.0.revision"); ok { + payload.BlueprintRevision = revision.(string) + } + if configuration, ok := d.GetOk("configuration"); ok && isRedeploy { configurationChanges := getConfigurationVariablesFromSchema(configuration.([]interface{})) scope := client.ScopeEnvironment diff --git a/env0/resource_environment_test.go b/env0/resource_environment_test.go index ef2a0b16..13730cc5 100644 --- a/env0/resource_environment_test.go +++ b/env0/resource_environment_test.go @@ -2541,6 +2541,13 @@ func TestUnitEnvironmentWithoutTemplateResource(t *testing.T) { // Update mock.EXPECT().TemplateUpdate(template.Id, templateUpdatePayload).Times(1).Return(updatedTemplate, nil), + mock.EXPECT().ConfigurationSetsAssignments("ENVIRONMENT", environment.Id).Times(1).Return(nil, nil), + mock.EXPECT().EnvironmentDeploy(environment.Id, client.DeployRequest{ + BlueprintId: template.Id, + BlueprintRevision: updatedTemplate.Revision, + }).Times(1).Return(client.EnvironmentDeployResponse{ + Id: environment.Id, + }, nil), // Read mock.EXPECT().Environment(environment.Id).Times(1).Return(environment, nil),