Skip to content

Commit 2dcab54

Browse files
authored
add traceroute checktype to synthetic_monitoring_check resource (#327)
1 parent 1fd2caa commit 2dcab54

File tree

6 files changed

+206
-0
lines changed

6 files changed

+206
-0
lines changed

docs/resources/synthetic_monitoring_check.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,57 @@ EOS
355355
}
356356
```
357357

358+
### Traceroute Basic
359+
360+
```terraform
361+
data "grafana_synthetic_monitoring_probes" "main" {}
362+
363+
resource "grafana_synthetic_monitoring_check" "traceroute" {
364+
job = "Traceroute defaults"
365+
target = "grafana.com"
366+
enabled = false
367+
frequency = 120000
368+
timeout = 30000
369+
probes = [
370+
data.grafana_synthetic_monitoring_probes.main.probes.Atlanta,
371+
]
372+
labels = {
373+
foo = "bar"
374+
}
375+
settings {
376+
traceroute {}
377+
}
378+
}
379+
```
380+
381+
### Traceroute Complex
382+
383+
```terraform
384+
data "grafana_synthetic_monitoring_probes" "main" {}
385+
386+
resource "grafana_synthetic_monitoring_check" "traceroute" {
387+
job = "Traceroute complex"
388+
target = "grafana.net"
389+
enabled = false
390+
frequency = 120000
391+
timeout = 30000
392+
probes = [
393+
data.grafana_synthetic_monitoring_probes.main.probes.Chicago,
394+
data.grafana_synthetic_monitoring_probes.main.probes.LosAngeles,
395+
]
396+
labels = {
397+
foo = "baz"
398+
}
399+
settings {
400+
traceroute {
401+
max_hops = 25
402+
max_unknown_hops = 10
403+
ptr_lookup = false
404+
}
405+
}
406+
}
407+
```
408+
358409
<!-- schema generated by tfplugindocs -->
359410
## Schema
360411

@@ -388,6 +439,7 @@ Optional:
388439
- **http** (Block Set, Max: 1) Settings for HTTP check. The target must be a URL (http or https). (see [below for nested schema](#nestedblock--settings--http))
389440
- **ping** (Block Set, Max: 1) Settings for ping (ICMP) check. The target must be a valid hostname or IP address. (see [below for nested schema](#nestedblock--settings--ping))
390441
- **tcp** (Block Set, Max: 1) Settings for TCP check. The target must be of the form `<host>:<port>`, where the host portion must be a valid hostname or IP address. (see [below for nested schema](#nestedblock--settings--tcp))
442+
- **traceroute** (Block Set, Max: 1) Settings for traceroute check. The target must be a valid hostname or IP address (see [below for nested schema](#nestedblock--settings--traceroute))
391443

392444
<a id="nestedblock--settings--dns"></a>
393445
### Nested Schema for `settings.dns`
@@ -552,3 +604,14 @@ Optional:
552604
- **server_name** (String) Used to verify the hostname for the targets.
553605

554606

607+
608+
<a id="nestedblock--settings--traceroute"></a>
609+
### Nested Schema for `settings.traceroute`
610+
611+
Optional:
612+
613+
- **max_hops** (Number) Maximum TTL for the trace Defaults to `64`.
614+
- **max_unknown_hops** (Number) Maximum number of hosts to travers that give no response Defaults to `15`.
615+
- **ptr_lookup** (Boolean) Reverse lookup hostnames from IP addresses Defaults to `true`.
616+
617+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
data "grafana_synthetic_monitoring_probes" "main" {}
2+
3+
resource "grafana_synthetic_monitoring_check" "traceroute" {
4+
job = "Traceroute defaults"
5+
target = "grafana.com"
6+
enabled = false
7+
frequency = 120000
8+
timeout = 30000
9+
probes = [
10+
data.grafana_synthetic_monitoring_probes.main.probes.Atlanta,
11+
]
12+
labels = {
13+
foo = "bar"
14+
}
15+
settings {
16+
traceroute {}
17+
}
18+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
data "grafana_synthetic_monitoring_probes" "main" {}
2+
3+
resource "grafana_synthetic_monitoring_check" "traceroute" {
4+
job = "Traceroute complex"
5+
target = "grafana.net"
6+
enabled = false
7+
frequency = 120000
8+
timeout = 30000
9+
probes = [
10+
data.grafana_synthetic_monitoring_probes.main.probes.Chicago,
11+
data.grafana_synthetic_monitoring_probes.main.probes.LosAngeles,
12+
]
13+
labels = {
14+
foo = "baz"
15+
}
16+
settings {
17+
traceroute {
18+
max_hops = 25
19+
max_unknown_hops = 10
20+
ptr_lookup = false
21+
}
22+
}
23+
}

grafana/resource_synthetic_monitoring_check.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ var (
9393
MaxItems: 1,
9494
Elem: syntheticMonitoringCheckSettingsTCP,
9595
},
96+
"traceroute": {
97+
Description: "Settings for traceroute check. The target must be a valid hostname or IP address",
98+
Type: schema.TypeSet,
99+
Optional: true,
100+
MaxItems: 1,
101+
Elem: syntheticMonitoringCheckSettingsTraceroute,
102+
},
96103
},
97104
}
98105

@@ -394,6 +401,29 @@ var (
394401
},
395402
},
396403
}
404+
405+
syntheticMonitoringCheckSettingsTraceroute = &schema.Resource{
406+
Schema: map[string]*schema.Schema{
407+
"max_hops": {
408+
Description: "Maximum TTL for the trace",
409+
Type: schema.TypeInt,
410+
Optional: true,
411+
Default: 64,
412+
},
413+
"max_unknown_hops": {
414+
Description: "Maximum number of hosts to travers that give no response",
415+
Type: schema.TypeInt,
416+
Optional: true,
417+
Default: 15,
418+
},
419+
"ptr_lookup": {
420+
Description: "Reverse lookup hostnames from IP addresses",
421+
Type: schema.TypeBool,
422+
Optional: true,
423+
Default: true,
424+
},
425+
},
426+
}
397427
)
398428

399429
func resourceSyntheticMonitoringCheck() *schema.Resource {
@@ -700,6 +730,20 @@ func resourceSyntheticMonitoringCheckRead(ctx context.Context, d *schema.Resourc
700730
settings.Add(map[string]interface{}{
701731
"tcp": tcp,
702732
})
733+
case chk.Settings.Traceroute != nil:
734+
traceroute := schema.NewSet(
735+
schema.HashResource(syntheticMonitoringCheckSettingsTraceroute),
736+
[]interface{}{},
737+
)
738+
739+
traceroute.Add(map[string]interface{}{
740+
"max_hops": int(chk.Settings.Traceroute.MaxHops),
741+
"max_unknown_hops": int(chk.Settings.Traceroute.MaxUnknownHops),
742+
"ptr_lookup": chk.Settings.Traceroute.PtrLookup,
743+
})
744+
settings.Add(map[string]interface{}{
745+
"traceroute": traceroute,
746+
})
703747
}
704748

705749
d.Set("settings", settings)
@@ -899,5 +943,15 @@ func makeCheckSettings(settings map[string]interface{}) sm.CheckSettings {
899943
}
900944
}
901945

946+
traceroute := settings["traceroute"].(*schema.Set).List()
947+
if len(traceroute) > 0 {
948+
t := traceroute[0].(map[string]interface{})
949+
cs.Traceroute = &sm.TracerouteSettings{
950+
MaxHops: int64(t["max_hops"].(int)),
951+
MaxUnknownHops: int64(t["max_unknown_hops"].(int)),
952+
PtrLookup: t["ptr_lookup"].(bool),
953+
}
954+
}
955+
902956
return cs
903957
}

grafana/resource_synthetic_monitoring_check_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,43 @@ func TestAccResourceSyntheticMonitoringCheck_tcp(t *testing.T) {
199199
},
200200
})
201201
}
202+
203+
func TestAccResourceSyntheticMonitoringCheck_traceroute(t *testing.T) {
204+
CheckCloudTestsEnabled(t)
205+
206+
resource.Test(t, resource.TestCase{
207+
PreCheck: func() { testAccPreCheckCloud(t) },
208+
ProviderFactories: testAccProviderFactories,
209+
Steps: []resource.TestStep{
210+
{
211+
Config: testAccExample(t, "resources/grafana_synthetic_monitoring_check/traceroute_basic.tf"),
212+
Check: resource.ComposeTestCheckFunc(
213+
resource.TestCheckResourceAttrSet("grafana_synthetic_monitoring_check.traceroute", "id"),
214+
resource.TestCheckResourceAttrSet("grafana_synthetic_monitoring_check.traceroute", "tenant_id"),
215+
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.traceroute", "job", "Traceroute defaults"),
216+
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.traceroute", "target", "grafana.com"),
217+
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.traceroute", "probes.0", "1"),
218+
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.traceroute", "labels.foo", "bar"),
219+
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.traceroute", "settings.0.traceroute.0.max_hops", "64"),
220+
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.traceroute", "settings.0.traceroute.0.max_unknown_hops", "15"),
221+
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.traceroute", "settings.0.traceroute.0.ptr_lookup", "true"),
222+
),
223+
},
224+
{
225+
Config: testAccExample(t, "resources/grafana_synthetic_monitoring_check/traceroute_complex.tf"),
226+
Check: resource.ComposeTestCheckFunc(
227+
resource.TestCheckResourceAttrSet("grafana_synthetic_monitoring_check.traceroute", "id"),
228+
resource.TestCheckResourceAttrSet("grafana_synthetic_monitoring_check.traceroute", "tenant_id"),
229+
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.traceroute", "job", "Traceroute complex"),
230+
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.traceroute", "target", "grafana.net"),
231+
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.traceroute", "probes.0", "2"),
232+
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.traceroute", "probes.1", "3"),
233+
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.traceroute", "labels.foo", "baz"),
234+
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.traceroute", "settings.0.traceroute.0.max_hops", "25"),
235+
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.traceroute", "settings.0.traceroute.0.max_unknown_hops", "10"),
236+
resource.TestCheckResourceAttr("grafana_synthetic_monitoring_check.traceroute", "settings.0.traceroute.0.ptr_lookup", "false"),
237+
),
238+
},
239+
},
240+
})
241+
}

templates/resources/synthetic_monitoring_check.md.tmpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ description: |-
4444

4545
{{ tffile "examples/resources/grafana_synthetic_monitoring_check/tcp_complex.tf" }}
4646

47+
### Traceroute Basic
48+
49+
{{ tffile "examples/resources/grafana_synthetic_monitoring_check/traceroute_basic.tf" }}
50+
51+
### Traceroute Complex
52+
53+
{{ tffile "examples/resources/grafana_synthetic_monitoring_check/traceroute_complex.tf" }}
54+
4755
{{ .SchemaMarkdown | trimspace }}
4856

4957
{{ if .HasImport -}}

0 commit comments

Comments
 (0)