Skip to content

Commit

Permalink
Fix: approve_plan_automatically attribute fails for sub_environment
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerHeber committed Sep 11, 2024
1 parent 8411711 commit 6604c6f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions env0/resource_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,11 @@ func getDeployPayload(d *schema.ResourceData, apiClient client.ApiClientInterfac
payload.BlueprintRevision = revision.(string)
}

// For 'Workflows', the 'root' environment should never require a user approval.
if _, ok := d.GetOk("sub_environment_configuration"); ok {
payload.UserRequiresApproval = boolPtr(false)
}

if isRedeploy {
if revision, ok := d.GetOk("without_template_settings.0.revision"); ok {
payload.BlueprintRevision = revision.(string)
Expand Down
8 changes: 5 additions & 3 deletions env0/resource_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2929,7 +2929,8 @@ func TestUnitEnvironmentWithSubEnvironment(t *testing.T) {
},
},
DeployRequest: &client.DeployRequest{
BlueprintId: environment.BlueprintId,
BlueprintId: environment.BlueprintId,
UserRequiresApproval: boolPtr(false),
SubEnvironments: map[string]client.SubEnvironment{
subEnvironment.Alias: {
Workspace: subEnvironment.Workspace,
Expand All @@ -2946,8 +2947,9 @@ func TestUnitEnvironmentWithSubEnvironment(t *testing.T) {
}

deployRequest := client.DeployRequest{
BlueprintId: environment.BlueprintId,
BlueprintRevision: environment.LatestDeploymentLog.BlueprintRevision,
BlueprintId: environment.BlueprintId,
BlueprintRevision: environment.LatestDeploymentLog.BlueprintRevision,
UserRequiresApproval: boolPtr(false),
SubEnvironments: map[string]client.SubEnvironment{
subEnvironment.Alias: {
Revision: subEnvironment.Revision,
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/012_environment/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ resource "env0_environment" "workflow-environment" {
name = "environment-workflow-${random_string.random.result}"
project_id = env0_project.test_project.id
template_id = env0_template.workflow_template.id
approve_plan_automatically = true

configuration {
name = "n1"
Expand All @@ -269,7 +268,7 @@ resource "env0_environment" "workflow-environment" {
sub_environment_configuration {
alias = "rootService1"
revision = "master"
approve_plan_automatically = var.second_run ? true : false
approve_plan_automatically = var.second_run ? false : true
configuration {
name = "sub_env1_var1"
value = "hello"
Expand Down

0 comments on commit 6604c6f

Please sign in to comment.