@@ -3,9 +3,11 @@ package cluster
33import (
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