Skip to content

Commit

Permalink
Merge branch 'main' into add_cost_cred_for_azure-#218
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel-br committed Mar 27, 2022
2 parents 4db96df + 22b50a3 commit 2e0247c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
12 changes: 11 additions & 1 deletion docs/resources/notification.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ description: |-
## Example Usage

```terraform
resource "env0_notification" "example" {
resource "env0_project" "example_project" {
name = "project-example"
}
resource "env0_notification" "example_notification" {
name = "notification-example"
type = "Slack"
value = "https://www.slack.com/example/webhook"
}
resource "env0_notification_project_assignment" "test_assignment" {
project_id = env0_project.example_project.id
notification_endpoint_id = env0_notification.example_notification.id
event_names = ["environmentMarkedForAutoDestroy", "deploymentCancelled"]
}
```

<!-- schema generated by tfplugindocs -->
Expand Down
9 changes: 9 additions & 0 deletions env0/resource_configuration_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"strings"

"github.com/env0/terraform-provider-env0/client"
"github.com/env0/terraform-provider-env0/client/http"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down Expand Up @@ -199,6 +201,13 @@ func resourceConfigurationVariableRead(ctx context.Context, d *schema.ResourceDa
variable, err := apiClient.ConfigurationVariablesById(id)

if err != nil {
if frerr, ok := err.(*http.FailedResponseError); ok {
if frerr.NotFound() {
log.Printf("[WARN] Drift Detected: Terraform will remove %s from state", d.Id())
d.SetId("")
return nil
}
}
return diag.Errorf("could not get configurationVariable: %v", err)
}

Expand Down
25 changes: 25 additions & 0 deletions env0/resource_configuration_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"text/template"

"github.com/env0/terraform-provider-env0/client"
"github.com/env0/terraform-provider-env0/client/http"
"github.com/golang/mock/gomock"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
Expand Down Expand Up @@ -374,6 +375,30 @@ resource "%s" "test" {
})
})

t.Run("Configuration Removed in UI", func(t *testing.T) {
createTestCase := resource.TestCase{
Steps: []resource.TestStep{
{
Config: stepConfig,
},
{
Config: stepConfig,
},
},
}

runUnitTest(t, createTestCase, func(mock *client.MockApiClientInterface) {
gomock.InOrder(
mock.EXPECT().ConfigurationVariableCreate(configurationVariableCreateParams).Times(1).Return(configVar, nil),
mock.EXPECT().ConfigurationVariablesById(configVar.Id).Times(1).Return(configVar, nil),
mock.EXPECT().ConfigurationVariablesById(configVar.Id).Times(1).Return(client.ConfigurationVariable{}, http.NewMockFailedResponseError(404)),
mock.EXPECT().ConfigurationVariableCreate(configurationVariableCreateParams).Times(1).Return(configVar, nil),
mock.EXPECT().ConfigurationVariablesById(configVar.Id).Times(1).Return(configVar, nil),
mock.EXPECT().ConfigurationVariableDelete(configVar.Id).Times(1).Return(nil),
)
})
})

t.Run("Update", func(t *testing.T) {
newIsReadonly := false
newIsRequired := true
Expand Down
12 changes: 11 additions & 1 deletion examples/resources/env0_notification/resource.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
resource "env0_notification" "example" {
resource "env0_project" "example_project" {
name = "project-example"
}

resource "env0_notification" "example_notification" {
name = "notification-example"
type = "Slack"
value = "https://www.slack.com/example/webhook"
}

resource "env0_notification_project_assignment" "test_assignment" {
project_id = env0_project.example_project.id
notification_endpoint_id = env0_notification.example_notification.id
event_names = ["environmentMarkedForAutoDestroy", "deploymentCancelled"]
}
11 changes: 11 additions & 0 deletions tests/integration/017_notification/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,14 @@ resource "env0_notification" "test_notification" {
type = var.second_run ? "Slack" : "Teams"
value = var.second_run ? "https://someotherurl.com" : "https://someurl.com"
}

resource "env0_project" "test_project" {
name = "Test-Project-For-Notification"
description = "Test Description"
}

resource "env0_notification_project_assignment" "test_assignment" {
project_id = env0_project.test_project.id
notification_endpoint_id = env0_notification.test_notification.id
event_names = var.second_run ? ["deploymentCancelled"] : ["environmentMarkedForAutoDestroy"]
}

0 comments on commit 2e0247c

Please sign in to comment.