Skip to content

Commit 92e0b14

Browse files
authored
Add kibana synthetics http and tcp monitor resources (#699)
Implements #610
1 parent 7773917 commit 92e0b14

File tree

29 files changed

+2317
-194
lines changed

29 files changed

+2317
-194
lines changed

.github/workflows/test.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ jobs:
6060
image: docker.elastic.co/elasticsearch/elasticsearch:${{ matrix.version }}
6161
env:
6262
discovery.type: single-node
63-
xpack.license.self_generated.type: trial
6463
xpack.security.enabled: true
6564
xpack.security.authc.api_key.enabled: true
65+
xpack.security.authc.token.enabled: true
66+
xpack.security.http.ssl.enabled: false
6667
xpack.watcher.enabled: true
68+
xpack.license.self_generated.type: trial
6769
repositories.url.allowed_urls: https://example.com/*
6870
path.repo: /tmp
6971
ELASTIC_PASSWORD: ${{ env.ELASTIC_PASSWORD }}
@@ -78,9 +80,10 @@ jobs:
7880
ELASTICSEARCH_USERNAME: ${{ env.KIBANA_SYSTEM_USERNAME }}
7981
ELASTICSEARCH_PASSWORD: ${{ env.KIBANA_SYSTEM_PASSWORD }}
8082
XPACK_ENCRYPTEDSAVEDOBJECTS_ENCRYPTIONKEY: a7a6311933d3503b89bc2dbc36572c33a6c10925682e591bffcab6911c06786d
81-
xpack.fleet.enabled: true
83+
# LOGGING_ROOT_LEVEL: debug
8284
ports:
8385
- 5601:5601
86+
options: --health-cmd="curl http://localhost:5601/api/status" --health-interval=10s --health-timeout=5s --health-retries=10
8487

8588
timeout-minutes: 15
8689
strategy:
@@ -135,6 +138,12 @@ jobs:
135138
ELASTICSEARCH_USERNAME: "elastic"
136139
ELASTICSEARCH_PASSWORD: ${{ env.ELASTIC_PASSWORD }}
137140

141+
- id: force-install-synthetics
142+
name: Force install synthetics
143+
if: matrix.version == '8.14.3' || matrix.version == '8.15.0'
144+
run: |-
145+
for i in {1..5}; do curl -s -H "Authorization: ApiKey ${{ steps.get-api-key.outputs.apikey }}" --header "Content-Type: application/json" --header "kbn-xsrf: true" --request POST --data '{ "force": true }' http://localhost:5601/api/fleet/epm/packages/synthetics/1.2.2 && break || sleep 15; done
146+
138147
- name: TF acceptance tests
139148
timeout-minutes: 10
140149
run: make testacc

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## [Unreleased]
2+
- Add support for Kibana synthetics http and tcp monitors ([#699](https://github.com/elastic/terraform-provider-elasticstack/pull/699))
23

34
- Add `elasticstack_kibana_spaces` data source ([#682](https://github.com/elastic/terraform-provider-elasticstack/pull/682))
45

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ docker-kibana: docker-network docker-elasticsearch set-kibana-password ## Start
132132
-e ELASTICSEARCH_USERNAME=$(KIBANA_SYSTEM_USERNAME) \
133133
-e ELASTICSEARCH_PASSWORD=$(KIBANA_SYSTEM_PASSWORD) \
134134
-e XPACK_ENCRYPTEDSAVEDOBJECTS_ENCRYPTIONKEY=a7a6311933d3503b89bc2dbc36572c33a6c10925682e591bffcab6911c06786d \
135-
-e "logging.root.level=debug" \
135+
-e LOGGING_ROOT_LEVEL=debug \
136136
--name $(KIBANA_NAME) \
137137
--network $(ELASTICSEARCH_NETWORK) \
138138
docker.elastic.co/kibana/kibana:$(STACK_VERSION); \
@@ -157,7 +157,7 @@ docker-kibana-with-tls: docker-network docker-elasticsearch set-kibana-password
157157
-e SERVER_SSL_CERTIFICATE=/certs/localhost+1.pem \
158158
-e SERVER_SSL_KEY=/certs/localhost+1-key.pem \
159159
-e SERVER_SSL_ENABLED=true \
160-
-e "logging.root.level=debug" \
160+
-e LOGGING_ROOT_LEVEL=debug \
161161
--name $(KIBANA_NAME) \
162162
--network $(ELASTICSEARCH_NETWORK) \
163163
docker.elastic.co/kibana/kibana:$(STACK_VERSION); \
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
---
2+
subcategory: "Kibana"
3+
layout: ""
4+
page_title: "Elasticstack: elasticstack_kibana_synthetics_monitor Resource"
5+
description: |-
6+
Creates or updates a Kibana synthetics monitor.
7+
---
8+
9+
# Resource: elasticstack_kibana_synthetics_monitor
10+
11+
Creates or updates a Kibana synthetics monitor.
12+
See [API docs](https://www.elastic.co/guide/en/kibana/current/add-monitor-api.html)
13+
14+
## Supported monitor types
15+
* `http`
16+
* `tcp`
17+
18+
**NOTE:** Due-to nature of partial update API, reset values to defaults is not supported.
19+
In case you would like to reset an optional monitor value, please set it explicitly or delete and create new monitor.
20+
21+
22+
## Example Usage
23+
24+
```terraform
25+
provider "elasticstack" {
26+
kibana {}
27+
}
28+
29+
resource "elasticstack_kibana_synthetics_monitor" "my_monitor" {
30+
name = "Example http monitor"
31+
space_id = "default"
32+
schedule = 10
33+
locations = ["us_west"]
34+
enabled = false
35+
tags = ["tag"]
36+
alert = {
37+
status = {
38+
enabled = true
39+
}
40+
tls = {
41+
enabled = false
42+
}
43+
}
44+
service_name = "example apm service"
45+
timeout = 30
46+
http = {
47+
url = "http://localhost:8080"
48+
ssl_verification_mode = "full"
49+
ssl_supported_protocols = ["TLSv1.2"]
50+
max_redirects = "10"
51+
mode = "all"
52+
ipv4 = true
53+
ipv6 = true
54+
}
55+
}
56+
```
57+
58+
<!-- schema generated by tfplugindocs -->
59+
## Schema
60+
61+
### Required
62+
63+
- `name` (String) The monitor’s name.
64+
65+
### Optional
66+
67+
- `alert` (Attributes) Alert configuration. Default: `{ status: { enabled: true }, tls: { enabled: true } }`. (see [below for nested schema](#nestedatt--alert))
68+
- `enabled` (Boolean) Whether the monitor is enabled. Default: `true`
69+
- `http` (Attributes) HTTP Monitor specific fields (see [below for nested schema](#nestedatt--http))
70+
- `locations` (List of String) Where to deploy the monitor. Monitors can be deployed in multiple locations so that you can detect differences in availability and response times across those locations.
71+
- `params` (String) Monitor parameters. Raw JSON object, use `jsonencode` function to represent JSON
72+
- `private_locations` (List of String) These Private Locations refer to locations hosted and managed by you, whereas locations are hosted by Elastic. You can specify a Private Location using the location’s name.
73+
- `retest_on_failure` (Boolean) Enable or disable retesting when a monitor fails. By default, monitors are automatically retested if the monitor goes from "up" to "down". If the result of the retest is also "down", an error will be created, and if configured, an alert sent. Then the monitor will resume running according to the defined schedule. Using retest_on_failure can reduce noise related to transient problems. Default: `true`.
74+
- `schedule` (Number) The monitor’s schedule in minutes. Supported values are 1, 3, 5, 10, 15, 30, 60, 120 and 240.
75+
- `service_name` (String) The APM service name.
76+
- `space_id` (String) The namespace field should be lowercase and not contain spaces. The namespace must not include any of the following characters: *, \, /, ?, ", <, >, |, whitespace, ,, #, :, or -. Default: `default`
77+
- `tags` (List of String) An array of tags.
78+
- `tcp` (Attributes) TCP Monitor specific fields (see [below for nested schema](#nestedatt--tcp))
79+
- `timeout` (Number) The monitor timeout in seconds, monitor will fail if it doesn’t complete within this time. Default: `16`
80+
81+
### Read-Only
82+
83+
- `id` (String) Generated identifier for the monitor
84+
85+
<a id="nestedatt--alert"></a>
86+
### Nested Schema for `alert`
87+
88+
Optional:
89+
90+
- `status` (Attributes) (see [below for nested schema](#nestedatt--alert--status))
91+
- `tls` (Attributes) (see [below for nested schema](#nestedatt--alert--tls))
92+
93+
<a id="nestedatt--alert--status"></a>
94+
### Nested Schema for `alert.status`
95+
96+
Optional:
97+
98+
- `enabled` (Boolean)
99+
100+
101+
<a id="nestedatt--alert--tls"></a>
102+
### Nested Schema for `alert.tls`
103+
104+
Optional:
105+
106+
- `enabled` (Boolean)
107+
108+
109+
110+
<a id="nestedatt--http"></a>
111+
### Nested Schema for `http`
112+
113+
Required:
114+
115+
- `url` (String) URL to monitor.
116+
117+
Optional:
118+
119+
- `check` (String) The check request settings.. Raw JSON object, use `jsonencode` function to represent JSON
120+
- `ipv4` (Boolean) Whether to ping using the ipv4 protocol.
121+
- `ipv6` (Boolean) Whether to ping using the ipv6 protocol.
122+
- `max_redirects` (Number) The maximum number of redirects to follow. Default: `0`
123+
- `mode` (String) The mode of the monitor. Can be "all" or "any". If you’re using a DNS-load balancer and want to ping every IP address for the specified hostname, you should use all.
124+
- `password` (String) The password for authenticating with the server. The credentials are passed with the request.
125+
- `proxy_header` (String) Additional headers to send to proxies during CONNECT requests.. Raw JSON object, use `jsonencode` function to represent JSON
126+
- `proxy_url` (String) The URL of the proxy to use for this monitor.
127+
- `response` (String) Controls the indexing of the HTTP response body contents to the `http.response.body.contents` field.. Raw JSON object, use `jsonencode` function to represent JSON
128+
- `ssl_supported_protocols` (List of String) List of allowed SSL/TLS versions.
129+
- `ssl_verification_mode` (String) Controls the verification of server certificates.
130+
- `username` (String) The username for authenticating with the server. The credentials are passed with the request.
131+
132+
133+
<a id="nestedatt--tcp"></a>
134+
### Nested Schema for `tcp`
135+
136+
Required:
137+
138+
- `host` (String) The host to monitor; it can be an IP address or a hostname. The host can include the port using a colon (e.g., "example.com:9200").
139+
140+
Optional:
141+
142+
- `check_receive` (String) The expected answer.
143+
- `check_send` (String) An optional payload string to send to the remote host.
144+
- `proxy_url` (String) The URL of the SOCKS5 proxy to use when connecting to the server. The value must be a URL with a scheme of `socks5://`. If the SOCKS5 proxy server requires client authentication, then a username and password can be embedded in the URL. When using a proxy, hostnames are resolved on the proxy server instead of on the client. You can change this behavior by setting the `proxy_use_local_resolver` option.
145+
- `proxy_use_local_resolver` (Boolean) A Boolean value that determines whether hostnames are resolved locally instead of being resolved on the proxy server. The default value is false, which means that name resolution occurs on the proxy server.
146+
- `ssl_supported_protocols` (List of String) List of allowed SSL/TLS versions.
147+
- `ssl_verification_mode` (String) Controls the verification of server certificates.
148+
149+
## Import
150+
151+
Import is supported using the following syntax:
152+
153+
```shell
154+
terraform import elasticstack_kibana_synthetics_monitor.my_monitor <space id>/<monitor_id>
155+
```
156+
157+
**NOTE:** Not all monitor fields are supported during the import due-to API limitation.
158+
Full field support could be implemented after this [kibana issue](https://github.com/elastic/kibana/issues/189906) is resolved.
159+
160+
Currently not supported fields during the import: `params`, `retest_on_failure`, `http.proxy_header`, `http.username`, `http.password`, `http.check`, `http.response`, `tcp.check_send`, `tcp.check_receive`

docs/resources/kibana_synthetics_private_location.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,5 @@ Required:
7272
Import is supported using the following syntax:
7373

7474
```shell
75-
terraform import elasticstack_kibana_synthetics_private_location.my_location <private_location_id>
75+
terraform import elasticstack_kibana_synthetics_private_location.my_location <space id>/<private_location_id>
7676
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
terraform import elasticstack_kibana_synthetics_monitor.my_monitor <space id>/<monitor_id>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
provider "elasticstack" {
2+
kibana {}
3+
}
4+
5+
resource "elasticstack_kibana_synthetics_monitor" "my_monitor" {
6+
name = "Example http monitor"
7+
space_id = "default"
8+
schedule = 10
9+
locations = ["us_west"]
10+
enabled = false
11+
tags = ["tag"]
12+
alert = {
13+
status = {
14+
enabled = true
15+
}
16+
tls = {
17+
enabled = false
18+
}
19+
}
20+
service_name = "example apm service"
21+
timeout = 30
22+
http = {
23+
url = "http://localhost:8080"
24+
ssl_verification_mode = "full"
25+
ssl_supported_protocols = ["TLSv1.2"]
26+
max_redirects = "10"
27+
mode = "all"
28+
ipv4 = true
29+
ipv6 = true
30+
}
31+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
terraform import elasticstack_kibana_synthetics_private_location.my_location <private_location_id>
1+
terraform import elasticstack_kibana_synthetics_private_location.my_location <space id>/<private_location_id>

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ require (
4949
github.com/hashicorp/logutils v1.0.0 // indirect
5050
github.com/hashicorp/terraform-exec v0.21.0 // indirect
5151
github.com/hashicorp/terraform-json v0.22.1 // indirect
52+
github.com/hashicorp/terraform-plugin-framework-jsontypes v0.1.0 // indirect
5253
github.com/hashicorp/terraform-registry-address v0.2.3 // indirect
5354
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
5455
github.com/hashicorp/yamux v0.1.1 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ github.com/hashicorp/terraform-json v0.22.1 h1:xft84GZR0QzjPVWs4lRUwvTcPnegqlyS7
9090
github.com/hashicorp/terraform-json v0.22.1/go.mod h1:JbWSQCLFSXFFhg42T7l9iJwdGXBYV8fmmD6o/ML4p3A=
9191
github.com/hashicorp/terraform-plugin-framework v1.10.0 h1:xXhICE2Fns1RYZxEQebwkB2+kXouLC932Li9qelozrc=
9292
github.com/hashicorp/terraform-plugin-framework v1.10.0/go.mod h1:qBXLDn69kM97NNVi/MQ9qgd1uWWsVftGSnygYG1tImM=
93+
github.com/hashicorp/terraform-plugin-framework-jsontypes v0.1.0 h1:b8vZYB/SkXJT4YPbT3trzE6oJ7dPyMy68+9dEDKsJjE=
94+
github.com/hashicorp/terraform-plugin-framework-jsontypes v0.1.0/go.mod h1:tP9BC3icoXBz72evMS5UTFvi98CiKhPdXF6yLs1wS8A=
9395
github.com/hashicorp/terraform-plugin-framework-validators v0.13.0 h1:bxZfGo9DIUoLLtHMElsu+zwqI4IsMZQBRRy4iLzZJ8E=
9496
github.com/hashicorp/terraform-plugin-framework-validators v0.13.0/go.mod h1:wGeI02gEhj9nPANU62F2jCaHjXulejm/X+af4PdZaNo=
9597
github.com/hashicorp/terraform-plugin-go v0.23.0 h1:AALVuU1gD1kPb48aPQUjug9Ir/125t+AAurhqphJ2Co=

0 commit comments

Comments
 (0)