Skip to content

feat(synthetics): support for private location resource #696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
- '8.11.4'
- '8.12.2'
- '8.13.4'
- '8.14.0'
- '8.14.3'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Fix setting `id` for Fleet outputs and servers ([#666](https://github.com/elastic/terraform-provider-elasticstack/pull/666))
- Fix `elasticstack_fleet_enrollment_tokens` returning empty tokens in some case ([#683](https://github.com/elastic/terraform-provider-elasticstack/pull/683))
- Add support for Kibana synthetics private locations ([#696](https://github.com/elastic/terraform-provider-elasticstack/pull/696))

## [0.11.4] - 2024-06-13

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ testacc: ## Run acceptance tests
test: ## Run unit tests
go test -v $(TEST) $(TESTARGS) -timeout=5m -parallel=4

# Retry command - first argumment is how many attempts are required, second argument is the command to run
# Backoff starts with 1 second and double with next itteration
# Retry command - first argument is how many attempts are required, second argument is the command to run
# Backoff starts with 1 second and double with next iteration
retry = until [ $$(if [ -z "$$attempt" ]; then echo -n "0"; else echo -n "$$attempt"; fi) -ge $(1) ]; do \
backoff=$$(if [ -z "$$backoff" ]; then echo "1"; else echo "$$backoff"; fi); \
sleep $$backoff; \
Expand Down
76 changes: 76 additions & 0 deletions docs/resources/kibana_synthetics_private_location
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
subcategory: "Kibana"
layout: ""
page_title: "Elasticstack: elasticstack_kibana_synthetics_private_location Resource"
description: |-
Creates or updates a Kibana synthetics private location.
---

# Resource: elasticstack_kibana_synthetics_private_location

Creates or updates a Kibana synthetics private location.
See [Monitor via a private agent](https://www.elastic.co/guide/en/observability/current/synthetics-private-location.html#monitor-via-private-agent)
and [api docs](https://www.elastic.co/guide/en/kibana/current/create-private-location-api.html)

## Example Usage

```terraform
provider "elasticstack" {
fleet {}
kibana {}
}

resource "elasticstack_fleet_agent_policy" "sample" {
name = "Sample Agent Policy"
namespace = "default"
description = "A sample agent policy"
monitor_logs = true
monitor_metrics = true
skip_destroy = false
}

resource "elasticstack_kibana_synthetics_private_location" "example" {
label = "example label"
space_id = "default"
agent_policy_id = elasticstack_fleet_agent_policy.sample.policy_id
tags = ["tag-a", "tag-b"]
geo = {
lat = 40.7128
lon = 74.0060
}
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `agent_policy_id` (String) The ID of the agent policy associated with the private location. To create a private location for synthetics monitor you need to create an agent policy in fleet and use its agentPolicyId
- `label` (String) A label for the private location, used as unique identifier

### Optional

- `geo` (Attributes) Geographic coordinates (WGS84) for the location (see [below for nested schema](#nestedatt--geo))
- `space_id` (String) An identifier for the space. If space_id is not provided, the default space is used.
- `tags` (List of String) An array of tags to categorize the private location.

### Read-Only

- `id` (String) Generated id for the private location. For monitor setup please use private location label.

<a id="nestedatt--geo"></a>
### Nested Schema for `geo`

Required:

- `lat` (Number) The latitude of the location.
- `lon` (Number) The longitude of the location.

## Import

Import is supported using the following syntax:

```shell
terraform import elasticstack_kibana_synthetics_private_location.my_location <private_location_id>
```
74 changes: 74 additions & 0 deletions docs/resources/kibana_synthetics_private_location.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "elasticstack_kibana_synthetics_private_location Resource - terraform-provider-elasticstack"
subcategory: ""
description: |-
Synthetics private location config, see https://www.elastic.co/guide/en/kibana/current/create-private-location-api.html for more details
---

# elasticstack_kibana_synthetics_private_location (Resource)

Synthetics private location config, see https://www.elastic.co/guide/en/kibana/current/create-private-location-api.html for more details

## Example Usage

```terraform
provider "elasticstack" {
fleet {}
kibana {}
}

resource "elasticstack_fleet_agent_policy" "sample" {
name = "Sample Agent Policy"
namespace = "default"
description = "A sample agent policy"
monitor_logs = true
monitor_metrics = true
skip_destroy = false
}

resource "elasticstack_kibana_synthetics_private_location" "example" {
label = "example label"
space_id = "default"
agent_policy_id = elasticstack_fleet_agent_policy.sample.policy_id
tags = ["tag-a", "tag-b"]
geo = {
lat = 40.7128
lon = 74.0060
}
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `agent_policy_id` (String) The ID of the agent policy associated with the private location. To create a private location for synthetics monitor you need to create an agent policy in fleet and use its agentPolicyId
- `label` (String) A label for the private location, used as unique identifier

### Optional

- `geo` (Attributes) Geographic coordinates (WGS84) for the location (see [below for nested schema](#nestedatt--geo))
- `space_id` (String) An identifier for the space. If space_id is not provided, the default space is used.
- `tags` (List of String) An array of tags to categorize the private location.

### Read-Only

- `id` (String) Generated id for the private location. For monitor setup please use private location label.

<a id="nestedatt--geo"></a>
### Nested Schema for `geo`

Required:

- `lat` (Number) The latitude of the location.
- `lon` (Number) The longitude of the location.

## Import

Import is supported using the following syntax:

```shell
terraform import elasticstack_kibana_synthetics_private_location.my_location <private_location_id>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import elasticstack_kibana_synthetics_private_location.my_location <private_location_id>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
provider "elasticstack" {
fleet {}
kibana {}
}

resource "elasticstack_fleet_agent_policy" "sample" {
name = "Sample Agent Policy"
namespace = "default"
description = "A sample agent policy"
monitor_logs = true
monitor_metrics = true
skip_destroy = false
}

resource "elasticstack_kibana_synthetics_private_location" "example" {
label = "example label"
space_id = "default"
agent_policy_id = elasticstack_fleet_agent_policy.sample.policy_id
tags = ["tag-a", "tag-b"]
geo = {
lat = 40.7128
lon = 74.0060
}
}
8 changes: 6 additions & 2 deletions internal/clients/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,12 @@ func buildKibanaClient(cfg config.Client) (*kibana.Client, error) {

if logging.IsDebugOrHigher() {
// Don't use kib.Client.SetDebug() here as we re-use the http client within the OpenAPI generated clients
kibHttpClient := kib.Client.GetClient()
kibHttpClient.Transport = utils.NewDebugTransport("Kibana", kibHttpClient.Transport)
transport, err := kib.Client.Transport()
if err != nil {
return nil, err
}
var roundTripper http.RoundTripper = utils.NewDebugTransport("Kibana", transport)
kib.Client.SetTransport(roundTripper)
}

return kib, nil
Expand Down
Loading