Skip to content

Commit 70876d0

Browse files
authored
Merge branch 'main' into vibe-framework
2 parents bda18fd + 1015d90 commit 70876d0

File tree

14 files changed

+475
-320
lines changed

14 files changed

+475
-320
lines changed

.buildkite/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
steps:
22
- label: Release
33
agents:
4-
image: "golang:1.24.3@sha256:4c0a1814a7c6c65ece28b3bfea14ee3cf83b5e80b81418453f0e9d5255a5d7b8"
4+
image: "golang:1.24.4@sha256:20a022e5112a144aa7b7aeb3f22ebf2cdaefcc4aac0d64e8deeee8cdc18b9c0f"
55
cpu: "16"
66
memory: "24G"
77
ephemeralStorage: "20G"

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- Add `headers` for the provider connection ([#1057](https://github.com/elastic/terraform-provider-elasticstack/pull/1057))
44
- Migrate `elasticstack_elasticsearch_system_user` resource to Terraform plugin framework ([#1154](https://github.com/elastic/terraform-provider-elasticstack/pull/1154))
5+
- Add custom `endpoint` configuration support for snapshot repository setup ([#1158](https://github.com/elastic/terraform-provider-elasticstack/pull/1158))
56

67
## [0.11.15] - 2025-04-23
78

CONTRIBUTING.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
Fork the repo, work on an issue
44

5+
## Updating the generated Kibana client.
6+
7+
If you're work involved the Kibana API, the endpoints may or may not be included in the generated client.
8+
Check [generated/kbapi](./generated/kbapi/) for more details.
9+
510
## Acceptance tests
611

712
```bash
@@ -60,4 +65,4 @@ To release a new provider version:
6065
- updates CHANGELOG.md with the list of changes being released.
6166
[Example](https://github.com/elastic/terraform-provider-elasticstack/commit/be866ebc918184e843dc1dd2f6e2e1b963da386d).
6267

63-
* Once the PR merged, the release CI pipeline can be started by pushing a new release tag to `main` branch.
68+
* Once the PR merged, the release CI pipeline can be started by pushing a new release tag to `main` branch.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ tools: $(GOBIN) tools-golangci-lint ## Install useful tools for linting, docs ge
254254

255255
.PHONY: tools-golangci-lint
256256
tools-golangci-lint: ## Download golangci-lint locally if necessary.
257-
@[[ -f $(GOBIN)/golangci-lint ]] || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v2.1.6
257+
@[[ -f $(GOBIN)/golangci-lint ]] || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v2.2.1
258258

259259

260260
.PHONY: misspell

docs/resources/elasticsearch_snapshot_repository.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ Optional:
166166
- `chunk_size` (String) Maximum size of files in snapshots.
167167
- `client` (String) The name of the S3 client to use to connect to S3.
168168
- `compress` (Boolean) If true, metadata files, such as index mappings and settings, are compressed in snapshots.
169+
- `endpoint` (String) Custom S3 service endpoint, useful when using VPC endpoints or non-default S3 URLs.
169170
- `max_restore_bytes_per_sec` (String) Maximum snapshot restore rate per node.
170171
- `max_snapshot_bytes_per_sec` (String) Maximum snapshot creation rate per node.
171172
- `path_style_access` (Boolean) If true, path style access pattern will be used.

generated/kbapi/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Generated Kibana API client
2+
3+
This package includes an API client generated from the Kibana OpenAPI spec.
4+
This client is very much a work in progress, there's opportunity for improvement both within this provider, but also within the OpenAPI spec created during the Kibana build process.
5+
6+
This readme serves to document the status quo, contributions improving this current process are very much welcome.
7+
8+
## Adding new endpoints
9+
10+
There's more detail on the full process below, this section aims to provide a tl;dr to what's required to cover new endpoints in the generated client.
11+
12+
1. `make transform`. This ensures you're starting with the latest API spec. If you encounter issues at this point, at least you know it's not related to any changes you've made :)
13+
1. Add the required API paths to the allow list. See `transformFilterPaths` in `transform_schema.go`. The definition here is straightforward, the path must match exactly what's in the API spec.
14+
1. If endpoints don't use any `oneOf` fields then you're likely done. Run `make transform generate` and start work on the provider resource. Sweeping statements like this tend to be wrong at times, if you encounter issues with the generated client then you'll have to investigate them and may need to define additional transforms.
15+
1. If the endpoints use `oneOf` in the request/response bodies then you'll need to define additional transforms to extract those to reusable components. See `transformKibanaPaths` or `transformFleetPaths` for some examples.
16+
1. `make transform generate` and go test the fresh client.
17+
18+
## Client generation
19+
20+
The actual final Go client generation is relatively straightforward. `make generate` executes [`oapi-codegen`](https://github.com/oapi-codegen/oapi-codegen) which creates `kibana.gen.go` from `oas-filtered.yaml`.
21+
22+
## OpenAPI spec transforms.
23+
24+
This is where the dragons lie.
25+
26+
`make transform` downloads the schema in kibana/main, and passes it through `transform_schema.go`. This transform step aims to patch over:
27+
* Issues with the Kibana schema, any issues we encounter should also be raised in the Kibana repo.
28+
* Issues with oapi-codegen, similarly we should ensure there's a corresponding issue in the oapi-codegen repo.
29+
30+
At a high level, `transform_schema.go`:
31+
* Filters out API paths no in the allow list (see `transformFilterPaths`).
32+
* Removes any `kbnXsrf` parameters. We add this heaer in the client by default. We should look to remove this transform to simplify the overall process.
33+
* Removes the `elastic-api-version` header. We only have a single version at the moment, that said we should remove this transform and properly define this logic within the client.
34+
* Transforms any versioned content types (e.g `application/json; Elastic-Api-Version=2023-10-31`) into plain `application/json`. Similarly to above, the TF provider should properly handle these content types moving forward.
35+
* Ensures Kibana api paths have a `spaceId` parameter (see `transformKibanaPaths`). We should ensure Kibana is correctly including this parameter in any cases where it's required. Not defining this parameter should be seen as a bug in spec generation, not something for clients to work around.
36+
* Extracts nested type definitions to a shared component (see `transformKibanaPaths`). We've encountered issues in oapi-codegen (https://github.com/oapi-codegen/oapi-codegen/issues/1900) where nested, polymorphic types (`oneOf`) create a syntactically invalid API client. To workaround this, `transform_schema` pulls those nested types into re-usable components, and then updated the schema to reference those new types.
37+
* Ultimately the spec is valid here, it would be ideal for oapi-codegen to handle this correctly. That said, this transformation is the most tedious, and complicated in this stack. If we continue to encounter this issue long term we should look to see if it's possible for the Kibana spec generation to create these re-usable types directly.
38+
* Makes several endpoint specific request/response body updates. There are several bugs within some request/response body definitions. These have all been raised as issues in the Kibana repo, in the meantime the transformer is patching the schema to create a working client.
39+
40+
## Possible improvements
41+
42+
These should likely be issues in this repo...
43+
44+
1. Avoid the need for this transformation stuff entirely? It doesn't seem unreasonable to expect the spec provided by Kibana to 'work'. IMO that includes avoiding long standing issues with well used client generators if possible. Anything we can fix within the Kibana repo should be fixed there in preference to adding new transformation code.
45+
1. Migrate the bespoke `transform_schema` to [redocly](https://redocly.com/docs/cli) or oapi-codegen [overlays](https://github.com/oapi-codegen/oapi-codegen?tab=readme-ov-file#modifying-the-input-openapi-specification-with-openapi-overlay). We're reinventing the wheel here. Specifically with the `$ref` issue, if this requires local transformation long term then we should blanket apply this transform to all request/response bodies. That's likely easier done with a well tested tool like redocly than it is with homegrown tooling.
46+
1. Include all paths by default. The barrier here is the high level of transformation required to produce a working client. That's likely reduced substantially since `transform_schema` was introduced and it's likely worth investigation.
47+
1. Remove pointless transforms. Why are we removing examples?

generated/kbapi/transform_schema.go

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,6 @@ var transformers = []TransformFunc{
545545
transformAddMisingDescriptions,
546546
transformKibanaPaths,
547547
transformFleetPaths,
548-
// transformRemoveEnums,
549-
// transformAddGoPointersFlag,
550548
transformRemoveExamples,
551549
transformRemoveUnusedComponents,
552550
}
@@ -1014,22 +1012,6 @@ func transformFleetPaths(schema *Schema) {
10141012
schema.Components.Set("schemas.package_policy_request.properties.output_id.x-omitempty", true)
10151013
}
10161014

1017-
// transformRemoveEnums remove all enums.
1018-
func transformRemoveEnums(schema *Schema) {
1019-
deleteEnumFn := func(key string, node Map) {
1020-
if node.Has("enum") {
1021-
delete(node, "enum")
1022-
}
1023-
}
1024-
1025-
for _, pathInfo := range schema.Paths {
1026-
for _, methInfo := range pathInfo.Endpoints {
1027-
methInfo.Iterate(deleteEnumFn)
1028-
}
1029-
}
1030-
schema.Components.Iterate(deleteEnumFn)
1031-
}
1032-
10331015
// transformRemoveExamples removes all examples.
10341016
func transformRemoveExamples(schema *Schema) {
10351017
deleteExampleFn := func(key string, node Map) {
@@ -1050,27 +1032,6 @@ func transformRemoveExamples(schema *Schema) {
10501032
schema.Components.Set("examples", Map{})
10511033
}
10521034

1053-
// transformAddOptionalPointersFlag adds a x-go-type-skip-optional-pointer
1054-
// flag to maps and arrays, since they are already nullable types.
1055-
func transformAddOptionalPointersFlag(schema *Schema) {
1056-
addFlagFn := func(key string, node Map) {
1057-
if node["type"] == "array" {
1058-
node["x-go-type-skip-optional-pointer"] = true
1059-
} else if node["type"] == "object" {
1060-
if _, ok := node["properties"]; !ok {
1061-
node["x-go-type-skip-optional-pointer"] = true
1062-
}
1063-
}
1064-
}
1065-
1066-
for _, pathInfo := range schema.Paths {
1067-
for _, methInfo := range pathInfo.Endpoints {
1068-
methInfo.Iterate(addFlagFn)
1069-
}
1070-
}
1071-
schema.Components.Iterate(addFlagFn)
1072-
}
1073-
10741035
// transformRemoveUnusedComponents removes all unused schema components.
10751036
func transformRemoveUnusedComponents(schema *Schema) {
10761037
var refs map[string]any

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ module github.com/elastic/terraform-provider-elasticstack
22

33
go 1.23.0
44

5-
toolchain go1.24.3
5+
toolchain go1.24.4
66

77
require (
88
github.com/disaster37/go-kibana-rest/v8 v8.5.0
99
github.com/elastic/elastic-transport-go/v8 v8.7.0
10-
github.com/elastic/go-elasticsearch/v8 v8.18.0
10+
github.com/elastic/go-elasticsearch/v8 v8.18.1
1111
github.com/google/gofuzz v1.2.0
1212
github.com/google/uuid v1.6.0
1313
github.com/hashicorp/go-cty v1.5.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
2424
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2525
github.com/elastic/elastic-transport-go/v8 v8.7.0 h1:OgTneVuXP2uip4BA658Xi6Hfw+PeIOod2rY3GVMGoVE=
2626
github.com/elastic/elastic-transport-go/v8 v8.7.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk=
27-
github.com/elastic/go-elasticsearch/v8 v8.18.0 h1:ANNq1h7DEiPUaALb8+5w3baQzaS08WfHV0DNzp0VG4M=
28-
github.com/elastic/go-elasticsearch/v8 v8.18.0/go.mod h1:WLqwXsJmQoYkoA9JBFeEwPkQhCfAZuUvfpdU/NvSSf0=
27+
github.com/elastic/go-elasticsearch/v8 v8.18.1 h1:lPsN2Wk6+QqBeD4ckmOax7G/Y8tAZgroDYG8j6/5Ce0=
28+
github.com/elastic/go-elasticsearch/v8 v8.18.1/go.mod h1:F3j9e+BubmKvzvLjNui/1++nJuJxbkhHefbaT0kFKGY=
2929
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
3030
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
3131
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=

internal/elasticsearch/cluster/snapshot_repository.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package cluster
33
import (
44
"context"
55
"fmt"
6+
"net/url"
67
"reflect"
78
"regexp"
89
"strconv"
10+
"strings"
911

1012
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
1113
"github.com/elastic/terraform-provider-elasticstack/internal/clients/elasticsearch"
@@ -144,6 +146,13 @@ func ResourceSnapshotRepository() *schema.Resource {
144146
Type: schema.TypeString,
145147
Required: true,
146148
},
149+
"endpoint": {
150+
Description: "Custom S3 service endpoint, useful when using VPC endpoints or non-default S3 URLs.",
151+
Type: schema.TypeString,
152+
Optional: true,
153+
Computed: true,
154+
ValidateFunc: validateURLEndpoint,
155+
},
147156
"client": {
148157
Description: "The name of the S3 client to use to connect to S3.",
149158
Type: schema.TypeString,
@@ -466,3 +475,21 @@ func resourceSnapRepoDelete(ctx context.Context, d *schema.ResourceData, meta in
466475
}
467476
return diags
468477
}
478+
479+
func validateURLEndpoint(val interface{}, key string) ([]string, []error) {
480+
v := val.(string)
481+
if v == "" {
482+
return nil, nil
483+
}
484+
485+
parsed, err := url.ParseRequestURI(v)
486+
if err != nil || parsed.Scheme == "" || parsed.Host == "" {
487+
return nil, []error{fmt.Errorf("%q must be a valid HTTP/HTTPS URL, got: %q", key, v)}
488+
}
489+
490+
if !strings.HasPrefix(v, "http://") && !strings.HasPrefix(v, "https://") {
491+
return nil, []error{fmt.Errorf("%q must start with http:// or https://, got: %q", key, v)}
492+
}
493+
494+
return nil, nil
495+
}

0 commit comments

Comments
 (0)