Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [Unreleased]

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

## [0.11.15] - 2025-04-23

Expand Down
1 change: 1 addition & 0 deletions docs/resources/elasticsearch_snapshot_repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ Optional:
- `chunk_size` (String) Maximum size of files in snapshots.
- `client` (String) The name of the S3 client to use to connect to S3.
- `compress` (Boolean) If true, metadata files, such as index mappings and settings, are compressed in snapshots.
- `endpoint` (String) Custom S3 service endpoint, useful when using VPC endpoints or non-default S3 URLs.
- `max_restore_bytes_per_sec` (String) Maximum snapshot restore rate per node.
- `max_snapshot_bytes_per_sec` (String) Maximum snapshot creation rate per node.
- `path_style_access` (Boolean) If true, path style access pattern will be used.
Expand Down
27 changes: 27 additions & 0 deletions internal/elasticsearch/cluster/snapshot_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package cluster
import (
"context"
"fmt"
"net/url"
"reflect"
"regexp"
"strconv"
"strings"

"github.com/elastic/terraform-provider-elasticstack/internal/clients"
"github.com/elastic/terraform-provider-elasticstack/internal/clients/elasticsearch"
Expand Down Expand Up @@ -144,6 +146,13 @@ func ResourceSnapshotRepository() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"endpoint": {
Description: "Custom S3 service endpoint, useful when using VPC endpoints or non-default S3 URLs.",
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validateURLEndpoint,
},
"client": {
Description: "The name of the S3 client to use to connect to S3.",
Type: schema.TypeString,
Expand Down Expand Up @@ -466,3 +475,21 @@ func resourceSnapRepoDelete(ctx context.Context, d *schema.ResourceData, meta in
}
return diags
}

func validateURLEndpoint(val interface{}, key string) ([]string, []error) {
v := val.(string)
if v == "" {
return nil, nil
}

parsed, err := url.ParseRequestURI(v)
if err != nil || parsed.Scheme == "" || parsed.Host == "" {
return nil, []error{fmt.Errorf("%q must be a valid HTTP/HTTPS URL, got: %q", key, v)}
}

if !strings.HasPrefix(v, "http://") && !strings.HasPrefix(v, "https://") {
return nil, []error{fmt.Errorf("%q must start with http:// or https://, got: %q", key, v)}
}

return nil, nil
}
Loading