From da10b27cd0df51cc6dda51260f0c1814f75cff67 Mon Sep 17 00:00:00 2001 From: Gefferson Ferraz Date: Wed, 6 Nov 2024 11:17:03 -0300 Subject: [PATCH 1/2] fix: tf - required api key --- .../docs-extra/index.md | 2 ++ mgc/terraform-provider-mgc/mgc/client/sdk.go | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/mgc/terraform-provider-mgc/docs-extra/index.md b/mgc/terraform-provider-mgc/docs-extra/index.md index 13d024a2d..74a743e75 100644 --- a/mgc/terraform-provider-mgc/docs-extra/index.md +++ b/mgc/terraform-provider-mgc/docs-extra/index.md @@ -46,6 +46,8 @@ provider "mgc" { } ``` +> API-key are required, except when using key-pair authentication for object storage resources. + ## Schema diff --git a/mgc/terraform-provider-mgc/mgc/client/sdk.go b/mgc/terraform-provider-mgc/mgc/client/sdk.go index b826394df..110d1ffaa 100644 --- a/mgc/terraform-provider-mgc/mgc/client/sdk.go +++ b/mgc/terraform-provider-mgc/mgc/client/sdk.go @@ -46,15 +46,22 @@ func NewSDKClient[T SDKFrom](req T) (*mgcSdk.Client, error, error) { _ = sdkClient.Sdk().Config().SetTempConfig("env", config.Env.ValueString()) } - if 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`) - } - - _ = 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 From f55346fa0abe4bef1e50d23e948ef9c04c8cabb9 Mon Sep 17 00:00:00 2001 From: Gefferson Ferraz Date: Wed, 6 Nov 2024 11:28:29 -0300 Subject: [PATCH 2/2] fix: tf - required api key --- .pre-commit-config.yaml | 3 +-- mgc/terraform-provider-mgc/docs/index.md | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cc0ff7392..cc848f06f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -35,8 +35,7 @@ repos: - id: tf-docs name: generate terraform documentation language: system - entry: bash -c 'if [ "$SKIP_TF_STEP" != "true" ]; then make -C ./mgc/terraform-provider-mgc/ generate-docs; else echo "Skipped"; fi' - # entry: make -C ./mgc/terraform-provider-mgc/ generate-docs + entry: make -C ./mgc/terraform-provider-mgc/ generate-docs require_serial: true pass_filenames: false stages: [pre-commit] diff --git a/mgc/terraform-provider-mgc/docs/index.md b/mgc/terraform-provider-mgc/docs/index.md index 13d024a2d..74a743e75 100644 --- a/mgc/terraform-provider-mgc/docs/index.md +++ b/mgc/terraform-provider-mgc/docs/index.md @@ -46,6 +46,8 @@ provider "mgc" { } ``` +> API-key are required, except when using key-pair authentication for object storage resources. + ## Schema