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

feat: tf - required api key #1242

Open
wants to merge 5 commits into
base: main
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
2 changes: 2 additions & 0 deletions mgc/terraform-provider-mgc/docs-extra/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ provider "mgc" {
}
```

> API-key are required, except when using key-pair authentication for object storage resources.

<!-- schema generated by tfplugindocs -->
## Schema

Expand Down
2 changes: 2 additions & 0 deletions mgc/terraform-provider-mgc/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ provider "mgc" {
}
```

> API-key are required, except when using key-pair authentication for object storage resources.

<!-- schema generated by tfplugindocs -->
## Schema

Expand Down
17 changes: 13 additions & 4 deletions mgc/terraform-provider-mgc/mgc/client/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,22 @@ func NewSDKClient[T SDKFrom](req T) (*mgcSdk.Client, error, error) {
_ = sdkClient.Sdk().Config().SetTempConfig("env", config.Env.ValueString())
}

if config.ApiKey.ValueString() != "" {
_ = sdkClient.Sdk().Auth().SetAPIKey(config.ApiKey.ValueString())
}

keyPairPresent := false
if config.ObjectStorage != nil && config.ObjectStorage.ObjectKeyPair != nil {
sdkClient.Sdk().Config().AddTempKeyPair("apikey", config.ObjectStorage.ObjectKeyPair.KeyID.ValueString(),
config.ObjectStorage.ObjectKeyPair.KeySecret.ValueString())
keyPairPresent = true
}

if !keyPairPresent && config.ApiKey.ValueString() == "" {
return nil, fmt.Errorf("provider with api_key must be setted"), fmt.Errorf(`please check the resource to see if they are using 'provider' and verify if the provider has the 'api_key' correctly set`)
}

if config.ApiKey.ValueString() != "" {
err := sdkClient.Sdk().Auth().SetAPIKey(config.ApiKey.ValueString())
if err != nil {
return nil, fmt.Errorf("fail to set api_key"), err
}
}

return sdkClient, nil, nil
Expand Down