allow base url change
This commit is contained in:
parent
15b3af2a99
commit
3eef94f685
4 changed files with 25 additions and 4 deletions
|
|
@ -30,6 +30,15 @@ provider "towerops" {
|
|||
}
|
||||
```
|
||||
|
||||
To use a custom API URL (e.g., for self-hosted or development):
|
||||
|
||||
```hcl
|
||||
provider "towerops" {
|
||||
token = var.towerops_api_token
|
||||
api_url = "https://custom.example.com"
|
||||
}
|
||||
```
|
||||
|
||||
You can also set the token via environment variable:
|
||||
|
||||
```bash
|
||||
|
|
|
|||
|
|
@ -45,3 +45,7 @@ resource "towerops_device" "router" {
|
|||
### Required
|
||||
|
||||
- `token` (String, Sensitive) - The API token for authenticating with TowerOps.
|
||||
|
||||
### Optional
|
||||
|
||||
- `api_url` (String) - The base URL for the TowerOps API. Defaults to `https://towerops.net`.
|
||||
|
|
|
|||
|
|
@ -19,9 +19,12 @@ type Client struct {
|
|||
}
|
||||
|
||||
// NewClient creates a new TowerOps API client.
|
||||
func NewClient(token string) *Client {
|
||||
func NewClient(token, baseURL string) *Client {
|
||||
if baseURL == "" {
|
||||
baseURL = defaultBaseURL
|
||||
}
|
||||
return &Client{
|
||||
BaseURL: defaultBaseURL,
|
||||
BaseURL: baseURL,
|
||||
Token: token,
|
||||
HTTPClient: &http.Client{
|
||||
Timeout: 30 * time.Second,
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@ type ToweropsProvider struct {
|
|||
|
||||
// ToweropsProviderModel describes the provider data model.
|
||||
type ToweropsProviderModel struct {
|
||||
Token types.String `tfsdk:"token"`
|
||||
Token types.String `tfsdk:"token"`
|
||||
APIURL types.String `tfsdk:"api_url"`
|
||||
}
|
||||
|
||||
// New creates a new provider instance.
|
||||
|
|
@ -45,6 +46,10 @@ func (p *ToweropsProvider) Schema(ctx context.Context, req provider.SchemaReques
|
|||
Required: true,
|
||||
Sensitive: true,
|
||||
},
|
||||
"api_url": schema.StringAttribute{
|
||||
Description: "The base URL for the TowerOps API. Defaults to https://towerops.net.",
|
||||
Optional: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
@ -73,7 +78,7 @@ func (p *ToweropsProvider) Configure(ctx context.Context, req provider.Configure
|
|||
return
|
||||
}
|
||||
|
||||
client := NewClient(config.Token.ValueString())
|
||||
client := NewClient(config.Token.ValueString(), config.APIURL.ValueString())
|
||||
|
||||
resp.DataSourceData = client
|
||||
resp.ResourceData = client
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue