Skip to content

Commit

Permalink
feat: suport versioned runtime in checks/groups (runtime_id)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignacio Anaya committed Jul 13, 2021
1 parent 41b999e commit 5c12d8d
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 11 deletions.
19 changes: 19 additions & 0 deletions checkly/resource_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ func resourceCheck() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"runtime_id": {
Type: schema.TypeString,
Optional: true,
Default: nil,
},
"alert_channel_subscription": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -438,10 +443,16 @@ func resourceDataFromCheck(c *checkly.Check, d *schema.ResourceData) error {
d.Set("teardown_snippet_id", c.TearDownSnippetID)
d.Set("local_setup_script", c.LocalSetupScript)
d.Set("local_teardown_script", c.LocalTearDownScript)

if c.RuntimeID != nil {
d.Set("runtime_id", *c.RuntimeID)
}

if err := d.Set("alert_settings", setFromAlertSettings(c.AlertSettings)); err != nil {
return fmt.Errorf("error setting alert settings for resource %s: %w", d.Id(), err)
}
d.Set("use_global_alert_settings", c.UseGlobalAlertSettings)

if c.Type == checkly.TypeAPI {
err := d.Set("request", setFromRequest(c.Request))
if err != nil {
Expand Down Expand Up @@ -567,6 +578,14 @@ func checkFromResourceData(d *schema.ResourceData) (checkly.Check, error) {
GroupOrder: d.Get("group_order").(int),
AlertChannelSubscriptions: alertChannelSubscriptionsFromSet(d.Get("alert_channel_subscription").([]interface{})),
}

runtimeId := d.Get("runtime_id").(string)
if runtimeId == "" {
check.RuntimeID = nil
} else {
check.RuntimeID = &runtimeId
}

if check.Type == checkly.TypeAPI {
// this will prevent subsequent apply from causing a tf config change in browser checks
check.Request = requestFromSet(d.Get("request").(*schema.Set))
Expand Down
23 changes: 21 additions & 2 deletions checkly/resource_check_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ func resourceCheckGroup() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"runtime_id": {
Type: schema.TypeString,
Optional: true,
Default: nil,
},
"alert_channel_subscription": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -352,6 +357,11 @@ func resourceDataFromCheckGroup(g *checkly.Group, d *schema.ResourceData) error
d.Set("teardown_snippet_id", g.TearDownSnippetID)
d.Set("local_setup_script", g.LocalSetupScript)
d.Set("local_teardown_script", g.LocalTearDownScript)

if g.RuntimeID != nil {
d.Set("runtime_id", *g.RuntimeID)
}

if err := d.Set("alert_settings", setFromAlertSettings(g.AlertSettings)); err != nil {
return fmt.Errorf("error setting alert settings for resource %s: %s", d.Id(), err)
}
Expand All @@ -372,7 +382,7 @@ func checkGroupFromResourceData(d *schema.ResourceData) (checkly.Group, error) {
}
ID = 0
}
return checkly.Group{
group := checkly.Group{
ID: ID,
Name: d.Get("name").(string),
Concurrency: d.Get("concurrency").(int),
Expand All @@ -390,7 +400,16 @@ func checkGroupFromResourceData(d *schema.ResourceData) (checkly.Group, error) {
UseGlobalAlertSettings: d.Get("use_global_alert_settings").(bool),
APICheckDefaults: apiCheckDefaultsFromSet(d.Get("api_check_defaults").(*schema.Set)),
AlertChannelSubscriptions: alertChannelSubscriptionsFromSet(d.Get("alert_channel_subscription").([]interface{})),
}, nil
}

runtimeId := d.Get("runtime_id").(string)
if runtimeId == "" {
group.RuntimeID = nil
} else {
group.RuntimeID = &runtimeId
}

return group, nil
}

func setFromAPICheckDefaults(a checkly.APICheckDefaults) []tfMap {
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/alert-channel.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# checkly_alert_channel
The `checkly_alert_channel` resource allows users to manage checkly Alert Channels.
The `checkly_alert_channel` resource allows users to manage Checkly alert channels.

Checkly's Alert Channels feature allows you to define global alerting channels for the checks in your account:

Expand Down
5 changes: 4 additions & 1 deletion docs/resources/check.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# checkly_check
`checkly_check` allows users to manage checkly checks. Add a `checkly_check` resource to your resource file.
`checkly_check` allows users to manage Checkly checks. Add a `checkly_check` resource to your resource file.

## Example Usage - API checks
This first example is a very minimal **API check**.
Expand Down Expand Up @@ -123,6 +123,8 @@ resource "checkly_check" "browser-check-1" {
"us-west-1"
]
runtime_id = "2021.06"
script = <<EOT
const assert = require("chai").assert;
const puppeteer = require("puppeteer");
Expand Down Expand Up @@ -230,6 +232,7 @@ The following arguments are supported:
* `group_order` (Optional) The position of this check in a check group. It determines in what order checks are run when a group is triggered from the API or from CI/CD.
* `request` (Optional). An API check might have one request config. Supported values documented below.
* `alert_settings` (Optional). Supported values documented below.
* `runtime_id` (Optional). The id of the runtime to use for this check.

### Argument Reference: request
The `request` section is added to API checks and supports the following:
Expand Down
3 changes: 2 additions & 1 deletion docs/resources/check_group.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# checkly_check_group
The `checkly_check_group` resource allows users to manage checkly Check Groups.
The `checkly_check_group` resource allows users to manage Checkly check groups.

Checkly's groups feature allows you to group together a set of related checks, which can also share default settings for various attributes. Here is an example check group:

Expand Down Expand Up @@ -154,6 +154,7 @@ resource "checkly_check_group" "test-group1" {
* `use_global_alert_settings` (Optional) When true, the account level alert setting will be used, not the alert setting defined on this check group.
* `api_check_defaults` (Optional) Default configs to use for all api checks belonging to this group. Supported values documented below.
* `alert_settings` (Optional). Supported values documented below.
* `runtime_id` (Optional). The id of the runtime to use for this group.


### Argument Reference: api_check_defaults
Expand Down
8 changes: 4 additions & 4 deletions docs/resources/snippet.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# checkly_snippet
`checkly_snippet` allows users to manage checkly snippets. Add a `checkly_snippet` resource to your resource file.
`checkly_snippet` allows users to manage Checkly snippets. Add a `checkly_snippet` resource to your resource file.

## Example Usage

```terraform
Expand Down Expand Up @@ -35,7 +35,7 @@ resource "checkly_snippet" "example-3" {
}
```

## Argument Reference
## Argument Reference
The following arguments are supported:
* `name` - (Required) The name of the snippet.
* `name` - (Required) The name of the snippet.
* `script` - (Required) Your Node.js code that interacts with the API check lifecycle, or functions as a partial for browser checks.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,3 @@ require (
github.com/zclconf/go-cty v1.4.2 // indirect
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980 // indirect
)

// replace github.com/checkly/checkly-go-sdk => ../checkly-go-sdk
2 changes: 2 additions & 0 deletions test.tf
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ resource "checkly_check" "browser-check-1" {
"us-west-1"
]

runtime_id = "2020.01"

script = <<EOT
const assert = require("chai").assert;
const puppeteer = require("puppeteer");
Expand Down

0 comments on commit 5c12d8d

Please sign in to comment.