Skip to content

Commit

Permalink
bugfix: Missig provider credentials setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Leng Lim committed Aug 15, 2024
1 parent 3c9a84e commit 9e360ca
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions internal/clients/vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const (
errUnmarshalCredentials = "cannot unmarshal vsphere credentials as JSON"
)

var reqFields = []string{"user", "password", "vsphere_server"}
var optFields = []string{"allow_unverified_ssl", "vim_keep_alive", "api_timeout"}

// TerraformSetupBuilder builds Terraform a terraform.SetupFn function which
// returns Terraform provider setup configuration
func TerraformSetupBuilder(version, providerSource, providerVersion string) terraform.SetupFn {
Expand Down Expand Up @@ -62,11 +65,18 @@ func TerraformSetupBuilder(version, providerSource, providerVersion string) terr
return ps, errors.Wrap(err, errUnmarshalCredentials)
}

// Set credentials in Terraform provider configuration.
/*ps.Configuration = map[string]any{
"username": creds["username"],
"password": creds["password"],
}*/
ps.Configuration = map[string]any{}
// Required fields
for _, req := range reqFields {
ps.Configuration[req] = creds[req]
}
// Optional fields
for _, opt := range optFields {
if v, ok := creds[opt]; ok {
ps.Configuration[opt] = v
}
}

return ps, nil
}
}

0 comments on commit 9e360ca

Please sign in to comment.