Skip to content

Commit

Permalink
feat: Add support for setting check attributes
Browse files Browse the repository at this point in the history
Issue #6
  • Loading branch information
MatthewJohn committed Aug 11, 2023
1 parent 3424e06 commit e6d5328
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
24 changes: 16 additions & 8 deletions jmon/resource_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ import (
)

type CheckData struct {
Name string `yaml:"name"`
Environment string `yaml:"environment,omitempty"`
Steps []interface{} `yaml:"steps"`
ScreenshotOnError bool `yaml:"screenshot_on_error,omitempty"`
Interval int `yaml:"interval,omitempty"`
Timeout int `yaml:"timeout,omitempty"`
Client string `yaml:"client,omitempty"`
Enable bool `yaml:"enable,omitempty"`
Name string `yaml:"name"`
Environment string `yaml:"environment,omitempty"`
Steps []interface{} `yaml:"steps"`
ScreenshotOnError bool `yaml:"screenshot_on_error,omitempty"`
Interval int `yaml:"interval,omitempty"`
Timeout int `yaml:"timeout,omitempty"`
Client string `yaml:"client,omitempty"`
Enable bool `yaml:"enable,omitempty"`
Attributes map[string]interface{} `yaml:"attributes,omitempty"`
}

func resourceCheck() *schema.Resource {
Expand Down Expand Up @@ -75,6 +76,11 @@ func resourceCheck() *schema.Resource {
Optional: true,
Computed: true,
},
"attributes": &schema.Schema{
Type: schema.TypeMap,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
},
},
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
Expand Down Expand Up @@ -116,6 +122,7 @@ func upsertCheck(d *schema.ResourceData, m interface{}, check *CheckData) error
check.ScreenshotOnError = d.Get("screenshot_on_error").(bool)
check.Client = d.Get("client").(string)
check.Enable = d.Get("enable").(bool)
check.Attributes = d.Get("attributes").(map[string]interface{})

// Convert steps YAML to interface in check object
ymlErr := yaml.Unmarshal([]byte(d.Get("steps").(string)), &check.Steps)
Expand Down Expand Up @@ -285,6 +292,7 @@ func resourceCheckRead(ctx context.Context, d *schema.ResourceData, m interface{
d.Set("steps", string(stepsString))
d.Set("screenshot_on_error", check.ScreenshotOnError)
d.Set("enable", check.Enable)
d.Set("attributes", check.Attributes)

return diags
}
Expand Down
4 changes: 4 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ resource "jmon_check" "full_check" {
EOF

interval = 20

attributes = {
notification_slack_channel = "test"
}
}

provider "jmon" {
Expand Down

0 comments on commit e6d5328

Please sign in to comment.