From 798483faf252dfd95920d678e0b297c99dce3e65 Mon Sep 17 00:00:00 2001 From: rjeczalik Date: Tue, 6 Aug 2024 17:53:44 +0200 Subject: [PATCH] internal/provider: add optional metadata param (#161) This PR adds a new, optional metadata parameter, which controls whether ScyllaDB Cloud client should fetch deployment metadata prior to issuing API calls. The deployment metadata is used to map various region, instance etc. identifier to human-readable text strings. By default metadata is always on and true. It is safe to turn off the metadata retrieval, when it's known to be not needed - e.g. for Stacks API integration. For regular use of terraform providers user will not need to control this behavior. The main use-case for this new param are automation flows. --- go.mod | 8 ++++---- go.sum | 12 ++++++------ internal/provider/provider.go | 17 ++++++++--------- internal/scylla/client.go | 4 ++-- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index 073a639..e05aa31 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.22 toolchain go1.22.0 require ( - github.com/eapache/go-resiliency v1.6.0 + github.com/eapache/go-resiliency v1.7.0 github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/terraform-plugin-docs v0.18.0 github.com/hashicorp/terraform-plugin-framework v1.10.0 @@ -13,6 +13,7 @@ require ( github.com/hashicorp/terraform-plugin-log v0.9.0 github.com/hashicorp/terraform-plugin-mux v0.16.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0 + golang.org/x/net v0.27.0 sigs.k8s.io/yaml v1.4.0 ) @@ -68,17 +69,16 @@ require ( github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/yuin/goldmark v1.6.0 // indirect github.com/yuin/goldmark-meta v1.1.0 // indirect - github.com/zclconf/go-cty v1.14.4 // indirect + github.com/zclconf/go-cty v1.15.0 // indirect golang.org/x/crypto v0.25.0 // indirect golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect golang.org/x/mod v0.19.0 // indirect - golang.org/x/net v0.27.0 // indirect golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.22.0 // indirect golang.org/x/text v0.16.0 // indirect golang.org/x/tools v0.23.0 // indirect google.golang.org/appengine v1.6.8 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf // indirect google.golang.org/grpc v1.65.0 // indirect google.golang.org/protobuf v1.34.2 // indirect gopkg.in/yaml.v2 v2.3.0 // indirect diff --git a/go.sum b/go.sum index 7fd04d6..1a1ebf3 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,8 @@ github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxG github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/eapache/go-resiliency v1.6.0 h1:CqGDTLtpwuWKn6Nj3uNUdflaq+/kIPsg0gfNzHton30= -github.com/eapache/go-resiliency v1.6.0/go.mod h1:5yPzW0MIvSe0JDsv0v+DvcjEv2FyD6iZYSs1ZI+iQho= +github.com/eapache/go-resiliency v1.7.0 h1:n3NRTnBn5N0Cbi/IeOHuQn9s2UwVUH7Ga0ZWcP+9JTA= +github.com/eapache/go-resiliency v1.7.0/go.mod h1:5yPzW0MIvSe0JDsv0v+DvcjEv2FyD6iZYSs1ZI+iQho= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= @@ -198,8 +198,8 @@ github.com/yuin/goldmark v1.6.0 h1:boZcn2GTjpsynOsC0iJHnBWa4Bi0qzfJjthwauItG68= github.com/yuin/goldmark v1.6.0/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark-meta v1.1.0 h1:pWw+JLHGZe8Rk0EGsMVssiNb/AaPMHfSRszZeUeiOUc= github.com/yuin/goldmark-meta v1.1.0/go.mod h1:U4spWENafuA7Zyg+Lj5RqK/MF+ovMYtBvXi1lBb2VP0= -github.com/zclconf/go-cty v1.14.4 h1:uXXczd9QDGsgu0i/QFR/hzI5NYCHLf6NQw/atrbnhq8= -github.com/zclconf/go-cty v1.14.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= +github.com/zclconf/go-cty v1.15.0 h1:tTCRWxsexYUmtt/wVxgDClUe+uQusuI443uL6e+5sXQ= +github.com/zclconf/go-cty v1.15.0/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo= github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -260,8 +260,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 h1:SbSDUWW1PAO24TNpLdeheoYPd7kllICcLU52x6eD4kQ= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf h1:liao9UHurZLtiEwBgT9LMOnKYsHze6eA6w1KQCMVN2Q= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240730163845-b1a4ccb954bf/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc= google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 6bd6702..5238e5f 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -4,7 +4,6 @@ import ( "context" "os" "runtime" - "strconv" "github.com/scylladb/terraform-provider-scylladbcloud/internal/provider/allowlistrule" "github.com/scylladb/terraform-provider-scylladbcloud/internal/provider/cluster" @@ -30,12 +29,6 @@ func envEndpoint() string { return os.Getenv("SCYLLADB_CLOUD_ENDPOINT") } -func ignoreMeta() bool { - s := os.Getenv("SCYLLADB_CLOUD_IGNORE_META") - ok, _ := strconv.ParseBool(s) - return ok -} - func New(context.Context) (*schema.Provider, error) { p := &schema.Provider{ Schema: map[string]*schema.Schema{ @@ -62,6 +55,12 @@ func New(context.Context) (*schema.Provider, error) { }, Description: "Bearer token used to authenticate with the API.", }, + "metadata": { + Type: schema.TypeBool, + Optional: true, + Default: true, + Description: "Whether to preload deployment metadata for the provider.", + }, }, DataSourcesMap: map[string]*schema.Resource{ @@ -90,10 +89,10 @@ func configure(ctx context.Context, p *schema.Provider, d *schema.ResourceData) var ( endpoint = d.Get("endpoint").(string) token = d.Get("token").(string) - ignore = ignoreMeta() + metadata = d.Get("metadata").(bool) ) - c, err := scylla.NewClient(endpoint, token, userAgent(p.TerraformVersion), ignore) + c, err := scylla.NewClient(endpoint, token, userAgent(p.TerraformVersion), metadata) if err != nil { return nil, diag.Errorf("could not create new Scylla client: %s", err) } diff --git a/internal/scylla/client.go b/internal/scylla/client.go index b149022..aef59ef 100644 --- a/internal/scylla/client.go +++ b/internal/scylla/client.go @@ -56,7 +56,7 @@ type Client struct { V2 *v2scylla.Client } -func NewClient(endpoint, token, useragent string, ignoreMeta bool) (*Client, error) { +func NewClient(endpoint, token, useragent string, metadata bool) (*Client, error) { errCodes, err := parse(codes, codesDelim, codesFunc) if err != nil { return nil, fmt.Errorf("failed to parse error codes: %w", err) @@ -92,7 +92,7 @@ func NewClient(endpoint, token, useragent string, ignoreMeta bool) (*Client, err c.Headers.Set("Accept", "application/json; charset=utf-8") c.Headers.Set("User-Agent", useragent) - if !ignoreMeta { + if metadata { if c.Meta, err = BuildCloudmeta(ctx, c); err != nil { return nil, fmt.Errorf("error building metadata: %w", err) }