Skip to content

Commit

Permalink
feat: enable terraform import for alerts/views
Browse files Browse the repository at this point in the history
This adds the necessary configuration to view and alert resources
to support `terraform import`.

Ref: LOG-10221
  • Loading branch information
mdeltito committed Jul 21, 2021
1 parent 529d2fa commit 854b57b
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/resources/logdna_alert.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ resource "logdna_alert" "my_alert" {
}
```

## Import

Preset Alerts can be imported by `id`, which can be found in the URL when editing the
Preset Alert in the web UI:

```sh
$ terraform import logdna_alert.your-alert-name <id>
```

Note that only the alert channels supported by this provider will be imported.

## Argument Reference

The following arguments are supported by `logdna_alert`:
Expand Down
11 changes: 11 additions & 0 deletions docs/resources/logdna_view.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ resource "logdna_view" "my_view" {
}
```

## Import

Views can be imported by `id`, which can be found in the URL when editing the
View in the web UI:

```sh
$ terraform import logdna_view.your-view-name <id>
```

Note that only the alert channels supported by this provider will be imported.

## Argument Reference

The following arguments are supported by `logdna_view`:
Expand Down
3 changes: 3 additions & 0 deletions logdna/resource_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ func resourceAlert() *schema.Resource {
ReadContext: resourceAlertRead,
UpdateContext: resourceAlertUpdate,
DeleteContext: resourceAlertDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},

Schema: map[string]*schema.Schema{
"name": {
Expand Down
20 changes: 20 additions & 0 deletions logdna/resource_alert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ func TestAlertBasic(t *testing.T) {
resource.TestCheckResourceAttr("logdna_alert.new", "webhook_channel.#", "0"),
),
},
{
ResourceName: "logdna_alert.new",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -245,6 +250,11 @@ func TestAlertBasicUpdate(t *testing.T) {
resource.TestCheckResourceAttr("logdna_alert.new", "webhook_channel.#", "0"),
),
},
{
ResourceName: "logdna_alert.new",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand All @@ -261,6 +271,11 @@ func TestAlertJSONUpdateError(t *testing.T) {
testAlertExists("logdna_alert.new"),
),
},
{
ResourceName: "logdna_alert.new",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAlertConfigMultipleChannelsInvalidJSON(),
ExpectError: regexp.MustCompile("Error: bodytemplate is not a valid JSON string"),
Expand Down Expand Up @@ -299,6 +314,11 @@ func TestAlertMultipleChannels(t *testing.T) {
resource.TestCheckResourceAttr("logdna_alert.new", "webhook_channel.0.bodytemplate", "{\n \"fields\": {\n \"description\": \"{{ matches }} matches found for {{ name }}\",\n \"issuetype\": {\n \"name\": \"Bug\"\n },\n \"project\": {\n \"key\": \"test\"\n },\n \"summary\": \"Alert From {{ name }}\"\n }\n}"),
),
},
{
ResourceName: "logdna_alert.new",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAlertConfigMultipleChannelsInvalidJSON(),
ExpectError: regexp.MustCompile("Error: bodytemplate is not a valid JSON string"),
Expand Down
3 changes: 3 additions & 0 deletions logdna/resource_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ func resourceView() *schema.Resource {
ReadContext: resourceViewRead,
UpdateContext: resourceViewUpdate,
DeleteContext: resourceViewDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},

Schema: map[string]*schema.Schema{
"apps": {
Expand Down
30 changes: 30 additions & 0 deletions logdna/resource_view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ func TestViewBasic(t *testing.T) {
resource.TestCheckResourceAttr("logdna_view.new", "query", query),
),
},
{
ResourceName: "logdna_view.new",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -279,6 +284,11 @@ func TestViewBasicUpdate(t *testing.T) {
resource.TestCheckResourceAttr("logdna_view.new", "query", query2),
),
},
{
ResourceName: "logdna_view.new",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -306,6 +316,11 @@ func TestViewJSONUpdateError(t *testing.T) {
testViewExists("logdna_view.new"),
),
},
{
ResourceName: "logdna_view.new",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testViewConfigMultipleChannelsInvalidJSON(),
ExpectError: regexp.MustCompile("Error: bodytemplate is not a valid JSON string"),
Expand Down Expand Up @@ -375,6 +390,11 @@ func TestViewBulkEmails(t *testing.T) {
resource.TestCheckResourceAttr("logdna_view.new", "webhook_channels.#", "0"),
),
},
{
ResourceName: "logdna_view.new",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -495,6 +515,11 @@ func TestViewBulkEmailsUpdate(t *testing.T) {
resource.TestCheckResourceAttr("logdna_view.new", "webhook_channels.#", "0"),
),
},
{
ResourceName: "logdna_view.new",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -573,6 +598,11 @@ func TestViewMultipleChannels(t *testing.T) {
resource.TestCheckResourceAttr("logdna_view.new", "webhook_channel.0.url", "https://yourwebhook/endpoint"),
),
},
{
ResourceName: "logdna_view.new",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down

0 comments on commit 854b57b

Please sign in to comment.