elastic / elastic/terraform-provider-elasticstack
[Feature] Add kibana_spaces support to elasticstack_kibana_synthetics_monitor
- Dominant language
- Go
- Stars
- 209
- Forks
- 150
- Avg merge
- 23h 11m
- Merged PRs (30d)
- 169
Description
**Is your feature request related to a problem? Please describe.**
Synthetic monitors can only be assigned to a single Kibana space via the `space_id` attribute. The Kibana UI and API support sharing a monitor across multiple spaces using the `spaces` / `kibana_spaces` field (which maps to saved object `initialNamespaces`), but the Terraform provider doesn't expose this. This means users who need a monitor visible in multiple spaces must either duplicate the monitor or manage sharing out-of-band via API calls after `terraform apply`.
**Describe the resource you would like to have implemented.**
The Kibana Synthetics Monitor API ([Add Monitor API](https://www.elastic.co/guide/en/kibana/current/add-monitor-api.html)) accepts a `spaces` field (array of strings) in the request body. Internally this is stored as `ConfigKey.KIBANA_SPACES` and sets `initialNamespaces` on the saved object, allowing the monitor to appear in multiple Kibana spaces without duplication.
Relevant Kibana source:
- `x-pack/solutions/observability/plugins/synthetics/server/services/monitor_config_repository.ts` — uses `initialNamespaces: spaces` on saved object creation
- `x-pack/solutions/observability/plugins/synthetics/server/routes/monitor_cruds/edit_monitor.ts` — handles `KIBANA_SPACES` on update
- A wildcard value `["*"]` shares to all spaces
**Describe the solution you'd like**
Add an optional `kibana_spaces` attribute (list of strings) to `elasticstack_kibana_synthetics_monitor`:
```hcl
resource "elasticstack_kibana_synthetics_monitor" "my_monitor" {
name = "My Monitor"
space_id = "y"
kibana_spaces = ["y", "infrastructure"]
# ... other fields
}
```
When `kibana_spaces` is set, the provider should include the `spaces` field in the Kibana API request body. The `space_id` remains the "owner" space for the API endpoint path, while `kibana_spaces` controls visibility. A value of `["*"]` should share to all spaces.
**Describe alternatives you've considered**
- Duplicating monitors in each space (doubles cost, creates drift risk)
- Using a `null_resource` with `local-exec` to call the Kibana API after monitor creation (fragile, out-of-band state)
- Using `elasticstack_kibana_import_saved_objects` to copy the monitor SO to additional spaces (doesn't maintain sharing link)
**Additional context**
- Provider version tested: `0.14.4`
- Latest provider version checked: `0.15.2` (still missing this field)
- Kibana versions with this feature: 8.x+
- The Kibana UI exposes this under "Advanced > Kibana Spaces" in the monitor edit form
Contributor guide
No contributing guide indexed for this repository
Research direction
Locate the implementation and tests for the elasticstack_kibana_synthetics_monitor resource, then compare its request construction with the Kibana paths named in the issue: monitor_config_repository.ts and edit_monitor.ts. Done means an optional kibana_spaces list is accepted, sent as spaces while space_id remains the owner path, and supports the ["*"] wildcard.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, terraform
- Domain
- infrastructure, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100