Skip to content

Commit

Permalink
provider: Add "host" attribute (#34)
Browse files Browse the repository at this point in the history
Allows the user to specify a P0 host other than the standard api.p0.app.
  • Loading branch information
nbrahms authored Jun 28, 2024
1 parent 369ab83 commit c72cf25
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 5 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ provider "p0" {

### Required

- `org` (String) Your P0 organization identifier.
- `org` (String) Your P0 organization identifier

### Optional

- `host` (String) Your P0 application API host (defaults to `https://api.p0.app`)
12 changes: 8 additions & 4 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ type P0Provider struct {

// P0ProviderModel describes the provider data model.
type P0ProviderModel struct {
Org types.String `tfsdk:"org"`
Host types.String `tfsdk:"host"`
Org types.String `tfsdk:"org"`
}

func (p *P0Provider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) {
Expand All @@ -52,8 +53,12 @@ func (p *P0Provider) Schema(ctx context.Context, req provider.SchemaRequest, res
You must also configure a P0 API token (on your P0 app "/settings" page). Then run Terraform with your API token in
the P0_API_TOKEN environment variable.`,
Attributes: map[string]schema.Attribute{
"host": schema.StringAttribute{
MarkdownDescription: "Your P0 application API host (defaults to `https://api.p0.app`)",
Optional: true,
},
"org": schema.StringAttribute{
MarkdownDescription: "Your P0 organization identifier.",
MarkdownDescription: "Your P0 organization identifier",
Required: true,
},
},
Expand Down Expand Up @@ -83,8 +88,7 @@ func (p *P0Provider) Configure(ctx context.Context, req provider.ConfigureReques
)
}

// For dev only: optionally override P0 app server
p0_host := os.Getenv("P0_HOST")
p0_host := model.Host.ValueString()
if p0_host == "" {
p0_host = "https://api.p0.app"
}
Expand Down

0 comments on commit c72cf25

Please sign in to comment.