From 850c77f58a955ee3983ceab19583013f82df7fe1 Mon Sep 17 00:00:00 2001 From: Arel Rabinowitz <30493345+RLRabinowitz@users.noreply.github.com> Date: Wed, 24 Jul 2024 19:05:44 +0300 Subject: [PATCH 1/2] Change description of variable_sets field on environment_resource (#905) --- docs/resources/environment.md | 2 +- env0/resource_environment.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/resources/environment.md b/docs/resources/environment.md index a30f7a3e..b76acd04 100644 --- a/docs/resources/environment.md +++ b/docs/resources/environment.md @@ -84,7 +84,7 @@ Important note: the template must first be assigned to the same project as the e Important note: After the environment is created, this field cannot be modified. - `terragrunt_working_directory` (String) The working directory path to be used by a Terragrunt template. If left empty '/' is used. Note: modifying this field destroys the current environment and creates a new one - `ttl` (String) the date the environment should be destroyed at (iso format). omitting this attribute will result in infinite ttl. -- `variable_sets` (List of String) a list of variable set to assign to this environment. Note: must not be used with 'env0_variable_set_assignment' +- `variable_sets` (List of String) a list of IDs of variable sets to assign to this environment. Note: must not be used with 'env0_variable_set_assignment' - `vcs_commands_alias` (String) set an alias for this environment in favor of running VCS commands using PR comments against it. Additional details: https://docs.env0.com/docs/plan-and-apply-from-pr-comments - `vcs_pr_comments_enabled` (Boolean) set to 'true' to enable running VCS PR plan/apply commands using PR comments. This can be set to 'true' (enabled) without setting alias in 'vcs_commands_alias'. Additional details: https://docs.env0.com/docs/plan-and-apply-from-pr-comments#configuration - `without_template_settings` (Block List, Max: 1) settings for creating an environment without a template (see [below for nested schema](#nestedblock--without_template_settings)) diff --git a/env0/resource_environment.go b/env0/resource_environment.go index cfd3d018..696b2d03 100644 --- a/env0/resource_environment.go +++ b/env0/resource_environment.go @@ -362,7 +362,7 @@ func resourceEnvironment() *schema.Resource { }, "variable_sets": { Type: schema.TypeList, - Description: "a list of variable set to assign to this environment. Note: must not be used with 'env0_variable_set_assignment'", + Description: "a list of IDs of variable sets to assign to this environment. Note: must not be used with 'env0_variable_set_assignment'", Optional: true, Elem: &schema.Schema{ Type: schema.TypeString, From 9581439e54e9fd44958f03177bb7661c7da49cdf Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Thu, 25 Jul 2024 16:24:28 -0500 Subject: [PATCH 2/2] 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),