Skip to content

Commit

Permalink
Merge branch 'main' into fix-configuration-override-#894
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerHeber authored Sep 25, 2024
2 parents f4afc47 + ee882b8 commit 9e47c7b
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 6 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/assign-reviewers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Assign PR Reviewers

on:
issue_comment:
types: [created]

jobs:
assign-reviewers:
runs-on: ubuntu-latest
if: ${{ github.event.issue.pull_request != null && github.event.comment.body == '/review' }}
steps:
- name: Assign PR Reviewers
env:
GITHUB_TOKEN: ${{ secrets.ENV0_BOT_PAT }}
run: |
curl -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.issue.number }}/requested_reviewers \
-d '{"team_reviewers":["env0-team"]}'
9 changes: 9 additions & 0 deletions docs/data-sources/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,14 @@ output "environment_name" {
- `revision` (String) the last deployed revision
- `run_plan_on_pull_requests` (Boolean) does pr plan enable
- `status` (String) the status of the environment
- `sub_environment_configuration` (List of Object) the sub environments of the workflow environment. (Empty for non workflow environments) (see [below for nested schema](#nestedatt--sub_environment_configuration))
- `template_id` (String) the template id the environment is to be created from
- `token_id` (String) The token id used for repo integrations (Used by Gitlab or Azure DevOps)

<a id="nestedatt--sub_environment_configuration"></a>
### Nested Schema for `sub_environment_configuration`

Read-Only:

- `alias` (String)
- `id` (String)
45 changes: 45 additions & 0 deletions env0/data_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package env0

import (
"context"
"slices"
"strings"

"github.com/env0/terraform-provider-env0/client"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -98,6 +100,25 @@ func dataEnvironment() *schema.Resource {
Description: "The token id used for repo integrations (Used by Gitlab or Azure DevOps)",
Computed: true,
},
"sub_environment_configuration": {
Type: schema.TypeList,
Description: "the sub environments of the workflow environment. (Empty for non workflow environments)",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Description: "the id of the sub environment",
Computed: true,
},
"alias": {
Type: schema.TypeString,
Description: "sub environment alias name",
Computed: true,
},
},
},
},
},
}
}
Expand Down Expand Up @@ -127,6 +148,30 @@ func dataEnvironmentRead(ctx context.Context, d *schema.ResourceData, meta inter
return diag.FromErr(err)
}

subEnvironments := []interface{}{}

if environment.LatestDeploymentLog.WorkflowFile != nil {
for alias, subenv := range environment.LatestDeploymentLog.WorkflowFile.Environments {
subEnvironment := map[string]interface{}{
"id": subenv.EnvironmentId,
"alias": alias,
}
subEnvironments = append(subEnvironments, subEnvironment)
}
}

slices.SortFunc(subEnvironments, func(a, b interface{}) int {
amap := a.(map[string]interface{})
bmap := b.(map[string]interface{})

aalias := amap["alias"].(string)
balias := bmap["alias"].(string)

return strings.Compare(aalias, balias)
})

d.Set("sub_environment_configuration", subEnvironments)

templateId := environment.LatestDeploymentLog.BlueprintId

template, err := getTemplateById(templateId, meta)
Expand Down
14 changes: 14 additions & 0 deletions env0/data_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ func TestEnvironmentDataSource(t *testing.T) {
BlueprintId: template.Id,
BlueprintRevision: "revision",
Output: []byte(`{"a": "b"}`),
WorkflowFile: &client.WorkflowFile{
Environments: map[string]client.WorkflowSubEnvironment{
"db": {
EnvironmentId: "id_db",
},
"compute": {
EnvironmentId: "id_compute",
},
},
},
},
}

Expand Down Expand Up @@ -78,6 +88,10 @@ func TestEnvironmentDataSource(t *testing.T) {
resource.TestCheckResourceAttr(accessor, "token_id", template.TokenId),
resource.TestCheckResourceAttr(accessor, "github_installation_id", strconv.Itoa(template.GithubInstallationId)),
resource.TestCheckResourceAttr(accessor, "bitbucket_client_key", template.BitbucketClientKey),
resource.TestCheckResourceAttr(accessor, "sub_environment_configuration.0.alias", "compute"),
resource.TestCheckResourceAttr(accessor, "sub_environment_configuration.0.id", "id_compute"),
resource.TestCheckResourceAttr(accessor, "sub_environment_configuration.1.alias", "db"),
resource.TestCheckResourceAttr(accessor, "sub_environment_configuration.1.id", "id_db"),
),
},
},
Expand Down
15 changes: 9 additions & 6 deletions tests/integration/012_environment/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ resource "env0_template_project_assignment" "assignment_workflow" {
project_id = env0_project.test_project.id
}


resource "env0_variable_set" "variable_set1" {
name = "variable-set-project-${random_string.random.result}"
description = "description123"
Expand Down Expand Up @@ -253,10 +252,10 @@ resource "env0_environment" "workflow-environment" {
env0_template_project_assignment.assignment_workflow,
env0_template_project_assignment.assignment_sub_environment_null_template
]
force_destroy = true
name = "environment-workflow-${random_string.random.result}"
project_id = env0_project.test_project.id
template_id = env0_template.workflow_template.id
force_destroy = true
name = "environment-workflow-${random_string.random.result}"
project_id = env0_project.test_project.id
template_id = env0_template.workflow_template.id

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

data "env0_environment" "test-workflow" {
id = env0_environment.workflow-environment.id
}

resource "env0_environment" "mark_as_archived" {
depends_on = [env0_template_project_assignment.assignment]
name = "environment-mark-as-archived-${random_string.random.result}"
Expand Down

0 comments on commit 9e47c7b

Please sign in to comment.