Skip to content
Merged
Changes from 1 commit
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
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