mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-04 21:14:05 +00:00
Latest work
This commit is contained in:
parent
b6655b2a4d
commit
97ae8ba5ed
@ -28,7 +28,7 @@ func dataSourceVirtualEnvironmentGroup() *schema.Resource {
|
||||
Required: true,
|
||||
},
|
||||
mkDataSourceVirtualEnvironmentGroupMembers: &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Type: schema.TypeSet,
|
||||
Description: "The group members",
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
@ -55,7 +55,12 @@ func dataSourceVirtualEnvironmentGroupRead(d *schema.ResourceData, m interface{}
|
||||
|
||||
d.SetId(groupID)
|
||||
|
||||
d.Set(mkDataSourceVirtualEnvironmentGroupComment, accessGroup.Comment)
|
||||
if accessGroup.Comment != nil {
|
||||
d.Set(mkDataSourceVirtualEnvironmentGroupComment, accessGroup.Comment)
|
||||
} else {
|
||||
d.Set(mkDataSourceVirtualEnvironmentGroupComment, "")
|
||||
}
|
||||
|
||||
d.Set(mkDataSourceVirtualEnvironmentGroupMembers, accessGroup.Members)
|
||||
|
||||
return nil
|
||||
|
@ -51,7 +51,12 @@ func dataSourceVirtualEnvironmentGroupsRead(d *schema.ResourceData, m interface{
|
||||
groupIDs := make([]interface{}, len(list))
|
||||
|
||||
for i, v := range list {
|
||||
comments[i] = v.Comment
|
||||
if v.Comment != nil {
|
||||
comments[i] = v.Comment
|
||||
} else {
|
||||
comments[i] = ""
|
||||
}
|
||||
|
||||
groupIDs[i] = v.ID
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ func dataSourceVirtualEnvironmentRole() *schema.Resource {
|
||||
Required: true,
|
||||
},
|
||||
mkDataSourceVirtualEnvironmentRolePrivileges: &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Type: schema.TypeSet,
|
||||
Description: "The role privileges",
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
@ -47,8 +47,17 @@ func dataSourceVirtualEnvironmentRoleRead(d *schema.ResourceData, m interface{})
|
||||
return err
|
||||
}
|
||||
|
||||
privileges := schema.NewSet(schema.HashString, make([]interface{}, 0))
|
||||
|
||||
if *accessRole != nil {
|
||||
for _, v := range *accessRole {
|
||||
privileges.Add(v)
|
||||
}
|
||||
}
|
||||
|
||||
d.SetId(roleID)
|
||||
d.Set(mkDataSourceVirtualEnvironmentRolePrivileges, *accessRole)
|
||||
|
||||
d.Set(mkDataSourceVirtualEnvironmentRolePrivileges, privileges)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ func dataSourceVirtualEnvironmentRoles() *schema.Resource {
|
||||
Description: "The role privileges",
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Type: schema.TypeSet,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
},
|
||||
},
|
||||
@ -62,9 +62,25 @@ func dataSourceVirtualEnvironmentRolesRead(d *schema.ResourceData, m interface{}
|
||||
special := make([]interface{}, len(list))
|
||||
|
||||
for i, v := range list {
|
||||
privileges[i] = v.Privileges
|
||||
if v.Privileges != nil {
|
||||
p := schema.NewSet(schema.HashString, make([]interface{}, 0))
|
||||
|
||||
for _, v := range *v.Privileges {
|
||||
p.Add(v)
|
||||
}
|
||||
|
||||
privileges[i] = p
|
||||
} else {
|
||||
privileges[i] = make(map[string]interface{})
|
||||
}
|
||||
|
||||
roleIDs[i] = v.ID
|
||||
special[i] = v.Special
|
||||
|
||||
if v.Special != nil {
|
||||
special[i] = v.Special
|
||||
} else {
|
||||
special[i] = false
|
||||
}
|
||||
}
|
||||
|
||||
d.SetId("access_roles")
|
||||
|
@ -1,4 +1,6 @@
|
||||
data "proxmox_virtual_environment_groups" "example" {}
|
||||
data "proxmox_virtual_environment_groups" "example" {
|
||||
depends_on = ["proxmox_virtual_environment_group.example"]
|
||||
}
|
||||
|
||||
output "data_proxmox_virtual_environment_groups_example" {
|
||||
value = "${map(
|
||||
|
@ -1,4 +1,6 @@
|
||||
data "proxmox_virtual_environment_roles" "example" {}
|
||||
data "proxmox_virtual_environment_roles" "example" {
|
||||
depends_on = ["proxmox_virtual_environment_role.example"]
|
||||
}
|
||||
|
||||
output "data_proxmox_virtual_environment_roles_example_privileges" {
|
||||
value = "${data.proxmox_virtual_environment_roles.example.privileges}"
|
||||
|
@ -1,5 +1,6 @@
|
||||
resource "proxmox_virtual_environment_role" "example" {
|
||||
privileges = [
|
||||
"VM.Console",
|
||||
"VM.Monitor",
|
||||
]
|
||||
role_id = "terraform-provider-proxmox-example"
|
||||
|
@ -94,6 +94,8 @@ func (c *VirtualEnvironmentClient) DoRequest(method, path string, requestBody in
|
||||
|
||||
encodedValues := v.Encode()
|
||||
urlEncodedRequestBody = bytes.NewBufferString(encodedValues)
|
||||
|
||||
log.Printf("[DEBUG] Added request body to HTTP %s request (path: %s) - Body: %s", method, path, encodedValues)
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(method, fmt.Sprintf("%s/%s/%s", c.Endpoint, basePathJSONAPI, path), urlEncodedRequestBody)
|
||||
@ -141,6 +143,8 @@ func (c *VirtualEnvironmentClient) DoRequest(method, path string, requestBody in
|
||||
func (c *VirtualEnvironmentClient) ValidateResponseCode(res *http.Response) error {
|
||||
if res.StatusCode < 200 || res.StatusCode >= 300 {
|
||||
switch res.StatusCode {
|
||||
case 400:
|
||||
return fmt.Errorf("Received a HTTP %d response - This is most likely caused by a bug in the code, so please create a new issue on https://github.com/danitso/terraform-provider-proxmox/issues", res.StatusCode)
|
||||
case 401:
|
||||
return fmt.Errorf("Received a HTTP %d response - Please verify that the specified credentials are valid", res.StatusCode)
|
||||
case 403:
|
||||
|
@ -29,10 +29,10 @@ type VirtualEnvironmentAuthenticationResponseCapabilities struct {
|
||||
|
||||
// VirtualEnvironmentAuthenticationResponseData contains the data from an authentication response.
|
||||
type VirtualEnvironmentAuthenticationResponseData struct {
|
||||
ClusterName string `json:"clustername,omitempty"`
|
||||
CSRFPreventionToken string `json:"CSRFPreventionToken"`
|
||||
ClusterName *string `json:"clustername,omitempty"`
|
||||
CSRFPreventionToken *string `json:"CSRFPreventionToken,omitempty"`
|
||||
Capabilities *VirtualEnvironmentAuthenticationResponseCapabilities `json:"cap,omitempty"`
|
||||
Ticket string `json:"ticket"`
|
||||
Ticket *string `json:"ticket,omitempty"`
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
@ -74,11 +74,11 @@ func (c *VirtualEnvironmentClient) Authenticate(reset bool) error {
|
||||
return errors.New("The server did not include a data object in the authentication response")
|
||||
}
|
||||
|
||||
if resBody.Data.CSRFPreventionToken == "" {
|
||||
if resBody.Data.CSRFPreventionToken == nil {
|
||||
return errors.New("The server did not include a CSRF prevention token in the authentication response")
|
||||
}
|
||||
|
||||
if resBody.Data.Ticket == "" {
|
||||
if resBody.Data.Ticket == nil {
|
||||
return errors.New("The server did not include a ticket in the authentication response")
|
||||
}
|
||||
|
||||
@ -101,11 +101,11 @@ func (c *VirtualEnvironmentClient) AuthenticateRequest(req *http.Request) error
|
||||
|
||||
req.AddCookie(&http.Cookie{
|
||||
Name: "PVEAuthCookie",
|
||||
Value: c.authenticationData.Ticket,
|
||||
Value: *c.authenticationData.Ticket,
|
||||
})
|
||||
|
||||
if req.Method != "GET" {
|
||||
req.Header.Add("CSRFPreventionToken", c.authenticationData.CSRFPreventionToken)
|
||||
req.Header.Add("CSRFPreventionToken", *c.authenticationData.CSRFPreventionToken)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -13,8 +13,8 @@ import (
|
||||
|
||||
// VirtualEnvironmentGroupCreateRequestBody contains the data for an access group create request.
|
||||
type VirtualEnvironmentGroupCreateRequestBody struct {
|
||||
Comment string `json:"comment" url:"comment"`
|
||||
ID string `json:"groupid" url:"groupid"`
|
||||
Comment *string `json:"comment,omitempty" url:"comment,omitempty"`
|
||||
ID string `json:"groupid" url:"groupid"`
|
||||
}
|
||||
|
||||
// VirtualEnvironmentGroupGetResponseBody contains the body from an access group get response.
|
||||
@ -24,7 +24,7 @@ type VirtualEnvironmentGroupGetResponseBody struct {
|
||||
|
||||
// VirtualEnvironmentGroupGetResponseData contains the data from an access group get response.
|
||||
type VirtualEnvironmentGroupGetResponseData struct {
|
||||
Comment string `json:"comment"`
|
||||
Comment *string `json:"comment,omitempty"`
|
||||
Members []string `json:"members"`
|
||||
}
|
||||
|
||||
@ -35,13 +35,13 @@ type VirtualEnvironmentGroupListResponseBody struct {
|
||||
|
||||
// VirtualEnvironmentGroupListResponseData contains the data from an access group list response.
|
||||
type VirtualEnvironmentGroupListResponseData struct {
|
||||
Comment string `json:"comment"`
|
||||
ID string `json:"groupid"`
|
||||
Comment *string `json:"comment,omitempty"`
|
||||
ID string `json:"groupid"`
|
||||
}
|
||||
|
||||
// VirtualEnvironmentGroupUpdateRequestBody contains the data for an access group update request.
|
||||
type VirtualEnvironmentGroupUpdateRequestBody struct {
|
||||
Comment string `json:"comment" url:"comment"`
|
||||
Comment *string `json:"comment,omitempty" url:"comment,omitempty"`
|
||||
}
|
||||
|
||||
// CreateGroup creates an access group.
|
||||
|
@ -30,8 +30,8 @@ type VirtualEnvironmentRoleListResponseBody struct {
|
||||
// VirtualEnvironmentRoleListResponseData contains the data from an access group list response.
|
||||
type VirtualEnvironmentRoleListResponseData struct {
|
||||
ID string `json:"roleid"`
|
||||
Privileges *CustomPrivileges `json:"privs"`
|
||||
Special CustomBool `json:"special"`
|
||||
Privileges *CustomPrivileges `json:"privs,omitempty"`
|
||||
Special *CustomBool `json:"special,omitempty"`
|
||||
}
|
||||
|
||||
// VirtualEnvironmentRoleUpdateRequestBody contains the data for an access group update request.
|
||||
@ -84,6 +84,12 @@ func (c *VirtualEnvironmentClient) ListRoles() ([]*VirtualEnvironmentRoleListRes
|
||||
return resBody.Data[i].ID < resBody.Data[j].ID
|
||||
})
|
||||
|
||||
for i := range resBody.Data {
|
||||
if resBody.Data[i].Privileges != nil {
|
||||
sort.Strings(*resBody.Data[i].Privileges)
|
||||
}
|
||||
}
|
||||
|
||||
return resBody.Data, nil
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ func resourceVirtualEnvironmentGroup() *schema.Resource {
|
||||
Required: true,
|
||||
},
|
||||
mkResourceVirtualEnvironmentGroupMembers: &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Type: schema.TypeSet,
|
||||
Description: "The group members",
|
||||
Computed: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
@ -53,9 +53,11 @@ func resourceVirtualEnvironmentGroupCreate(d *schema.ResourceData, m interface{}
|
||||
return err
|
||||
}
|
||||
|
||||
comment := d.Get(mkResourceVirtualEnvironmentGroupComment).(string)
|
||||
groupID := d.Get(mkResourceVirtualEnvironmentGroupID).(string)
|
||||
|
||||
body := &proxmox.VirtualEnvironmentGroupCreateRequestBody{
|
||||
Comment: d.Get(mkResourceVirtualEnvironmentGroupComment).(string),
|
||||
Comment: &comment,
|
||||
ID: groupID,
|
||||
}
|
||||
|
||||
@ -93,7 +95,12 @@ func resourceVirtualEnvironmentGroupRead(d *schema.ResourceData, m interface{})
|
||||
|
||||
d.SetId(groupID)
|
||||
|
||||
d.Set(mkResourceVirtualEnvironmentGroupComment, accessGroup.Comment)
|
||||
if accessGroup.Comment != nil {
|
||||
d.Set(mkResourceVirtualEnvironmentGroupComment, accessGroup.Comment)
|
||||
} else {
|
||||
d.Set(mkResourceVirtualEnvironmentGroupComment, "")
|
||||
}
|
||||
|
||||
d.Set(mkResourceVirtualEnvironmentGroupMembers, accessGroup.Members)
|
||||
|
||||
return nil
|
||||
@ -107,11 +114,13 @@ func resourceVirtualEnvironmentGroupUpdate(d *schema.ResourceData, m interface{}
|
||||
return err
|
||||
}
|
||||
|
||||
comment := d.Get(mkResourceVirtualEnvironmentGroupComment).(string)
|
||||
groupID := d.Id()
|
||||
|
||||
body := &proxmox.VirtualEnvironmentGroupUpdateRequestBody{
|
||||
Comment: d.Get(mkResourceVirtualEnvironmentGroupComment).(string),
|
||||
Comment: &comment,
|
||||
}
|
||||
|
||||
groupID := d.Id()
|
||||
err = veClient.UpdateGroup(groupID, body)
|
||||
|
||||
if err != nil {
|
||||
|
@ -20,7 +20,7 @@ func resourceVirtualEnvironmentRole() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
mkResourceVirtualEnvironmentRolePrivileges: &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Type: schema.TypeSet,
|
||||
Description: "The role privileges",
|
||||
Required: true,
|
||||
Elem: &schema.Schema{Type: schema.TypeString},
|
||||
@ -46,10 +46,9 @@ func resourceVirtualEnvironmentRoleCreate(d *schema.ResourceData, m interface{})
|
||||
return err
|
||||
}
|
||||
|
||||
privileges := d.Get(mkResourceVirtualEnvironmentRolePrivileges).([]interface{})
|
||||
roleID := d.Get(mkResourceVirtualEnvironmentRoleRoleID).(string)
|
||||
|
||||
privileges := d.Get(mkResourceVirtualEnvironmentRolePrivileges).(*schema.Set).List()
|
||||
customPrivileges := make(proxmox.CustomPrivileges, len(privileges))
|
||||
roleID := d.Get(mkResourceVirtualEnvironmentRoleRoleID).(string)
|
||||
|
||||
for i, v := range privileges {
|
||||
customPrivileges[i] = v.(string)
|
||||
@ -92,9 +91,17 @@ func resourceVirtualEnvironmentRoleRead(d *schema.ResourceData, m interface{}) e
|
||||
return err
|
||||
}
|
||||
|
||||
privileges := schema.NewSet(schema.HashString, make([]interface{}, 0))
|
||||
|
||||
if *accessRole != nil {
|
||||
for _, v := range *accessRole {
|
||||
privileges.Add(v)
|
||||
}
|
||||
}
|
||||
|
||||
d.SetId(roleID)
|
||||
|
||||
d.Set(mkResourceVirtualEnvironmentRolePrivileges, *accessRole)
|
||||
d.Set(mkResourceVirtualEnvironmentRolePrivileges, privileges)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -107,8 +114,9 @@ func resourceVirtualEnvironmentRoleUpdate(d *schema.ResourceData, m interface{})
|
||||
return err
|
||||
}
|
||||
|
||||
privileges := d.Get(mkResourceVirtualEnvironmentRolePrivileges).([]interface{})
|
||||
privileges := d.Get(mkResourceVirtualEnvironmentRolePrivileges).(*schema.Set).List()
|
||||
customPrivileges := make(proxmox.CustomPrivileges, len(privileges))
|
||||
roleID := d.Id()
|
||||
|
||||
for i, v := range privileges {
|
||||
customPrivileges[i] = v.(string)
|
||||
@ -118,7 +126,6 @@ func resourceVirtualEnvironmentRoleUpdate(d *schema.ResourceData, m interface{})
|
||||
Privileges: customPrivileges,
|
||||
}
|
||||
|
||||
roleID := d.Id()
|
||||
err = veClient.UpdateRole(roleID, body)
|
||||
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user