diff --git a/examples/providerconfig/secret.yaml b/examples/providerconfig/secret.yaml index 10c4e74..6b043c3 100644 --- a/examples/providerconfig/secret.yaml +++ b/examples/providerconfig/secret.yaml @@ -7,5 +7,5 @@ stringData: credentials: | { "url": "https://api.mgmt.cloud.vmware.com", - "refresh_token": "" + "refresh_token": "", } diff --git a/internal/clients/vra.go b/internal/clients/vra.go index b0c5851..200b88b 100644 --- a/internal/clients/vra.go +++ b/internal/clients/vra.go @@ -27,10 +27,8 @@ const ( errUnmarshalCredentials = "cannot unmarshal vRA credentials as JSON" ) -const ( - keyURL = "url" - keyRefreshToken = "refresh_token" -) +var reqFields = []string{"url", "refresh_token"} +var optFields = []string{"insecure"} // TerraformSetupBuilder builds Terraform a terraform.SetupFn function which // returns Terraform provider setup configuration @@ -63,31 +61,21 @@ func TerraformSetupBuilder(version, providerSource, providerVersion string) terr return ps, errors.Wrap(err, errExtractCredentials) } - // Configuration is a map of provider configuration values. - vraCreds := map[string]string{} - if err := json.Unmarshal(data, &vraCreds); err != nil { + creds := map[string]string{} + if err := json.Unmarshal(data, &creds); err != nil { return ps, errors.Wrap(err, errUnmarshalCredentials) } - ps.Configuration = map[string]interface{}{} - if v, ok := vraCreds[keyURL]; ok { - ps.Configuration[keyURL] = v + // Required fields + for _, req := range reqFields { + ps.Configuration[req] = creds[req] } - if v, ok := vraCreds[keyRefreshToken]; ok { - ps.Configuration[keyRefreshToken] = v + // Optional fields + for _, opt := range optFields { + if v, ok := creds[opt]; ok { + ps.Configuration[opt] = v + } } - - // Set credentials in Terraform provider environment. - /*ps.Env = []string{ - fmt.Sprintf("%s=%s", envURL, vraCreds[keyURL]), - fmt.Sprintf("%s=%s", envRefreshToken, vraCreds[keyRefreshToken]), - }*/ - - // Set credentials in Terraform provider configuration. - /*ps.Configuration = map[string]any{ - "username": creds["username"], - "password": creds["password"], - }*/ return ps, nil } }