mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-08-22 11:28:33 +00:00
Latest work
This commit is contained in:
parent
96cc4ef2e6
commit
9f312bf1cc
12
CHANGELOG.md
12
CHANGELOG.md
@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
FEATURES:
|
FEATURES:
|
||||||
|
|
||||||
* **New Data Source:** `proxmox_virtual_environment_access_group`
|
* **New Data Source:** `proxmox_virtual_environment_group`
|
||||||
* **New Data Source:** `proxmox_virtual_environment_access_groups`
|
* **New Data Source:** `proxmox_virtual_environment_groups`
|
||||||
* **New Data Source:** `proxmox_virtual_environment_access_role`
|
* **New Data Source:** `proxmox_virtual_environment_role`
|
||||||
* **New Data Source:** `proxmox_virtual_environment_access_roles`
|
* **New Data Source:** `proxmox_virtual_environment_roles`
|
||||||
* **New Data Source:** `proxmox_virtual_environment_version`
|
* **New Data Source:** `proxmox_virtual_environment_version`
|
||||||
* **New Resource:** `proxmox_virtual_environment_access_group`
|
* **New Resource:** `proxmox_virtual_environment_group`
|
||||||
* **New Resource:** `proxmox_virtual_environment_access_role`
|
* **New Resource:** `proxmox_virtual_environment_role`
|
||||||
|
12
README.md
12
README.md
@ -37,7 +37,7 @@ If you're building the provider, follow the instructions to [install it as a plu
|
|||||||
|
|
||||||
#### Virtual Environment
|
#### Virtual Environment
|
||||||
|
|
||||||
##### Access Group (proxmox_virtual_environment_access_group)
|
##### Group (proxmox_virtual_environment_group)
|
||||||
|
|
||||||
###### Arguments
|
###### Arguments
|
||||||
* `group_id` - (Required) The group id.
|
* `group_id` - (Required) The group id.
|
||||||
@ -46,7 +46,7 @@ If you're building the provider, follow the instructions to [install it as a plu
|
|||||||
* `comment` - The group comment.
|
* `comment` - The group comment.
|
||||||
* `members` - The group members as a list with `username@realm` entries.
|
* `members` - The group members as a list with `username@realm` entries.
|
||||||
|
|
||||||
##### Access Groups (proxmox_virtual_environment_access_groups)
|
##### Groups (proxmox_virtual_environment_groups)
|
||||||
|
|
||||||
###### Arguments
|
###### Arguments
|
||||||
This data source doesn't accept arguments.
|
This data source doesn't accept arguments.
|
||||||
@ -55,7 +55,7 @@ This data source doesn't accept arguments.
|
|||||||
* `comments` - The group comments.
|
* `comments` - The group comments.
|
||||||
* `group_ids` - The group ids.
|
* `group_ids` - The group ids.
|
||||||
|
|
||||||
##### Access Role (proxmox_virtual_environment_access_role)
|
##### Role (proxmox_virtual_environment_role)
|
||||||
|
|
||||||
###### Arguments
|
###### Arguments
|
||||||
* `role_id` - (Required) The role id.
|
* `role_id` - (Required) The role id.
|
||||||
@ -63,7 +63,7 @@ This data source doesn't accept arguments.
|
|||||||
###### Attributes
|
###### Attributes
|
||||||
* `privileges` - The role privileges.
|
* `privileges` - The role privileges.
|
||||||
|
|
||||||
##### Access Roles (proxmox_virtual_environment_access_roles)
|
##### Roles (proxmox_virtual_environment_roles)
|
||||||
|
|
||||||
###### Arguments
|
###### Arguments
|
||||||
This data source doesn't accept arguments.
|
This data source doesn't accept arguments.
|
||||||
@ -88,7 +88,7 @@ This data source doesn't accept arguments.
|
|||||||
|
|
||||||
#### Virtual Environment
|
#### Virtual Environment
|
||||||
|
|
||||||
##### Access Group (proxmox_virtual_environment_access_group)
|
##### Group (proxmox_virtual_environment_group)
|
||||||
|
|
||||||
###### Arguments
|
###### Arguments
|
||||||
* `comment` - (Optional) The group comment.
|
* `comment` - (Optional) The group comment.
|
||||||
@ -97,7 +97,7 @@ This data source doesn't accept arguments.
|
|||||||
###### Attributes
|
###### Attributes
|
||||||
* `members` - The group members as a list with `username@realm` entries.
|
* `members` - The group members as a list with `username@realm` entries.
|
||||||
|
|
||||||
##### Access Role (proxmox_virtual_environment_access_role)
|
##### Role (proxmox_virtual_environment_role)
|
||||||
|
|
||||||
###### Arguments
|
###### Arguments
|
||||||
* `privileges` - (Required) The role privileges.
|
* `privileges` - (Required) The role privileges.
|
||||||
|
@ -9,36 +9,36 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
mkDataSourceVirtualEnvironmentAccessGroupComment = "comment"
|
mkDataSourceVirtualEnvironmentGroupComment = "comment"
|
||||||
mkDataSourceVirtualEnvironmentAccessGroupID = "group_id"
|
mkDataSourceVirtualEnvironmentGroupID = "group_id"
|
||||||
mkDataSourceVirtualEnvironmentAccessGroupMembers = "members"
|
mkDataSourceVirtualEnvironmentGroupMembers = "members"
|
||||||
)
|
)
|
||||||
|
|
||||||
func dataSourceVirtualEnvironmentAccessGroup() *schema.Resource {
|
func dataSourceVirtualEnvironmentGroup() *schema.Resource {
|
||||||
return &schema.Resource{
|
return &schema.Resource{
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
mkDataSourceVirtualEnvironmentAccessGroupComment: &schema.Schema{
|
mkDataSourceVirtualEnvironmentGroupComment: &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Description: "The group comment",
|
Description: "The group comment",
|
||||||
Computed: true,
|
Computed: true,
|
||||||
},
|
},
|
||||||
mkDataSourceVirtualEnvironmentAccessGroupID: &schema.Schema{
|
mkDataSourceVirtualEnvironmentGroupID: &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Description: "The group id",
|
Description: "The group id",
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
mkDataSourceVirtualEnvironmentAccessGroupMembers: &schema.Schema{
|
mkDataSourceVirtualEnvironmentGroupMembers: &schema.Schema{
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
Description: "The group members",
|
Description: "The group members",
|
||||||
Computed: true,
|
Computed: true,
|
||||||
Elem: &schema.Schema{Type: schema.TypeString},
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Read: dataSourceVirtualEnvironmentAccessGroupRead,
|
Read: dataSourceVirtualEnvironmentGroupRead,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceVirtualEnvironmentAccessGroupRead(d *schema.ResourceData, m interface{}) error {
|
func dataSourceVirtualEnvironmentGroupRead(d *schema.ResourceData, m interface{}) error {
|
||||||
config := m.(providerConfiguration)
|
config := m.(providerConfiguration)
|
||||||
veClient, err := config.GetVEClient()
|
veClient, err := config.GetVEClient()
|
||||||
|
|
||||||
@ -46,8 +46,8 @@ func dataSourceVirtualEnvironmentAccessGroupRead(d *schema.ResourceData, m inter
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
groupID := d.Get(mkDataSourceVirtualEnvironmentAccessGroupID).(string)
|
groupID := d.Get(mkDataSourceVirtualEnvironmentGroupID).(string)
|
||||||
accessGroup, err := veClient.GetAccessGroup(groupID)
|
accessGroup, err := veClient.GetGroup(groupID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -55,8 +55,8 @@ func dataSourceVirtualEnvironmentAccessGroupRead(d *schema.ResourceData, m inter
|
|||||||
|
|
||||||
d.SetId(groupID)
|
d.SetId(groupID)
|
||||||
|
|
||||||
d.Set(mkDataSourceVirtualEnvironmentAccessGroupComment, accessGroup.Comment)
|
d.Set(mkDataSourceVirtualEnvironmentGroupComment, accessGroup.Comment)
|
||||||
d.Set(mkDataSourceVirtualEnvironmentAccessGroupMembers, accessGroup.Members)
|
d.Set(mkDataSourceVirtualEnvironmentGroupMembers, accessGroup.Members)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -8,31 +8,31 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestDataSourceVirtualEnvironmentAccessGroupInstantiation tests whether the DataSourceVirtualEnvironmentAccessGroup instance can be instantiated.
|
// TestDataSourceVirtualEnvironmentGroupInstantiation tests whether the DataSourceVirtualEnvironmentGroup instance can be instantiated.
|
||||||
func TestDataSourceVirtualEnvironmentAccessGroupInstantiation(t *testing.T) {
|
func TestDataSourceVirtualEnvironmentGroupInstantiation(t *testing.T) {
|
||||||
s := dataSourceVirtualEnvironmentAccessGroup()
|
s := dataSourceVirtualEnvironmentGroup()
|
||||||
|
|
||||||
if s == nil {
|
if s == nil {
|
||||||
t.Fatalf("Cannot instantiate dataSourceVirtualEnvironmentAccessGroup")
|
t.Fatalf("Cannot instantiate dataSourceVirtualEnvironmentGroup")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestDataSourceVirtualEnvironmentAccessGroupSchema tests the dataSourceVirtualEnvironmentAccessGroup schema.
|
// TestDataSourceVirtualEnvironmentGroupSchema tests the dataSourceVirtualEnvironmentGroup schema.
|
||||||
func TestDataSourceVirtualEnvironmentAccessGroupSchema(t *testing.T) {
|
func TestDataSourceVirtualEnvironmentGroupSchema(t *testing.T) {
|
||||||
s := dataSourceVirtualEnvironmentAccessGroup()
|
s := dataSourceVirtualEnvironmentGroup()
|
||||||
|
|
||||||
attributeKeys := []string{
|
attributeKeys := []string{
|
||||||
mkDataSourceVirtualEnvironmentAccessGroupComment,
|
mkDataSourceVirtualEnvironmentGroupComment,
|
||||||
mkDataSourceVirtualEnvironmentAccessGroupMembers,
|
mkDataSourceVirtualEnvironmentGroupMembers,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range attributeKeys {
|
for _, v := range attributeKeys {
|
||||||
if s.Schema[v] == nil {
|
if s.Schema[v] == nil {
|
||||||
t.Fatalf("Error in dataSourceVirtualEnvironmentAccessGroup.Schema: Missing attribute \"%s\"", v)
|
t.Fatalf("Error in dataSourceVirtualEnvironmentGroup.Schema: Missing attribute \"%s\"", v)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Schema[v].Computed != true {
|
if s.Schema[v].Computed != true {
|
||||||
t.Fatalf("Error in dataSourceVirtualEnvironmentAccessGroup.Schema: Attribute \"%s\" is not computed", v)
|
t.Fatalf("Error in dataSourceVirtualEnvironmentGroup.Schema: Attribute \"%s\" is not computed", v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,31 +9,31 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
mkDataSourceVirtualEnvironmentAccessGroupsComments = "comments"
|
mkDataSourceVirtualEnvironmentGroupsComments = "comments"
|
||||||
mkDataSourceVirtualEnvironmentAccessGroupsGroupIDs = "group_ids"
|
mkDataSourceVirtualEnvironmentGroupsGroupIDs = "group_ids"
|
||||||
)
|
)
|
||||||
|
|
||||||
func dataSourceVirtualEnvironmentAccessGroups() *schema.Resource {
|
func dataSourceVirtualEnvironmentGroups() *schema.Resource {
|
||||||
return &schema.Resource{
|
return &schema.Resource{
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
mkDataSourceVirtualEnvironmentAccessGroupsComments: &schema.Schema{
|
mkDataSourceVirtualEnvironmentGroupsComments: &schema.Schema{
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
Description: "The group comments",
|
Description: "The group comments",
|
||||||
Computed: true,
|
Computed: true,
|
||||||
Elem: &schema.Schema{Type: schema.TypeString},
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
},
|
},
|
||||||
mkDataSourceVirtualEnvironmentAccessGroupsGroupIDs: &schema.Schema{
|
mkDataSourceVirtualEnvironmentGroupsGroupIDs: &schema.Schema{
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
Description: "The group ids",
|
Description: "The group ids",
|
||||||
Computed: true,
|
Computed: true,
|
||||||
Elem: &schema.Schema{Type: schema.TypeString},
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Read: dataSourceVirtualEnvironmentAccessGroupsRead,
|
Read: dataSourceVirtualEnvironmentGroupsRead,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceVirtualEnvironmentAccessGroupsRead(d *schema.ResourceData, m interface{}) error {
|
func dataSourceVirtualEnvironmentGroupsRead(d *schema.ResourceData, m interface{}) error {
|
||||||
config := m.(providerConfiguration)
|
config := m.(providerConfiguration)
|
||||||
veClient, err := config.GetVEClient()
|
veClient, err := config.GetVEClient()
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ func dataSourceVirtualEnvironmentAccessGroupsRead(d *schema.ResourceData, m inte
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
list, err := veClient.ListAccessGroups()
|
list, err := veClient.ListGroups()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -57,8 +57,8 @@ func dataSourceVirtualEnvironmentAccessGroupsRead(d *schema.ResourceData, m inte
|
|||||||
|
|
||||||
d.SetId("access_groups")
|
d.SetId("access_groups")
|
||||||
|
|
||||||
d.Set(mkDataSourceVirtualEnvironmentAccessGroupsComments, comments)
|
d.Set(mkDataSourceVirtualEnvironmentGroupsComments, comments)
|
||||||
d.Set(mkDataSourceVirtualEnvironmentAccessGroupsGroupIDs, groupIDs)
|
d.Set(mkDataSourceVirtualEnvironmentGroupsGroupIDs, groupIDs)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -8,31 +8,31 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestDataSourceVirtualEnvironmentAccessGroupsInstantiation tests whether the DataSourceVirtualEnvironmentAccessGroups instance can be instantiated.
|
// TestDataSourceVirtualEnvironmentGroupsInstantiation tests whether the DataSourceVirtualEnvironmentGroups instance can be instantiated.
|
||||||
func TestDataSourceVirtualEnvironmentAccessGroupsInstantiation(t *testing.T) {
|
func TestDataSourceVirtualEnvironmentGroupsInstantiation(t *testing.T) {
|
||||||
s := dataSourceVirtualEnvironmentAccessGroups()
|
s := dataSourceVirtualEnvironmentGroups()
|
||||||
|
|
||||||
if s == nil {
|
if s == nil {
|
||||||
t.Fatalf("Cannot instantiate dataSourceVirtualEnvironmentAccessGroups")
|
t.Fatalf("Cannot instantiate dataSourceVirtualEnvironmentGroups")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestDataSourceVirtualEnvironmentAccessGroupsSchema tests the dataSourceVirtualEnvironmentAccessGroups schema.
|
// TestDataSourceVirtualEnvironmentGroupsSchema tests the dataSourceVirtualEnvironmentGroups schema.
|
||||||
func TestDataSourceVirtualEnvironmentAccessGroupsSchema(t *testing.T) {
|
func TestDataSourceVirtualEnvironmentGroupsSchema(t *testing.T) {
|
||||||
s := dataSourceVirtualEnvironmentAccessGroups()
|
s := dataSourceVirtualEnvironmentGroups()
|
||||||
|
|
||||||
attributeKeys := []string{
|
attributeKeys := []string{
|
||||||
mkDataSourceVirtualEnvironmentAccessGroupsComments,
|
mkDataSourceVirtualEnvironmentGroupsComments,
|
||||||
mkDataSourceVirtualEnvironmentAccessGroupsGroupIDs,
|
mkDataSourceVirtualEnvironmentGroupsGroupIDs,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range attributeKeys {
|
for _, v := range attributeKeys {
|
||||||
if s.Schema[v] == nil {
|
if s.Schema[v] == nil {
|
||||||
t.Fatalf("Error in dataSourceVirtualEnvironmentAccessGroups.Schema: Missing attribute \"%s\"", v)
|
t.Fatalf("Error in dataSourceVirtualEnvironmentGroups.Schema: Missing attribute \"%s\"", v)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Schema[v].Computed != true {
|
if s.Schema[v].Computed != true {
|
||||||
t.Fatalf("Error in dataSourceVirtualEnvironmentAccessGroups.Schema: Attribute \"%s\" is not computed", v)
|
t.Fatalf("Error in dataSourceVirtualEnvironmentGroups.Schema: Attribute \"%s\" is not computed", v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,30 +9,30 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
mkDataSourceVirtualEnvironmentAccessRoleID = "role_id"
|
mkDataSourceVirtualEnvironmentRoleID = "role_id"
|
||||||
mkDataSourceVirtualEnvironmentAccessRolePrivileges = "privileges"
|
mkDataSourceVirtualEnvironmentRolePrivileges = "privileges"
|
||||||
)
|
)
|
||||||
|
|
||||||
func dataSourceVirtualEnvironmentAccessRole() *schema.Resource {
|
func dataSourceVirtualEnvironmentRole() *schema.Resource {
|
||||||
return &schema.Resource{
|
return &schema.Resource{
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
mkDataSourceVirtualEnvironmentAccessRoleID: &schema.Schema{
|
mkDataSourceVirtualEnvironmentRoleID: &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Description: "The role id",
|
Description: "The role id",
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
mkDataSourceVirtualEnvironmentAccessRolePrivileges: &schema.Schema{
|
mkDataSourceVirtualEnvironmentRolePrivileges: &schema.Schema{
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
Description: "The role privileges",
|
Description: "The role privileges",
|
||||||
Computed: true,
|
Computed: true,
|
||||||
Elem: &schema.Schema{Type: schema.TypeString},
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Read: dataSourceVirtualEnvironmentAccessRoleRead,
|
Read: dataSourceVirtualEnvironmentRoleRead,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceVirtualEnvironmentAccessRoleRead(d *schema.ResourceData, m interface{}) error {
|
func dataSourceVirtualEnvironmentRoleRead(d *schema.ResourceData, m interface{}) error {
|
||||||
config := m.(providerConfiguration)
|
config := m.(providerConfiguration)
|
||||||
veClient, err := config.GetVEClient()
|
veClient, err := config.GetVEClient()
|
||||||
|
|
||||||
@ -40,15 +40,15 @@ func dataSourceVirtualEnvironmentAccessRoleRead(d *schema.ResourceData, m interf
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
roleID := d.Get(mkDataSourceVirtualEnvironmentAccessRoleID).(string)
|
roleID := d.Get(mkDataSourceVirtualEnvironmentRoleID).(string)
|
||||||
accessRole, err := veClient.GetAccessRole(roleID)
|
accessRole, err := veClient.GetRole(roleID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
d.SetId(roleID)
|
d.SetId(roleID)
|
||||||
d.Set(mkDataSourceVirtualEnvironmentAccessRolePrivileges, *accessRole)
|
d.Set(mkDataSourceVirtualEnvironmentRolePrivileges, *accessRole)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -8,30 +8,30 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestDataSourceVirtualEnvironmentAccessRoleInstantiation tests whether the DataSourceVirtualEnvironmentAccessRole instance can be instantiated.
|
// TestDataSourceVirtualEnvironmentRoleInstantiation tests whether the DataSourceVirtualEnvironmentRole instance can be instantiated.
|
||||||
func TestDataSourceVirtualEnvironmentAccessRoleInstantiation(t *testing.T) {
|
func TestDataSourceVirtualEnvironmentRoleInstantiation(t *testing.T) {
|
||||||
s := dataSourceVirtualEnvironmentAccessRole()
|
s := dataSourceVirtualEnvironmentRole()
|
||||||
|
|
||||||
if s == nil {
|
if s == nil {
|
||||||
t.Fatalf("Cannot instantiate dataSourceVirtualEnvironmentAccessRole")
|
t.Fatalf("Cannot instantiate dataSourceVirtualEnvironmentRole")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestDataSourceVirtualEnvironmentAccessRoleSchema tests the dataSourceVirtualEnvironmentAccessRole schema.
|
// TestDataSourceVirtualEnvironmentRoleSchema tests the dataSourceVirtualEnvironmentRole schema.
|
||||||
func TestDataSourceVirtualEnvironmentAccessRoleSchema(t *testing.T) {
|
func TestDataSourceVirtualEnvironmentRoleSchema(t *testing.T) {
|
||||||
s := dataSourceVirtualEnvironmentAccessRole()
|
s := dataSourceVirtualEnvironmentRole()
|
||||||
|
|
||||||
attributeKeys := []string{
|
attributeKeys := []string{
|
||||||
mkDataSourceVirtualEnvironmentAccessRolePrivileges,
|
mkDataSourceVirtualEnvironmentRolePrivileges,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range attributeKeys {
|
for _, v := range attributeKeys {
|
||||||
if s.Schema[v] == nil {
|
if s.Schema[v] == nil {
|
||||||
t.Fatalf("Error in dataSourceVirtualEnvironmentAccessRole.Schema: Missing attribute \"%s\"", v)
|
t.Fatalf("Error in dataSourceVirtualEnvironmentRole.Schema: Missing attribute \"%s\"", v)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Schema[v].Computed != true {
|
if s.Schema[v].Computed != true {
|
||||||
t.Fatalf("Error in dataSourceVirtualEnvironmentAccessRole.Schema: Attribute \"%s\" is not computed", v)
|
t.Fatalf("Error in dataSourceVirtualEnvironmentRole.Schema: Attribute \"%s\" is not computed", v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,15 +9,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
mkDataSourceVirtualEnvironmentAccessRolesPrivileges = "privileges"
|
mkDataSourceVirtualEnvironmentRolesPrivileges = "privileges"
|
||||||
mkDataSourceVirtualEnvironmentAccessRolesRoleIDs = "role_ids"
|
mkDataSourceVirtualEnvironmentRolesRoleIDs = "role_ids"
|
||||||
mkDataSourceVirtualEnvironmentAccessRolesSpecial = "special"
|
mkDataSourceVirtualEnvironmentRolesSpecial = "special"
|
||||||
)
|
)
|
||||||
|
|
||||||
func dataSourceVirtualEnvironmentAccessRoles() *schema.Resource {
|
func dataSourceVirtualEnvironmentRoles() *schema.Resource {
|
||||||
return &schema.Resource{
|
return &schema.Resource{
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
mkDataSourceVirtualEnvironmentAccessRolesPrivileges: &schema.Schema{
|
mkDataSourceVirtualEnvironmentRolesPrivileges: &schema.Schema{
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
Description: "The role privileges",
|
Description: "The role privileges",
|
||||||
Computed: true,
|
Computed: true,
|
||||||
@ -26,24 +26,24 @@ func dataSourceVirtualEnvironmentAccessRoles() *schema.Resource {
|
|||||||
Elem: &schema.Schema{Type: schema.TypeString},
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
mkDataSourceVirtualEnvironmentAccessRolesRoleIDs: &schema.Schema{
|
mkDataSourceVirtualEnvironmentRolesRoleIDs: &schema.Schema{
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
Description: "The role ids",
|
Description: "The role ids",
|
||||||
Computed: true,
|
Computed: true,
|
||||||
Elem: &schema.Schema{Type: schema.TypeString},
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
},
|
},
|
||||||
mkDataSourceVirtualEnvironmentAccessRolesSpecial: &schema.Schema{
|
mkDataSourceVirtualEnvironmentRolesSpecial: &schema.Schema{
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
Description: "Whether the role is special (built-in)",
|
Description: "Whether the role is special (built-in)",
|
||||||
Computed: true,
|
Computed: true,
|
||||||
Elem: &schema.Schema{Type: schema.TypeBool},
|
Elem: &schema.Schema{Type: schema.TypeBool},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Read: dataSourceVirtualEnvironmentAccessRolesRead,
|
Read: dataSourceVirtualEnvironmentRolesRead,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceVirtualEnvironmentAccessRolesRead(d *schema.ResourceData, m interface{}) error {
|
func dataSourceVirtualEnvironmentRolesRead(d *schema.ResourceData, m interface{}) error {
|
||||||
config := m.(providerConfiguration)
|
config := m.(providerConfiguration)
|
||||||
veClient, err := config.GetVEClient()
|
veClient, err := config.GetVEClient()
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ func dataSourceVirtualEnvironmentAccessRolesRead(d *schema.ResourceData, m inter
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
list, err := veClient.ListAccessRoles()
|
list, err := veClient.ListRoles()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -69,9 +69,9 @@ func dataSourceVirtualEnvironmentAccessRolesRead(d *schema.ResourceData, m inter
|
|||||||
|
|
||||||
d.SetId("access_roles")
|
d.SetId("access_roles")
|
||||||
|
|
||||||
d.Set(mkDataSourceVirtualEnvironmentAccessRolesPrivileges, privileges)
|
d.Set(mkDataSourceVirtualEnvironmentRolesPrivileges, privileges)
|
||||||
d.Set(mkDataSourceVirtualEnvironmentAccessRolesRoleIDs, roleIDs)
|
d.Set(mkDataSourceVirtualEnvironmentRolesRoleIDs, roleIDs)
|
||||||
d.Set(mkDataSourceVirtualEnvironmentAccessRolesSpecial, special)
|
d.Set(mkDataSourceVirtualEnvironmentRolesSpecial, special)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -8,32 +8,32 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestDataSourceVirtualEnvironmentAccessRolesInstantiation tests whether the DataSourceVirtualEnvironmentAccessRoles instance can be instantiated.
|
// TestDataSourceVirtualEnvironmentRolesInstantiation tests whether the DataSourceVirtualEnvironmentRoles instance can be instantiated.
|
||||||
func TestDataSourceVirtualEnvironmentAccessRolesInstantiation(t *testing.T) {
|
func TestDataSourceVirtualEnvironmentRolesInstantiation(t *testing.T) {
|
||||||
s := dataSourceVirtualEnvironmentAccessRoles()
|
s := dataSourceVirtualEnvironmentRoles()
|
||||||
|
|
||||||
if s == nil {
|
if s == nil {
|
||||||
t.Fatalf("Cannot instantiate dataSourceVirtualEnvironmentAccessRoles")
|
t.Fatalf("Cannot instantiate dataSourceVirtualEnvironmentRoles")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestDataSourceVirtualEnvironmentAccessRolesSchema tests the dataSourceVirtualEnvironmentAccessRoles schema.
|
// TestDataSourceVirtualEnvironmentRolesSchema tests the dataSourceVirtualEnvironmentRoles schema.
|
||||||
func TestDataSourceVirtualEnvironmentAccessRolesSchema(t *testing.T) {
|
func TestDataSourceVirtualEnvironmentRolesSchema(t *testing.T) {
|
||||||
s := dataSourceVirtualEnvironmentAccessRoles()
|
s := dataSourceVirtualEnvironmentRoles()
|
||||||
|
|
||||||
attributeKeys := []string{
|
attributeKeys := []string{
|
||||||
mkDataSourceVirtualEnvironmentAccessRolesPrivileges,
|
mkDataSourceVirtualEnvironmentRolesPrivileges,
|
||||||
mkDataSourceVirtualEnvironmentAccessRolesRoleIDs,
|
mkDataSourceVirtualEnvironmentRolesRoleIDs,
|
||||||
mkDataSourceVirtualEnvironmentAccessRolesSpecial,
|
mkDataSourceVirtualEnvironmentRolesSpecial,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range attributeKeys {
|
for _, v := range attributeKeys {
|
||||||
if s.Schema[v] == nil {
|
if s.Schema[v] == nil {
|
||||||
t.Fatalf("Error in dataSourceVirtualEnvironmentAccessRoles.Schema: Missing attribute \"%s\"", v)
|
t.Fatalf("Error in dataSourceVirtualEnvironmentRoles.Schema: Missing attribute \"%s\"", v)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Schema[v].Computed != true {
|
if s.Schema[v].Computed != true {
|
||||||
t.Fatalf("Error in dataSourceVirtualEnvironmentAccessRoles.Schema: Attribute \"%s\" is not computed", v)
|
t.Fatalf("Error in dataSourceVirtualEnvironmentRoles.Schema: Attribute \"%s\" is not computed", v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
data "proxmox_virtual_environment_access_group" "example" {
|
|
||||||
group_id = "${proxmox_virtual_environment_access_group.example.id}"
|
|
||||||
}
|
|
||||||
|
|
||||||
output "data_proxmox_virtual_environment_access_group_example_comments" {
|
|
||||||
value = "${data.proxmox_virtual_environment_access_group.example.*.comment}"
|
|
||||||
}
|
|
||||||
|
|
||||||
output "data_proxmox_virtual_environment_access_group_example_members" {
|
|
||||||
value = "${data.proxmox_virtual_environment_access_group.example.*.members}"
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
data "proxmox_virtual_environment_access_groups" "example" {}
|
|
||||||
|
|
||||||
output "data_proxmox_virtual_environment_access_groups_example" {
|
|
||||||
value = "${map(
|
|
||||||
"comments", data.proxmox_virtual_environment_access_groups.example.comments,
|
|
||||||
"group_ids", data.proxmox_virtual_environment_access_groups.example.group_ids,
|
|
||||||
)}"
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
data "proxmox_virtual_environment_access_role" "example" {
|
|
||||||
role_id = "${proxmox_virtual_environment_access_role.example.id}"
|
|
||||||
}
|
|
||||||
|
|
||||||
output "data_proxmox_virtual_environment_access_role_example_privileges" {
|
|
||||||
value = "${data.proxmox_virtual_environment_access_role.example.privileges}"
|
|
||||||
}
|
|
||||||
|
|
||||||
output "data_proxmox_virtual_environment_access_role_example_role_id" {
|
|
||||||
value = "${data.proxmox_virtual_environment_access_role.example.id}"
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
data "proxmox_virtual_environment_access_roles" "example" {}
|
|
||||||
|
|
||||||
output "data_proxmox_virtual_environment_access_roles_example_privileges" {
|
|
||||||
value = "${data.proxmox_virtual_environment_access_roles.example.privileges}"
|
|
||||||
}
|
|
||||||
|
|
||||||
output "data_proxmox_virtual_environment_access_roles_example_role_ids" {
|
|
||||||
value = "${data.proxmox_virtual_environment_access_roles.example.role_ids}"
|
|
||||||
}
|
|
||||||
|
|
||||||
output "data_proxmox_virtual_environment_access_roles_example_special" {
|
|
||||||
value = "${data.proxmox_virtual_environment_access_roles.example.special}"
|
|
||||||
}
|
|
11
example/data_source_virtual_environment_group.tf
Normal file
11
example/data_source_virtual_environment_group.tf
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
data "proxmox_virtual_environment_group" "example" {
|
||||||
|
group_id = "${proxmox_virtual_environment_group.example.id}"
|
||||||
|
}
|
||||||
|
|
||||||
|
output "data_proxmox_virtual_environment_group_example_comments" {
|
||||||
|
value = "${data.proxmox_virtual_environment_group.example.*.comment}"
|
||||||
|
}
|
||||||
|
|
||||||
|
output "data_proxmox_virtual_environment_group_example_members" {
|
||||||
|
value = "${data.proxmox_virtual_environment_group.example.*.members}"
|
||||||
|
}
|
8
example/data_source_virtual_environment_groups.tf
Normal file
8
example/data_source_virtual_environment_groups.tf
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
data "proxmox_virtual_environment_groups" "example" {}
|
||||||
|
|
||||||
|
output "data_proxmox_virtual_environment_groups_example" {
|
||||||
|
value = "${map(
|
||||||
|
"comments", data.proxmox_virtual_environment_groups.example.comments,
|
||||||
|
"group_ids", data.proxmox_virtual_environment_groups.example.group_ids,
|
||||||
|
)}"
|
||||||
|
}
|
11
example/data_source_virtual_environment_role.tf
Normal file
11
example/data_source_virtual_environment_role.tf
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
data "proxmox_virtual_environment_role" "example" {
|
||||||
|
role_id = "${proxmox_virtual_environment_role.example.id}"
|
||||||
|
}
|
||||||
|
|
||||||
|
output "data_proxmox_virtual_environment_role_example_privileges" {
|
||||||
|
value = "${data.proxmox_virtual_environment_role.example.privileges}"
|
||||||
|
}
|
||||||
|
|
||||||
|
output "data_proxmox_virtual_environment_role_example_role_id" {
|
||||||
|
value = "${data.proxmox_virtual_environment_role.example.id}"
|
||||||
|
}
|
13
example/data_source_virtual_environment_roles.tf
Normal file
13
example/data_source_virtual_environment_roles.tf
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
data "proxmox_virtual_environment_roles" "example" {}
|
||||||
|
|
||||||
|
output "data_proxmox_virtual_environment_roles_example_privileges" {
|
||||||
|
value = "${data.proxmox_virtual_environment_roles.example.privileges}"
|
||||||
|
}
|
||||||
|
|
||||||
|
output "data_proxmox_virtual_environment_roles_example_role_ids" {
|
||||||
|
value = "${data.proxmox_virtual_environment_roles.example.role_ids}"
|
||||||
|
}
|
||||||
|
|
||||||
|
output "data_proxmox_virtual_environment_roles_example_special" {
|
||||||
|
value = "${data.proxmox_virtual_environment_roles.example.special}"
|
||||||
|
}
|
@ -1,16 +0,0 @@
|
|||||||
resource "proxmox_virtual_environment_access_group" "example" {
|
|
||||||
comment = "Created by Terraform"
|
|
||||||
group_id = "terraform-provider-proxmox-example"
|
|
||||||
}
|
|
||||||
|
|
||||||
output "resource_proxmox_virtual_environment_access_group_example_comment" {
|
|
||||||
value = "${proxmox_virtual_environment_access_group.example.comment}"
|
|
||||||
}
|
|
||||||
|
|
||||||
output "resource_proxmox_virtual_environment_access_group_example_id" {
|
|
||||||
value = "${proxmox_virtual_environment_access_group.example.id}"
|
|
||||||
}
|
|
||||||
|
|
||||||
output "resource_proxmox_virtual_environment_access_group_example_members" {
|
|
||||||
value = "${proxmox_virtual_environment_access_group.example.members}"
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
resource "proxmox_virtual_environment_access_role" "example" {
|
|
||||||
privileges = [
|
|
||||||
"VM.Monitor",
|
|
||||||
]
|
|
||||||
role_id = "terraform-provider-proxmox-example"
|
|
||||||
}
|
|
||||||
|
|
||||||
output "resource_proxmox_virtual_environment_access_role_example_privileges" {
|
|
||||||
value = "${proxmox_virtual_environment_access_role.example.privileges}"
|
|
||||||
}
|
|
||||||
|
|
||||||
output "resource_proxmox_virtual_environment_access_role_example_role_id" {
|
|
||||||
value = "${proxmox_virtual_environment_access_role.example.role_id}"
|
|
||||||
}
|
|
16
example/resource_virtual_environment_group.tf
Normal file
16
example/resource_virtual_environment_group.tf
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
resource "proxmox_virtual_environment_group" "example" {
|
||||||
|
comment = "Created by Terraform"
|
||||||
|
group_id = "terraform-provider-proxmox-example"
|
||||||
|
}
|
||||||
|
|
||||||
|
output "resource_proxmox_virtual_environment_group_example_comment" {
|
||||||
|
value = "${proxmox_virtual_environment_group.example.comment}"
|
||||||
|
}
|
||||||
|
|
||||||
|
output "resource_proxmox_virtual_environment_group_example_id" {
|
||||||
|
value = "${proxmox_virtual_environment_group.example.id}"
|
||||||
|
}
|
||||||
|
|
||||||
|
output "resource_proxmox_virtual_environment_group_example_members" {
|
||||||
|
value = "${proxmox_virtual_environment_group.example.members}"
|
||||||
|
}
|
14
example/resource_virtual_environment_role.tf
Normal file
14
example/resource_virtual_environment_role.tf
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
resource "proxmox_virtual_environment_role" "example" {
|
||||||
|
privileges = [
|
||||||
|
"VM.Monitor",
|
||||||
|
]
|
||||||
|
role_id = "terraform-provider-proxmox-example"
|
||||||
|
}
|
||||||
|
|
||||||
|
output "resource_proxmox_virtual_environment_role_example_privileges" {
|
||||||
|
value = "${proxmox_virtual_environment_role.example.privileges}"
|
||||||
|
}
|
||||||
|
|
||||||
|
output "resource_proxmox_virtual_environment_role_example_role_id" {
|
||||||
|
value = "${proxmox_virtual_environment_role.example.role_id}"
|
||||||
|
}
|
14
provider.go
14
provider.go
@ -28,15 +28,15 @@ func Provider() *schema.Provider {
|
|||||||
return &schema.Provider{
|
return &schema.Provider{
|
||||||
ConfigureFunc: providerConfigure,
|
ConfigureFunc: providerConfigure,
|
||||||
DataSourcesMap: map[string]*schema.Resource{
|
DataSourcesMap: map[string]*schema.Resource{
|
||||||
"proxmox_virtual_environment_access_group": dataSourceVirtualEnvironmentAccessGroup(),
|
"proxmox_virtual_environment_group": dataSourceVirtualEnvironmentGroup(),
|
||||||
"proxmox_virtual_environment_access_groups": dataSourceVirtualEnvironmentAccessGroups(),
|
"proxmox_virtual_environment_groups": dataSourceVirtualEnvironmentGroups(),
|
||||||
"proxmox_virtual_environment_access_role": dataSourceVirtualEnvironmentAccessRole(),
|
"proxmox_virtual_environment_role": dataSourceVirtualEnvironmentRole(),
|
||||||
"proxmox_virtual_environment_access_roles": dataSourceVirtualEnvironmentAccessRoles(),
|
"proxmox_virtual_environment_roles": dataSourceVirtualEnvironmentRoles(),
|
||||||
"proxmox_virtual_environment_version": dataSourceVirtualEnvironmentVersion(),
|
"proxmox_virtual_environment_version": dataSourceVirtualEnvironmentVersion(),
|
||||||
},
|
},
|
||||||
ResourcesMap: map[string]*schema.Resource{
|
ResourcesMap: map[string]*schema.Resource{
|
||||||
"proxmox_virtual_environment_access_group": resourceVirtualEnvironmentAccessGroup(),
|
"proxmox_virtual_environment_group": resourceVirtualEnvironmentGroup(),
|
||||||
"proxmox_virtual_environment_access_role": resourceVirtualEnvironmentAccessRole(),
|
"proxmox_virtual_environment_role": resourceVirtualEnvironmentRole(),
|
||||||
},
|
},
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
mkProviderVirtualEnvironment: &schema.Schema{
|
mkProviderVirtualEnvironment: &schema.Schema{
|
||||||
|
@ -148,7 +148,7 @@ func (c *VirtualEnvironmentClient) ValidateResponseCode(res *http.Response) erro
|
|||||||
case 404:
|
case 404:
|
||||||
return fmt.Errorf("Received a HTTP %d response - Please verify that the endpoint refers to a supported version of the Proxmox Virtual Environment API", res.StatusCode)
|
return fmt.Errorf("Received a HTTP %d response - Please verify that the endpoint refers to a supported version of the Proxmox Virtual Environment API", res.StatusCode)
|
||||||
case 500:
|
case 500:
|
||||||
return fmt.Errorf("Received a HTTP %d response - Please verify that Proxmox Virtual Environment is healthy", res.StatusCode)
|
return fmt.Errorf("Received a HTTP %d response - Please verify that the Proxmox Virtual Environment API is healthy", res.StatusCode)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Received a HTTP %d response", res.StatusCode)
|
return fmt.Errorf("Received a HTTP %d response", res.StatusCode)
|
||||||
}
|
}
|
||||||
|
@ -1,98 +0,0 @@
|
|||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
package proxmox
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"net/url"
|
|
||||||
"sort"
|
|
||||||
)
|
|
||||||
|
|
||||||
// VirtualEnvironmentAccessGroupCreateRequestBody contains the data for an access group create request.
|
|
||||||
type VirtualEnvironmentAccessGroupCreateRequestBody struct {
|
|
||||||
Comment string `json:"comment" url:"comment"`
|
|
||||||
ID string `json:"groupid" url:"groupid"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// VirtualEnvironmentAccessGroupGetResponseBody contains the body from an access group get response.
|
|
||||||
type VirtualEnvironmentAccessGroupGetResponseBody struct {
|
|
||||||
Data *VirtualEnvironmentAccessGroupGetResponseData `json:"data,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// VirtualEnvironmentAccessGroupGetResponseData contains the data from an access group get response.
|
|
||||||
type VirtualEnvironmentAccessGroupGetResponseData struct {
|
|
||||||
Comment string `json:"comment"`
|
|
||||||
Members []string `json:"members"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// VirtualEnvironmentAccessGroupListResponseBody contains the body from an access group list response.
|
|
||||||
type VirtualEnvironmentAccessGroupListResponseBody struct {
|
|
||||||
Data []*VirtualEnvironmentAccessGroupListResponseData `json:"data,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// VirtualEnvironmentAccessGroupListResponseData contains the data from an access group list response.
|
|
||||||
type VirtualEnvironmentAccessGroupListResponseData struct {
|
|
||||||
Comment string `json:"comment"`
|
|
||||||
ID string `json:"groupid"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// VirtualEnvironmentAccessGroupUpdateRequestBody contains the data for an access group update request.
|
|
||||||
type VirtualEnvironmentAccessGroupUpdateRequestBody struct {
|
|
||||||
Comment string `json:"comment" url:"comment"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateAccessGroup creates an access group.
|
|
||||||
func (c *VirtualEnvironmentClient) CreateAccessGroup(d *VirtualEnvironmentAccessGroupCreateRequestBody) error {
|
|
||||||
return c.DoRequest(hmPOST, "access/groups", d, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteAccessGroup deletes an access group.
|
|
||||||
func (c *VirtualEnvironmentClient) DeleteAccessGroup(id string) error {
|
|
||||||
return c.DoRequest(hmDELETE, fmt.Sprintf("access/groups/%s", id), nil, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetAccessGroup retrieves an access group.
|
|
||||||
func (c *VirtualEnvironmentClient) GetAccessGroup(id string) (*VirtualEnvironmentAccessGroupGetResponseData, error) {
|
|
||||||
resBody := &VirtualEnvironmentAccessGroupGetResponseBody{}
|
|
||||||
err := c.DoRequest(hmGET, fmt.Sprintf("access/groups/%s", url.PathEscape(id)), nil, resBody)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resBody.Data == nil {
|
|
||||||
return nil, errors.New("The server did not include a data object in the response")
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Strings(resBody.Data.Members)
|
|
||||||
|
|
||||||
return resBody.Data, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListAccessGroups retrieves a list of access groups.
|
|
||||||
func (c *VirtualEnvironmentClient) ListAccessGroups() ([]*VirtualEnvironmentAccessGroupListResponseData, error) {
|
|
||||||
resBody := &VirtualEnvironmentAccessGroupListResponseBody{}
|
|
||||||
err := c.DoRequest(hmGET, "access/groups", nil, resBody)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resBody.Data == nil {
|
|
||||||
return nil, errors.New("The server did not include a data object in the response")
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Slice(resBody.Data, func(i, j int) bool {
|
|
||||||
return resBody.Data[i].ID < resBody.Data[j].ID
|
|
||||||
})
|
|
||||||
|
|
||||||
return resBody.Data, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateAccessGroup updates an access group.
|
|
||||||
func (c *VirtualEnvironmentClient) UpdateAccessGroup(id string, d *VirtualEnvironmentAccessGroupUpdateRequestBody) error {
|
|
||||||
return c.DoRequest(hmPUT, fmt.Sprintf("access/groups/%s", id), d, nil)
|
|
||||||
}
|
|
@ -1,93 +0,0 @@
|
|||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
package proxmox
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"net/url"
|
|
||||||
"sort"
|
|
||||||
)
|
|
||||||
|
|
||||||
// VirtualEnvironmentAccessRoleCreateRequestBody contains the data for an access group create request.
|
|
||||||
type VirtualEnvironmentAccessRoleCreateRequestBody struct {
|
|
||||||
ID string `json:"roleid" url:"roleid"`
|
|
||||||
Privileges CustomPrivileges `json:"privs" url:"privs,comma"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// VirtualEnvironmentAccessRoleGetResponseBody contains the body from an access group get response.
|
|
||||||
type VirtualEnvironmentAccessRoleGetResponseBody struct {
|
|
||||||
Data *CustomPrivileges `json:"data,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// VirtualEnvironmentAccessRoleListResponseBody contains the body from an access group list response.
|
|
||||||
type VirtualEnvironmentAccessRoleListResponseBody struct {
|
|
||||||
Data []*VirtualEnvironmentAccessRoleListResponseData `json:"data,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// VirtualEnvironmentAccessRoleListResponseData contains the data from an access group list response.
|
|
||||||
type VirtualEnvironmentAccessRoleListResponseData struct {
|
|
||||||
ID string `json:"roleid"`
|
|
||||||
Privileges *CustomPrivileges `json:"privs"`
|
|
||||||
Special CustomBool `json:"special"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// VirtualEnvironmentAccessRoleUpdateRequestBody contains the data for an access group update request.
|
|
||||||
type VirtualEnvironmentAccessRoleUpdateRequestBody struct {
|
|
||||||
Privileges CustomPrivileges `json:"privs" url:"privs,comma"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateAccessRole creates an access role.
|
|
||||||
func (c *VirtualEnvironmentClient) CreateAccessRole(d *VirtualEnvironmentAccessRoleCreateRequestBody) error {
|
|
||||||
return c.DoRequest(hmPOST, "access/roles", d, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteAccessRole deletes an access role.
|
|
||||||
func (c *VirtualEnvironmentClient) DeleteAccessRole(id string) error {
|
|
||||||
return c.DoRequest(hmDELETE, fmt.Sprintf("access/roles/%s", id), nil, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetAccessRole retrieves an access role.
|
|
||||||
func (c *VirtualEnvironmentClient) GetAccessRole(id string) (*CustomPrivileges, error) {
|
|
||||||
resBody := &VirtualEnvironmentAccessRoleGetResponseBody{}
|
|
||||||
err := c.DoRequest(hmGET, fmt.Sprintf("access/roles/%s", url.PathEscape(id)), nil, resBody)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resBody.Data == nil {
|
|
||||||
return nil, errors.New("The server did not include a data object in the response")
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Strings(*resBody.Data)
|
|
||||||
|
|
||||||
return resBody.Data, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListAccessRoles retrieves a list of access roles.
|
|
||||||
func (c *VirtualEnvironmentClient) ListAccessRoles() ([]*VirtualEnvironmentAccessRoleListResponseData, error) {
|
|
||||||
resBody := &VirtualEnvironmentAccessRoleListResponseBody{}
|
|
||||||
err := c.DoRequest(hmGET, "access/roles", nil, resBody)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if resBody.Data == nil {
|
|
||||||
return nil, errors.New("The server did not include a data object in the response")
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Slice(resBody.Data, func(i, j int) bool {
|
|
||||||
return resBody.Data[i].ID < resBody.Data[j].ID
|
|
||||||
})
|
|
||||||
|
|
||||||
return resBody.Data, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateAccessRole updates an access role.
|
|
||||||
func (c *VirtualEnvironmentClient) UpdateAccessRole(id string, d *VirtualEnvironmentAccessRoleUpdateRequestBody) error {
|
|
||||||
return c.DoRequest(hmPUT, fmt.Sprintf("access/roles/%s", id), d, nil)
|
|
||||||
}
|
|
98
proxmox/virtual_environment_groups.go
Normal file
98
proxmox/virtual_environment_groups.go
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package proxmox
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"sort"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// VirtualEnvironmentGroupGetResponseBody contains the body from an access group get response.
|
||||||
|
type VirtualEnvironmentGroupGetResponseBody struct {
|
||||||
|
Data *VirtualEnvironmentGroupGetResponseData `json:"data,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// VirtualEnvironmentGroupGetResponseData contains the data from an access group get response.
|
||||||
|
type VirtualEnvironmentGroupGetResponseData struct {
|
||||||
|
Comment string `json:"comment"`
|
||||||
|
Members []string `json:"members"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// VirtualEnvironmentGroupListResponseBody contains the body from an access group list response.
|
||||||
|
type VirtualEnvironmentGroupListResponseBody struct {
|
||||||
|
Data []*VirtualEnvironmentGroupListResponseData `json:"data,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// VirtualEnvironmentGroupListResponseData contains the data from an access group list response.
|
||||||
|
type VirtualEnvironmentGroupListResponseData struct {
|
||||||
|
Comment string `json:"comment"`
|
||||||
|
ID string `json:"groupid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// VirtualEnvironmentGroupUpdateRequestBody contains the data for an access group update request.
|
||||||
|
type VirtualEnvironmentGroupUpdateRequestBody struct {
|
||||||
|
Comment string `json:"comment" url:"comment"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateGroup creates an access group.
|
||||||
|
func (c *VirtualEnvironmentClient) CreateGroup(d *VirtualEnvironmentGroupCreateRequestBody) error {
|
||||||
|
return c.DoRequest(hmPOST, "access/groups", d, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteGroup deletes an access group.
|
||||||
|
func (c *VirtualEnvironmentClient) DeleteGroup(id string) error {
|
||||||
|
return c.DoRequest(hmDELETE, fmt.Sprintf("access/groups/%s", id), nil, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGroup retrieves an access group.
|
||||||
|
func (c *VirtualEnvironmentClient) GetGroup(id string) (*VirtualEnvironmentGroupGetResponseData, error) {
|
||||||
|
resBody := &VirtualEnvironmentGroupGetResponseBody{}
|
||||||
|
err := c.DoRequest(hmGET, fmt.Sprintf("access/groups/%s", url.PathEscape(id)), nil, resBody)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resBody.Data == nil {
|
||||||
|
return nil, errors.New("The server did not include a data object in the response")
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Strings(resBody.Data.Members)
|
||||||
|
|
||||||
|
return resBody.Data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListGroups retrieves a list of access groups.
|
||||||
|
func (c *VirtualEnvironmentClient) ListGroups() ([]*VirtualEnvironmentGroupListResponseData, error) {
|
||||||
|
resBody := &VirtualEnvironmentGroupListResponseBody{}
|
||||||
|
err := c.DoRequest(hmGET, "access/groups", nil, resBody)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resBody.Data == nil {
|
||||||
|
return nil, errors.New("The server did not include a data object in the response")
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(resBody.Data, func(i, j int) bool {
|
||||||
|
return resBody.Data[i].ID < resBody.Data[j].ID
|
||||||
|
})
|
||||||
|
|
||||||
|
return resBody.Data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateGroup updates an access group.
|
||||||
|
func (c *VirtualEnvironmentClient) UpdateGroup(id string, d *VirtualEnvironmentGroupUpdateRequestBody) error {
|
||||||
|
return c.DoRequest(hmPUT, fmt.Sprintf("access/groups/%s", id), d, nil)
|
||||||
|
}
|
93
proxmox/virtual_environment_roles.go
Normal file
93
proxmox/virtual_environment_roles.go
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package proxmox
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"sort"
|
||||||
|
)
|
||||||
|
|
||||||
|
// VirtualEnvironmentRoleCreateRequestBody contains the data for an access group create request.
|
||||||
|
type VirtualEnvironmentRoleCreateRequestBody struct {
|
||||||
|
ID string `json:"roleid" url:"roleid"`
|
||||||
|
Privileges CustomPrivileges `json:"privs" url:"privs,comma"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// VirtualEnvironmentRoleGetResponseBody contains the body from an access group get response.
|
||||||
|
type VirtualEnvironmentRoleGetResponseBody struct {
|
||||||
|
Data *CustomPrivileges `json:"data,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// VirtualEnvironmentRoleListResponseBody contains the body from an access group list response.
|
||||||
|
type VirtualEnvironmentRoleListResponseBody struct {
|
||||||
|
Data []*VirtualEnvironmentRoleListResponseData `json:"data,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// VirtualEnvironmentRoleUpdateRequestBody contains the data for an access group update request.
|
||||||
|
type VirtualEnvironmentRoleUpdateRequestBody struct {
|
||||||
|
Privileges CustomPrivileges `json:"privs" url:"privs,comma"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateRole creates an access role.
|
||||||
|
func (c *VirtualEnvironmentClient) CreateRole(d *VirtualEnvironmentRoleCreateRequestBody) error {
|
||||||
|
return c.DoRequest(hmPOST, "access/roles", d, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteRole deletes an access role.
|
||||||
|
func (c *VirtualEnvironmentClient) DeleteRole(id string) error {
|
||||||
|
return c.DoRequest(hmDELETE, fmt.Sprintf("access/roles/%s", id), nil, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRole retrieves an access role.
|
||||||
|
func (c *VirtualEnvironmentClient) GetRole(id string) (*CustomPrivileges, error) {
|
||||||
|
resBody := &VirtualEnvironmentRoleGetResponseBody{}
|
||||||
|
err := c.DoRequest(hmGET, fmt.Sprintf("access/roles/%s", url.PathEscape(id)), nil, resBody)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resBody.Data == nil {
|
||||||
|
return nil, errors.New("The server did not include a data object in the response")
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Strings(*resBody.Data)
|
||||||
|
|
||||||
|
return resBody.Data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRoles retrieves a list of access roles.
|
||||||
|
func (c *VirtualEnvironmentClient) ListRoles() ([]*VirtualEnvironmentRoleListResponseData, error) {
|
||||||
|
resBody := &VirtualEnvironmentRoleListResponseBody{}
|
||||||
|
err := c.DoRequest(hmGET, "access/roles", nil, resBody)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resBody.Data == nil {
|
||||||
|
return nil, errors.New("The server did not include a data object in the response")
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(resBody.Data, func(i, j int) bool {
|
||||||
|
return resBody.Data[i].ID < resBody.Data[j].ID
|
||||||
|
})
|
||||||
|
|
||||||
|
return resBody.Data, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateRole updates an access role.
|
||||||
|
func (c *VirtualEnvironmentClient) UpdateRole(id string, d *VirtualEnvironmentRoleUpdateRequestBody) error {
|
||||||
|
return c.DoRequest(hmPUT, fmt.Sprintf("access/roles/%s", id), d, nil)
|
||||||
|
}
|
@ -12,40 +12,40 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
mkResourceVirtualEnvironmentAccessGroupComment = "comment"
|
mkResourceVirtualEnvironmentGroupComment = "comment"
|
||||||
mkResourceVirtualEnvironmentAccessGroupID = "group_id"
|
mkResourceVirtualEnvironmentGroupID = "group_id"
|
||||||
mkResourceVirtualEnvironmentAccessGroupMembers = "members"
|
mkResourceVirtualEnvironmentGroupMembers = "members"
|
||||||
)
|
)
|
||||||
|
|
||||||
func resourceVirtualEnvironmentAccessGroup() *schema.Resource {
|
func resourceVirtualEnvironmentGroup() *schema.Resource {
|
||||||
return &schema.Resource{
|
return &schema.Resource{
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
mkResourceVirtualEnvironmentAccessGroupComment: &schema.Schema{
|
mkResourceVirtualEnvironmentGroupComment: &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Description: "The group comment",
|
Description: "The group comment",
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Default: "",
|
Default: "",
|
||||||
},
|
},
|
||||||
mkResourceVirtualEnvironmentAccessGroupID: &schema.Schema{
|
mkResourceVirtualEnvironmentGroupID: &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Description: "The group id",
|
Description: "The group id",
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
mkResourceVirtualEnvironmentAccessGroupMembers: &schema.Schema{
|
mkResourceVirtualEnvironmentGroupMembers: &schema.Schema{
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
Description: "The group members",
|
Description: "The group members",
|
||||||
Computed: true,
|
Computed: true,
|
||||||
Elem: &schema.Schema{Type: schema.TypeString},
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Create: resourceVirtualEnvironmentAccessGroupCreate,
|
Create: resourceVirtualEnvironmentGroupCreate,
|
||||||
Read: resourceVirtualEnvironmentAccessGroupRead,
|
Read: resourceVirtualEnvironmentGroupRead,
|
||||||
Update: resourceVirtualEnvironmentAccessGroupUpdate,
|
Update: resourceVirtualEnvironmentGroupUpdate,
|
||||||
Delete: resourceVirtualEnvironmentAccessGroupDelete,
|
Delete: resourceVirtualEnvironmentGroupDelete,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceVirtualEnvironmentAccessGroupCreate(d *schema.ResourceData, m interface{}) error {
|
func resourceVirtualEnvironmentGroupCreate(d *schema.ResourceData, m interface{}) error {
|
||||||
config := m.(providerConfiguration)
|
config := m.(providerConfiguration)
|
||||||
veClient, err := config.GetVEClient()
|
veClient, err := config.GetVEClient()
|
||||||
|
|
||||||
@ -53,13 +53,13 @@ func resourceVirtualEnvironmentAccessGroupCreate(d *schema.ResourceData, m inter
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
groupID := d.Get(mkResourceVirtualEnvironmentAccessGroupID).(string)
|
groupID := d.Get(mkResourceVirtualEnvironmentGroupID).(string)
|
||||||
body := &proxmox.VirtualEnvironmentAccessGroupCreateRequestBody{
|
body := &proxmox.VirtualEnvironmentGroupCreateRequestBody{
|
||||||
Comment: d.Get(mkResourceVirtualEnvironmentAccessGroupComment).(string),
|
Comment: d.Get(mkResourceVirtualEnvironmentGroupComment).(string),
|
||||||
ID: groupID,
|
ID: groupID,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = veClient.CreateAccessGroup(body)
|
err = veClient.CreateGroup(body)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -67,10 +67,10 @@ func resourceVirtualEnvironmentAccessGroupCreate(d *schema.ResourceData, m inter
|
|||||||
|
|
||||||
d.SetId(groupID)
|
d.SetId(groupID)
|
||||||
|
|
||||||
return resourceVirtualEnvironmentAccessGroupRead(d, m)
|
return resourceVirtualEnvironmentGroupRead(d, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceVirtualEnvironmentAccessGroupRead(d *schema.ResourceData, m interface{}) error {
|
func resourceVirtualEnvironmentGroupRead(d *schema.ResourceData, m interface{}) error {
|
||||||
config := m.(providerConfiguration)
|
config := m.(providerConfiguration)
|
||||||
veClient, err := config.GetVEClient()
|
veClient, err := config.GetVEClient()
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ func resourceVirtualEnvironmentAccessGroupRead(d *schema.ResourceData, m interfa
|
|||||||
}
|
}
|
||||||
|
|
||||||
groupID := d.Id()
|
groupID := d.Id()
|
||||||
accessGroup, err := veClient.GetAccessGroup(groupID)
|
accessGroup, err := veClient.GetGroup(groupID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.Contains(err.Error(), "HTTP 404") {
|
if strings.Contains(err.Error(), "HTTP 404") {
|
||||||
@ -93,13 +93,13 @@ func resourceVirtualEnvironmentAccessGroupRead(d *schema.ResourceData, m interfa
|
|||||||
|
|
||||||
d.SetId(groupID)
|
d.SetId(groupID)
|
||||||
|
|
||||||
d.Set(mkResourceVirtualEnvironmentAccessGroupComment, accessGroup.Comment)
|
d.Set(mkResourceVirtualEnvironmentGroupComment, accessGroup.Comment)
|
||||||
d.Set(mkResourceVirtualEnvironmentAccessGroupMembers, accessGroup.Members)
|
d.Set(mkResourceVirtualEnvironmentGroupMembers, accessGroup.Members)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceVirtualEnvironmentAccessGroupUpdate(d *schema.ResourceData, m interface{}) error {
|
func resourceVirtualEnvironmentGroupUpdate(d *schema.ResourceData, m interface{}) error {
|
||||||
config := m.(providerConfiguration)
|
config := m.(providerConfiguration)
|
||||||
veClient, err := config.GetVEClient()
|
veClient, err := config.GetVEClient()
|
||||||
|
|
||||||
@ -107,21 +107,21 @@ func resourceVirtualEnvironmentAccessGroupUpdate(d *schema.ResourceData, m inter
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
body := &proxmox.VirtualEnvironmentAccessGroupUpdateRequestBody{
|
body := &proxmox.VirtualEnvironmentGroupUpdateRequestBody{
|
||||||
Comment: d.Get(mkResourceVirtualEnvironmentAccessGroupComment).(string),
|
Comment: d.Get(mkResourceVirtualEnvironmentGroupComment).(string),
|
||||||
}
|
}
|
||||||
|
|
||||||
groupID := d.Id()
|
groupID := d.Id()
|
||||||
err = veClient.UpdateAccessGroup(groupID, body)
|
err = veClient.UpdateGroup(groupID, body)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return resourceVirtualEnvironmentAccessGroupRead(d, m)
|
return resourceVirtualEnvironmentGroupRead(d, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceVirtualEnvironmentAccessGroupDelete(d *schema.ResourceData, m interface{}) error {
|
func resourceVirtualEnvironmentGroupDelete(d *schema.ResourceData, m interface{}) error {
|
||||||
config := m.(providerConfiguration)
|
config := m.(providerConfiguration)
|
||||||
veClient, err := config.GetVEClient()
|
veClient, err := config.GetVEClient()
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ func resourceVirtualEnvironmentAccessGroupDelete(d *schema.ResourceData, m inter
|
|||||||
}
|
}
|
||||||
|
|
||||||
groupID := d.Id()
|
groupID := d.Id()
|
||||||
err = veClient.DeleteAccessGroup(groupID)
|
err = veClient.DeleteGroup(groupID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.Contains(err.Error(), "HTTP 404") {
|
if strings.Contains(err.Error(), "HTTP 404") {
|
||||||
|
@ -8,30 +8,30 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestResourceVirtualEnvironmentAccessGroupInstantiation tests whether the ResourceVirtualEnvironmentAccessGroup instance can be instantiated.
|
// TestResourceVirtualEnvironmentGroupInstantiation tests whether the ResourceVirtualEnvironmentGroup instance can be instantiated.
|
||||||
func TestResourceVirtualEnvironmentAccessGroupInstantiation(t *testing.T) {
|
func TestResourceVirtualEnvironmentGroupInstantiation(t *testing.T) {
|
||||||
s := resourceVirtualEnvironmentAccessGroup()
|
s := resourceVirtualEnvironmentGroup()
|
||||||
|
|
||||||
if s == nil {
|
if s == nil {
|
||||||
t.Fatalf("Cannot instantiate resourceVirtualEnvironmentAccessGroup")
|
t.Fatalf("Cannot instantiate resourceVirtualEnvironmentGroup")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestResourceVirtualEnvironmentAccessGroupSchema tests the resourceVirtualEnvironmentAccessGroup schema.
|
// TestResourceVirtualEnvironmentGroupSchema tests the resourceVirtualEnvironmentGroup schema.
|
||||||
func TestResourceVirtualEnvironmentAccessGroupSchema(t *testing.T) {
|
func TestResourceVirtualEnvironmentGroupSchema(t *testing.T) {
|
||||||
s := resourceVirtualEnvironmentAccessGroup()
|
s := resourceVirtualEnvironmentGroup()
|
||||||
|
|
||||||
attributeKeys := []string{
|
attributeKeys := []string{
|
||||||
mkResourceVirtualEnvironmentAccessGroupMembers,
|
mkResourceVirtualEnvironmentGroupMembers,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range attributeKeys {
|
for _, v := range attributeKeys {
|
||||||
if s.Schema[v] == nil {
|
if s.Schema[v] == nil {
|
||||||
t.Fatalf("Error in resourceVirtualEnvironmentAccessGroup.Schema: Missing attribute \"%s\"", v)
|
t.Fatalf("Error in resourceVirtualEnvironmentGroup.Schema: Missing attribute \"%s\"", v)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Schema[v].Computed != true {
|
if s.Schema[v].Computed != true {
|
||||||
t.Fatalf("Error in resourceVirtualEnvironmentAccessGroup.Schema: Attribute \"%s\" is not computed", v)
|
t.Fatalf("Error in resourceVirtualEnvironmentGroup.Schema: Attribute \"%s\" is not computed", v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,33 +12,33 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
mkResourceVirtualEnvironmentAccessRolePrivileges = "privileges"
|
mkResourceVirtualEnvironmentRolePrivileges = "privileges"
|
||||||
mkResourceVirtualEnvironmentAccessRoleRoleID = "role_id"
|
mkResourceVirtualEnvironmentRoleRoleID = "role_id"
|
||||||
)
|
)
|
||||||
|
|
||||||
func resourceVirtualEnvironmentAccessRole() *schema.Resource {
|
func resourceVirtualEnvironmentRole() *schema.Resource {
|
||||||
return &schema.Resource{
|
return &schema.Resource{
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
mkResourceVirtualEnvironmentAccessRolePrivileges: &schema.Schema{
|
mkResourceVirtualEnvironmentRolePrivileges: &schema.Schema{
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
Description: "The role privileges",
|
Description: "The role privileges",
|
||||||
Required: true,
|
Required: true,
|
||||||
Elem: &schema.Schema{Type: schema.TypeString},
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
},
|
},
|
||||||
mkResourceVirtualEnvironmentAccessRoleRoleID: &schema.Schema{
|
mkResourceVirtualEnvironmentRoleRoleID: &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Description: "The role id",
|
Description: "The role id",
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Create: resourceVirtualEnvironmentAccessRoleCreate,
|
Create: resourceVirtualEnvironmentRoleCreate,
|
||||||
Read: resourceVirtualEnvironmentAccessRoleRead,
|
Read: resourceVirtualEnvironmentRoleRead,
|
||||||
Update: resourceVirtualEnvironmentAccessRoleUpdate,
|
Update: resourceVirtualEnvironmentRoleUpdate,
|
||||||
Delete: resourceVirtualEnvironmentAccessRoleDelete,
|
Delete: resourceVirtualEnvironmentRoleDelete,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceVirtualEnvironmentAccessRoleCreate(d *schema.ResourceData, m interface{}) error {
|
func resourceVirtualEnvironmentRoleCreate(d *schema.ResourceData, m interface{}) error {
|
||||||
config := m.(providerConfiguration)
|
config := m.(providerConfiguration)
|
||||||
veClient, err := config.GetVEClient()
|
veClient, err := config.GetVEClient()
|
||||||
|
|
||||||
@ -46,8 +46,8 @@ func resourceVirtualEnvironmentAccessRoleCreate(d *schema.ResourceData, m interf
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
privileges := d.Get(mkResourceVirtualEnvironmentAccessRolePrivileges).([]interface{})
|
privileges := d.Get(mkResourceVirtualEnvironmentRolePrivileges).([]interface{})
|
||||||
roleID := d.Get(mkResourceVirtualEnvironmentAccessRoleRoleID).(string)
|
roleID := d.Get(mkResourceVirtualEnvironmentRoleRoleID).(string)
|
||||||
|
|
||||||
customPrivileges := make(proxmox.CustomPrivileges, len(privileges))
|
customPrivileges := make(proxmox.CustomPrivileges, len(privileges))
|
||||||
|
|
||||||
@ -55,12 +55,12 @@ func resourceVirtualEnvironmentAccessRoleCreate(d *schema.ResourceData, m interf
|
|||||||
customPrivileges[i] = v.(string)
|
customPrivileges[i] = v.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
body := &proxmox.VirtualEnvironmentAccessRoleCreateRequestBody{
|
body := &proxmox.VirtualEnvironmentRoleCreateRequestBody{
|
||||||
ID: roleID,
|
ID: roleID,
|
||||||
Privileges: customPrivileges,
|
Privileges: customPrivileges,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = veClient.CreateAccessRole(body)
|
err = veClient.CreateRole(body)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -68,10 +68,10 @@ func resourceVirtualEnvironmentAccessRoleCreate(d *schema.ResourceData, m interf
|
|||||||
|
|
||||||
d.SetId(roleID)
|
d.SetId(roleID)
|
||||||
|
|
||||||
return resourceVirtualEnvironmentAccessRoleRead(d, m)
|
return resourceVirtualEnvironmentRoleRead(d, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceVirtualEnvironmentAccessRoleRead(d *schema.ResourceData, m interface{}) error {
|
func resourceVirtualEnvironmentRoleRead(d *schema.ResourceData, m interface{}) error {
|
||||||
config := m.(providerConfiguration)
|
config := m.(providerConfiguration)
|
||||||
veClient, err := config.GetVEClient()
|
veClient, err := config.GetVEClient()
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ func resourceVirtualEnvironmentAccessRoleRead(d *schema.ResourceData, m interfac
|
|||||||
}
|
}
|
||||||
|
|
||||||
roleID := d.Id()
|
roleID := d.Id()
|
||||||
accessRole, err := veClient.GetAccessRole(roleID)
|
accessRole, err := veClient.GetRole(roleID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.Contains(err.Error(), "HTTP 404") {
|
if strings.Contains(err.Error(), "HTTP 404") {
|
||||||
@ -94,12 +94,12 @@ func resourceVirtualEnvironmentAccessRoleRead(d *schema.ResourceData, m interfac
|
|||||||
|
|
||||||
d.SetId(roleID)
|
d.SetId(roleID)
|
||||||
|
|
||||||
d.Set(mkResourceVirtualEnvironmentAccessRolePrivileges, *accessRole)
|
d.Set(mkResourceVirtualEnvironmentRolePrivileges, *accessRole)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceVirtualEnvironmentAccessRoleUpdate(d *schema.ResourceData, m interface{}) error {
|
func resourceVirtualEnvironmentRoleUpdate(d *schema.ResourceData, m interface{}) error {
|
||||||
config := m.(providerConfiguration)
|
config := m.(providerConfiguration)
|
||||||
veClient, err := config.GetVEClient()
|
veClient, err := config.GetVEClient()
|
||||||
|
|
||||||
@ -107,28 +107,28 @@ func resourceVirtualEnvironmentAccessRoleUpdate(d *schema.ResourceData, m interf
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
privileges := d.Get(mkResourceVirtualEnvironmentAccessRolePrivileges).([]interface{})
|
privileges := d.Get(mkResourceVirtualEnvironmentRolePrivileges).([]interface{})
|
||||||
customPrivileges := make(proxmox.CustomPrivileges, len(privileges))
|
customPrivileges := make(proxmox.CustomPrivileges, len(privileges))
|
||||||
|
|
||||||
for i, v := range privileges {
|
for i, v := range privileges {
|
||||||
customPrivileges[i] = v.(string)
|
customPrivileges[i] = v.(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
body := &proxmox.VirtualEnvironmentAccessRoleUpdateRequestBody{
|
body := &proxmox.VirtualEnvironmentRoleUpdateRequestBody{
|
||||||
Privileges: customPrivileges,
|
Privileges: customPrivileges,
|
||||||
}
|
}
|
||||||
|
|
||||||
roleID := d.Id()
|
roleID := d.Id()
|
||||||
err = veClient.UpdateAccessRole(roleID, body)
|
err = veClient.UpdateRole(roleID, body)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return resourceVirtualEnvironmentAccessRoleRead(d, m)
|
return resourceVirtualEnvironmentRoleRead(d, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceVirtualEnvironmentAccessRoleDelete(d *schema.ResourceData, m interface{}) error {
|
func resourceVirtualEnvironmentRoleDelete(d *schema.ResourceData, m interface{}) error {
|
||||||
config := m.(providerConfiguration)
|
config := m.(providerConfiguration)
|
||||||
veClient, err := config.GetVEClient()
|
veClient, err := config.GetVEClient()
|
||||||
|
|
||||||
@ -137,7 +137,7 @@ func resourceVirtualEnvironmentAccessRoleDelete(d *schema.ResourceData, m interf
|
|||||||
}
|
}
|
||||||
|
|
||||||
roleID := d.Id()
|
roleID := d.Id()
|
||||||
err = veClient.DeleteAccessRole(roleID)
|
err = veClient.DeleteRole(roleID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.Contains(err.Error(), "HTTP 404") {
|
if strings.Contains(err.Error(), "HTTP 404") {
|
||||||
|
@ -8,28 +8,28 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestResourceVirtualEnvironmentAccessRoleInstantiation tests whether the ResourceVirtualEnvironmentAccessRole instance can be instantiated.
|
// TestResourceVirtualEnvironmentRoleInstantiation tests whether the ResourceVirtualEnvironmentRole instance can be instantiated.
|
||||||
func TestResourceVirtualEnvironmentAccessRoleInstantiation(t *testing.T) {
|
func TestResourceVirtualEnvironmentRoleInstantiation(t *testing.T) {
|
||||||
s := resourceVirtualEnvironmentAccessRole()
|
s := resourceVirtualEnvironmentRole()
|
||||||
|
|
||||||
if s == nil {
|
if s == nil {
|
||||||
t.Fatalf("Cannot instantiate resourceVirtualEnvironmentAccessRole")
|
t.Fatalf("Cannot instantiate resourceVirtualEnvironmentRole")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestResourceVirtualEnvironmentAccessRoleSchema tests the resourceVirtualEnvironmentAccessRole schema.
|
// TestResourceVirtualEnvironmentRoleSchema tests the resourceVirtualEnvironmentRole schema.
|
||||||
func TestResourceVirtualEnvironmentAccessRoleSchema(t *testing.T) {
|
func TestResourceVirtualEnvironmentRoleSchema(t *testing.T) {
|
||||||
s := resourceVirtualEnvironmentAccessRole()
|
s := resourceVirtualEnvironmentRole()
|
||||||
|
|
||||||
attributeKeys := []string{}
|
attributeKeys := []string{}
|
||||||
|
|
||||||
for _, v := range attributeKeys {
|
for _, v := range attributeKeys {
|
||||||
if s.Schema[v] == nil {
|
if s.Schema[v] == nil {
|
||||||
t.Fatalf("Error in resourceVirtualEnvironmentAccessRole.Schema: Missing attribute \"%s\"", v)
|
t.Fatalf("Error in resourceVirtualEnvironmentRole.Schema: Missing attribute \"%s\"", v)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Schema[v].Computed != true {
|
if s.Schema[v].Computed != true {
|
||||||
t.Fatalf("Error in resourceVirtualEnvironmentAccessRole.Schema: Attribute \"%s\" is not computed", v)
|
t.Fatalf("Error in resourceVirtualEnvironmentRole.Schema: Attribute \"%s\" is not computed", v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user