Skip to content

Commit

Permalink
Merge branch 'main' into feat-add_token_name-#902
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerHeber authored Jul 26, 2024
2 parents 1f8adee + 9581439 commit f82fbd6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/resources/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
15 changes: 12 additions & 3 deletions env0/resource_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down 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 f82fbd6

Please sign in to comment.