Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(org): make the organisation parameter optional #104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ CleverCloud provider allow you to interact with CleverCloud platform.
<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `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

- `endpoint` (String) CleverCloud API endpoint, default to https://api.clever-cloud.com
- `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.
- `secret` (String, Sensitive) CleverCloud OAuth1 secret, can be took from clever-tools after login. This parameter can also be provided via CC_OAUTH_SECRET environment variable.
- `token` (String, Sensitive) CleverCloud OAuth1 token, can be took from clever-tools after login. This parameter can also be provided via CC_OAUTH_TOKEN environment variable.
4 changes: 4 additions & 0 deletions pkg/provider/impl/provider_configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func (p *Provider) Configure(ctx context.Context, req provider.ConfigureRequest,
} else {
p.organization = config.Organisation.ValueString()
}
if p.organization == "" {
resp.Diagnostics.AddError("Invalid provider configuration", "Organisation should be set by either the organisation parameter or by the CC_ORGANISATION environment variable")
return
}

// Allow to get creds from CLI config directory or by injected variables
if config.Secret.IsUnknown() ||
Expand Down
37 changes: 37 additions & 0 deletions pkg/provider/impl/provider_configure_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package impl

import (
"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"regexp"
"testing"
)

var protoV6Provider = map[string]func() (tfprotov6.ProviderServer, error){
"clevercloud": providerserver.NewProtocol6WithError(New("test")()),
}

func TestProvider_ConfigureEmptyOrganisation(t *testing.T) {
providerBlock := `
provider "clevercloud" {}

// dummy resource to trigger provider configuration
resource "clevercloud_cellar" "test" {
name = "test"
}
`
expectedError := regexp.MustCompile("Organisation should be set")

resource.Test(t, resource.TestCase{
IsUnitTest: true,
ProtoV6ProviderFactories: protoV6Provider,
Steps: []resource.TestStep{{
Config: providerBlock,
SkipFunc: func() (bool, error) {
return false, nil
},
ExpectError: expectedError,
}},
})
}
2 changes: 1 addition & 1 deletion pkg/provider/impl/provider_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (p *Provider) Schema(_ context.Context, req provider.SchemaRequest, res *pr
},
"organisation": schema.StringAttribute{
Sensitive: true,
Required: true,
Optional: true, // can be read from environment variable
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