Skip to content

Commit

Permalink
internal/provider: add optional metadata param (#161)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rjeczalik authored Aug 6, 2024
1 parent 25d3e37 commit 798483f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ 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
github.com/hashicorp/terraform-plugin-go v0.23.0
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
)

Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
17 changes: 8 additions & 9 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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{
Expand All @@ -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{
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/scylla/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 798483f

Please sign in to comment.