Skip to content

Commit

Permalink
Fix: env0_environment does not redeploy when revision is changed in w…
Browse files Browse the repository at this point in the history
…ithout_template_settings (#907)
  • Loading branch information
TomerHeber authored Jul 25, 2024
1 parent 850c77f commit 9581439
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 11 additions & 2 deletions env0/resource_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions env0/resource_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 9581439

Please sign in to comment.