Skip to content

Commit

Permalink
feat(provider): add environment variable support for organization con…
Browse files Browse the repository at this point in the history
…fig (#48)
  • Loading branch information
juwit authored Dec 14, 2023
1 parent 939e9c8 commit b0737ba
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CleverCloud provider allow you to interact with CleverCloud platform.

### Required

- `organisation` (String, Sensitive) CleverCloud organisation, can be either orga_xxx, or user_xxx for personal spaces
- `organisation` (String, Sensitive) CleverCloud organisation, can be either orga_xxx, or user_xxx for personal spaces. This parameter can also be provided via CC_ORGANISATION environment variable.

### Optional

Expand Down
7 changes: 6 additions & 1 deletion pkg/provider/impl/provider_configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package impl
import (
"context"
"fmt"
"os"

"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-log/tflog"
Expand All @@ -20,7 +21,11 @@ func (p *Provider) Configure(ctx context.Context, req provider.ConfigureRequest,
return
}

p.organization = config.Organisation.ValueString()
if config.Organisation.IsUnknown() || config.Organisation.IsNull() {
p.organization = os.Getenv("CC_ORGANISATION")
} else {
p.organization = config.Organisation.ValueString()
}

// Allow to get creds from CLI config directory or by injected variables
if config.Secret.IsUnknown() ||
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/impl/provider_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (p *Provider) Schema(_ context.Context, req provider.SchemaRequest, res *pr
"organisation": schema.StringAttribute{
Sensitive: true,
Required: true,
MarkdownDescription: "CleverCloud organisation, can be either orga_xxx, or user_xxx for personal spaces",
MarkdownDescription: "CleverCloud organisation, can be either orga_xxx, or user_xxx for personal spaces. This parameter can also be provided via CC_ORGANISATION environment variable.",
Validators: []validator.String{
pkg.NewValidatorRegex("valid owner name", regexp.MustCompile(`^(user|orga)_.{36}`)),
},
Expand Down

0 comments on commit b0737ba

Please sign in to comment.