Skip to content

Commit

Permalink
adds configurable provider config for host & data host url scheme (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahadarsh authored May 24, 2024
1 parent e85cf73 commit 0803f2b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,5 @@ jobs:
ORG_ID: ${{ secrets.ORG_ID }}
TEMBO_HOST: ${{ secrets.TEMBO_HOST }}
TEMBO_DATA_HOST: ${{ secrets.TEMBO_DATA_HOST }}
run: go test -v -cover ./internal/provider/
timeout-minutes: 10
run: go test -v -cover -timeout 20m ./internal/provider/
timeout-minutes: 20
38 changes: 33 additions & 5 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ type temboProvider struct {

// temboProviderModel maps provider schema data to a Go type.
type temboProviderModel struct {
Host types.String `tfsdk:"host"`
DataHost types.String `tfsdk:"data_host"`
AccessToken types.String `tfsdk:"access_token"`
Host types.String `tfsdk:"host"`
HostURLScheme types.String `tfsdk:"host_url_scheme"`
DataHost types.String `tfsdk:"data_host"`
DataHostURLScheme types.String `tfsdk:"data_host_url_scheme"`
AccessToken types.String `tfsdk:"access_token"`
}

// Metadata returns the provider type name.
Expand All @@ -59,10 +61,18 @@ func (p *temboProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp
MarkdownDescription: "Tembo API the provider should connect to. By default it connects to Tembo Cloud Production API.",
Optional: true,
},
"host_url_scheme": schema.StringAttribute{
MarkdownDescription: "Url scheme for Tembo API. By default it is https.",
Optional: true,
},
"data_host": schema.StringAttribute{
MarkdownDescription: "Tembo Data API the provider should connect to. By default it connects to Tembo Data Cloud Production API.",
Optional: true,
},
"data_host_url_scheme": schema.StringAttribute{
MarkdownDescription: "Url scheme for Tembo Data API. By default it is https.",
Optional: true,
},
"access_token": schema.StringAttribute{
MarkdownDescription: "Access Token generated using steps [here](https://tembo.io/docs/tembo-cloud/api#create-a-long-lived-api-token).",
Optional: true,
Expand Down Expand Up @@ -119,7 +129,9 @@ func (p *temboProvider) Configure(ctx context.Context, req provider.ConfigureReq
// with Terraform configuration value if set.

host := os.Getenv("TEMBO_HOST")
host_url_scheme := os.Getenv("TEMBO_HOST_URL_SCHEME")
data_host := os.Getenv("TEMBO_DATA_HOST")
data_host_url_scheme := os.Getenv("TEMBO_DATA_HOST_URL_SCHEME")
access_token := os.Getenv("TEMBO_ACCESS_TOKEN")

if !config.Host.IsNull() {
Expand All @@ -130,6 +142,14 @@ func (p *temboProvider) Configure(ctx context.Context, req provider.ConfigureReq
host = "https://api.coredb.io"
}

if !config.HostURLScheme.IsNull() {
host_url_scheme = config.HostURLScheme.ValueString()
}

if host_url_scheme == "" {
host_url_scheme = "https"
}

if !config.DataHost.IsNull() {
data_host = config.DataHost.ValueString()
}
Expand All @@ -138,6 +158,14 @@ func (p *temboProvider) Configure(ctx context.Context, req provider.ConfigureReq
data_host = "https://api.data-1.use1.tembo.io"
}

if !config.DataHostURLScheme.IsNull() {
data_host_url_scheme = config.DataHostURLScheme.ValueString()
}

if data_host_url_scheme == "" {
data_host_url_scheme = "https"
}

if !config.AccessToken.IsNull() {
access_token = config.AccessToken.ValueString()
}
Expand Down Expand Up @@ -176,7 +204,7 @@ func (p *temboProvider) Configure(ctx context.Context, req provider.ConfigureReq
panic(err)
}

configuration.Scheme = "https"
configuration.Scheme = host_url_scheme

configuration.Host = hostUrl.Host

Expand All @@ -190,7 +218,7 @@ func (p *temboProvider) Configure(ctx context.Context, req provider.ConfigureReq
panic(err)
}

data_configuration.Scheme = "https"
data_configuration.Scheme = data_host_url_scheme

data_configuration.Host = dataHostUrl.Host

Expand Down

0 comments on commit 0803f2b

Please sign in to comment.