Skip to content

Commit 6ea1d5e

Browse files
authored
Support for custom endpoint configuration in snapshot repository setup (elastic#1158)
* Support for custom endpoint configuration in snapshot repository setup Related to issue elastic#1096 * Update docs with newly introduced arrtibute
1 parent 6da3fb2 commit 6ea1d5e

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## [Unreleased]
22

33
- Add `headers` for the provider connection ([#1057](https://github.com/elastic/terraform-provider-elasticstack/pull/1057))
4+
- Add custom `endpoint` configuration support for snapshot repository setup ([#1158](https://github.com/elastic/terraform-provider-elasticstack/pull/1158))
45

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

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.

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)