From 5ea5069e5f8869a9c7f5dc4e257f0b4234eef9ff Mon Sep 17 00:00:00 2001 From: Fumigatus Date: Tue, 3 Dec 2024 12:48:37 +0300 Subject: [PATCH] =?UTF-8?q?credentials=C2=A0fixed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/providerconfig/secret.yaml | 8 ++++++-- internal/clients/vcd.go | 25 ++++++++++--------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/examples/providerconfig/secret.yaml b/examples/providerconfig/secret.yaml index 594ff12..c3d27dd 100644 --- a/examples/providerconfig/secret.yaml +++ b/examples/providerconfig/secret.yaml @@ -7,6 +7,10 @@ type: Opaque stringData: credentials: | { - "user": "", - "password": "" + "user": "vcd_user", + "password": "vcd_password", + "auth_type": "integrated", + "org": "org", + "vdc": "vdc", + "url": "url" } diff --git a/internal/clients/vcd.go b/internal/clients/vcd.go index 87b4d6c..9a6f7d1 100644 --- a/internal/clients/vcd.go +++ b/internal/clients/vcd.go @@ -27,10 +27,8 @@ const ( errUnmarshalCredentials = "cannot unmarshal vcd credentials as JSON" ) -const ( - keyUser = "user" - keyPassword = "password" -) +var reqFields = []string{"user", "password", "auth_type", "org", "vdc", "url"} +var optFields = []string{"allow_unverified_ssl"} // TerraformSetupBuilder builds Terraform a terraform.SetupFn function which // returns Terraform provider setup configuration @@ -67,19 +65,16 @@ func TerraformSetupBuilder(version, providerSource, providerVersion string) terr return ps, errors.Wrap(err, errUnmarshalCredentials) } - ps.Configuration = map[string]interface{}{} - if v, ok := creds[keyUser]; ok { - ps.Configuration[keyUser] = v + // Required fields + for _, req := range reqFields { + ps.Configuration[req] = creds[req] } - if v, ok := creds[keyPassword]; ok { - ps.Configuration[keyPassword] = v + // Optional fields + for _, opt := range optFields { + if v, ok := creds[opt]; ok { + ps.Configuration[opt] = v + } } - - // Set credentials in Terraform provider configuration. - /*ps.Configuration = map[string]any{ - "username": creds["username"], - "password": creds["password"], - }*/ return ps, nil } }