diff --git a/.golangci.yml b/.golangci.yml index 6b6702b7..e6e7f3ba 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -23,6 +23,9 @@ issues: - path: _types\.go linters: - lll + - path: fwprovider/tests/.*\.go + linters: + - paralleltest linters-settings: exhaustive: default-signifies-exhaustive: true diff --git a/example/resource_virtual_environment_user.tf b/example/resource_virtual_environment_user.tf index 1e516ea3..919fcfd0 100644 --- a/example/resource_virtual_environment_user.tf +++ b/example/resource_virtual_environment_user.tf @@ -5,14 +5,15 @@ resource "proxmox_virtual_environment_user" "example" { role_id = "PVEVMAdmin" } - comment = "Managed by Terraform" - password = "Test1234!" - user_id = "terraform-provider-proxmox-example@pve" + comment = "Managed by Terraform" + password = "Test1234!" + user_id = "terraform-provider-proxmox-example@pve" + expiration_date = "2035-12-31T23:59:59Z" } resource "proxmox_virtual_environment_user" "example2" { - comment = "Managed by Terraform" - user_id = "terraform-provider-proxmox-example2@pve" + comment = "Managed by Terraform" + user_id = "terraform-provider-proxmox-example2@pve" } output "resource_proxmox_virtual_environment_user_example_acl" { diff --git a/fwprovider/tests/resource_container_test.go b/fwprovider/tests/resource_container_test.go index ea9f1589..f1d81230 100644 --- a/fwprovider/tests/resource_container_test.go +++ b/fwprovider/tests/resource_container_test.go @@ -21,7 +21,6 @@ const ( accTestContainerCloneName = "proxmox_virtual_environment_container.test_container_clone" ) -//nolint:paralleltest func TestAccResourceContainer(t *testing.T) { accProviders := testAccMuxProviders(context.Background(), t) diff --git a/fwprovider/tests/resource_download_file_test.go b/fwprovider/tests/resource_download_file_test.go index b43b9d8a..2ddf47f8 100644 --- a/fwprovider/tests/resource_download_file_test.go +++ b/fwprovider/tests/resource_download_file_test.go @@ -23,7 +23,6 @@ const ( fakeFileQCOW2 = "https://cdn.githubraw.com/rafsaf/036eece601975a3ad632a77fc2809046/raw/10500012fca9b4425b50de67a7258a12cba0c076/fake_file.qcow2" ) -//nolint:paralleltest func TestAccResourceDownloadFile(t *testing.T) { tests := []struct { name string diff --git a/fwprovider/tests/resource_linux_bridge_test.go b/fwprovider/tests/resource_linux_bridge_test.go index 6c5db932..b70d3b35 100644 --- a/fwprovider/tests/resource_linux_bridge_test.go +++ b/fwprovider/tests/resource_linux_bridge_test.go @@ -20,7 +20,6 @@ const ( accTestLinuxBridgeName = "proxmox_virtual_environment_network_linux_bridge.test" ) -//nolint:paralleltest func TestAccResourceLinuxBridge(t *testing.T) { accProviders := testAccMuxProviders(context.Background(), t) diff --git a/fwprovider/tests/resource_linux_vlan_test.go b/fwprovider/tests/resource_linux_vlan_test.go index a1583bee..3341c6ae 100644 --- a/fwprovider/tests/resource_linux_vlan_test.go +++ b/fwprovider/tests/resource_linux_vlan_test.go @@ -20,7 +20,6 @@ const ( accTestLinuxVLANName = "proxmox_virtual_environment_network_linux_vlan.test" ) -//nolint:paralleltest func TestAccResourceLinuxVLAN(t *testing.T) { accProviders := testAccMuxProviders(context.Background(), t) diff --git a/fwprovider/tests/resource_user_test.go b/fwprovider/tests/resource_user_test.go new file mode 100644 index 00000000..c538e946 --- /dev/null +++ b/fwprovider/tests/resource_user_test.go @@ -0,0 +1,76 @@ +/* + * 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 tests + +import ( + "context" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccResourceUser(t *testing.T) { + tests := []struct { + name string + steps []resource.TestStep + }{ + {"create and update user", []resource.TestStep{{ + Config: ` + resource "proxmox_virtual_environment_user" "user1" { + comment = "Managed by Terraform" + email = "user1@pve" + enabled = true + expiration_date = "2034-01-01T22:00:00Z" + first_name = "First" + last_name = "Last" + //password = "password" + user_id = "user1@pve" + } + `, + Check: resource.ComposeTestCheckFunc( + testResourceAttributes("proxmox_virtual_environment_user.user1", map[string]string{ + "comment": "Managed by Terraform", + "email": "user1@pve", + "enabled": "true", + "expiration_date": "2034-01-01T22:00:00Z", + "first_name": "First", + "last_name": "Last", + "user_id": "user1@pve", + }), + ), + }, { + Config: ` + resource "proxmox_virtual_environment_user" "user1" { + enabled = false + expiration_date = "2035-01-01T22:00:00Z" + user_id = "user1@pve" + first_name = "First One" + } + `, + Check: resource.ComposeTestCheckFunc( + testResourceAttributes("proxmox_virtual_environment_user.user1", map[string]string{ + "enabled": "false", + "expiration_date": "2035-01-01T22:00:00Z", + "first_name": "First One", + "user_id": "user1@pve", + }), + ), + }}}, + } + + accProviders := testAccMuxProviders(context.Background(), t) + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: accProviders, + Steps: tt.steps, + }) + }) + } +} diff --git a/fwprovider/tests/resource_vm_test.go b/fwprovider/tests/resource_vm_test.go index f9f8ef0f..caf7c68a 100644 --- a/fwprovider/tests/resource_vm_test.go +++ b/fwprovider/tests/resource_vm_test.go @@ -77,7 +77,6 @@ func TestAccResourceVM(t *testing.T) { } } -//nolint:paralleltest func TestAccResourceVMNetwork(t *testing.T) { tests := []struct { name string diff --git a/proxmox/access/users.go b/proxmox/access/users.go index d7fed0c3..c2343fec 100644 --- a/proxmox/access/users.go +++ b/proxmox/access/users.go @@ -12,10 +12,8 @@ import ( "net/http" "net/url" "sort" - "time" "github.com/bpg/terraform-provider-proxmox/proxmox/api" - "github.com/bpg/terraform-provider-proxmox/proxmox/types" ) func (c *Client) usersPath() string { @@ -74,11 +72,6 @@ func (c *Client) GetUser(ctx context.Context, id string) (*UserGetResponseData, return nil, api.ErrNoDataObjectInResponse } - if resBody.Data.ExpirationDate != nil { - expirationDate := types.CustomTimestamp(time.Time(*resBody.Data.ExpirationDate).UTC()) - resBody.Data.ExpirationDate = &expirationDate - } - if resBody.Data.Groups != nil { sort.Strings(*resBody.Data.Groups) } @@ -104,11 +97,6 @@ func (c *Client) ListUsers(ctx context.Context) ([]*UserListResponseData, error) }) for i := range resBody.Data { - if resBody.Data[i].ExpirationDate != nil { - expirationDate := types.CustomTimestamp(time.Time(*resBody.Data[i].ExpirationDate).UTC()) - resBody.Data[i].ExpirationDate = &expirationDate - } - if resBody.Data[i].Groups != nil { sort.Strings(*resBody.Data[i].Groups) } diff --git a/proxmox/access/users_types.go b/proxmox/access/users_types.go index a62b2efc..10a5f6a3 100644 --- a/proxmox/access/users_types.go +++ b/proxmox/access/users_types.go @@ -18,16 +18,16 @@ type UserChangePasswordRequestBody struct { // UserCreateRequestBody contains the data for a user create request. type UserCreateRequestBody struct { - Comment *string `json:"comment,omitempty" url:"comment,omitempty"` - Email *string `json:"email,omitempty" url:"email,omitempty"` - Enabled *types.CustomBool `json:"enable,omitempty" url:"enable,omitempty,int"` - ExpirationDate *types.CustomTimestamp `json:"expire,omitempty" url:"expire,omitempty,unix"` - FirstName *string `json:"firstname,omitempty" url:"firstname,omitempty"` - Groups []string `json:"groups,omitempty" url:"groups,omitempty,comma"` - ID string `json:"userid" url:"userid"` - Keys *string `json:"keys,omitempty" url:"keys,omitempty"` - LastName *string `json:"lastname,omitempty" url:"lastname,omitempty"` - Password string `json:"password" url:"password,omitempty"` + Comment *string `json:"comment,omitempty" url:"comment,omitempty"` + Email *string `json:"email,omitempty" url:"email,omitempty"` + Enabled *types.CustomBool `json:"enable,omitempty" url:"enable,omitempty,int"` + ExpirationDate *int64 `json:"expire,omitempty" url:"expire,omitempty"` + FirstName *string `json:"firstname,omitempty" url:"firstname,omitempty"` + Groups []string `json:"groups,omitempty" url:"groups,omitempty,comma"` + ID string `json:"userid" url:"userid"` + Keys *string `json:"keys,omitempty" url:"keys,omitempty"` + LastName *string `json:"lastname,omitempty" url:"lastname,omitempty"` + Password string `json:"password" url:"password,omitempty"` } // UserGetResponseBody contains the body from a user get response. @@ -37,14 +37,14 @@ type UserGetResponseBody struct { // UserGetResponseData contains the data from an user get response. type UserGetResponseData struct { - Comment *string `json:"comment,omitempty"` - Email *string `json:"email,omitempty"` - Enabled *types.CustomBool `json:"enable,omitempty"` - ExpirationDate *types.CustomTimestamp `json:"expire,omitempty"` - FirstName *string `json:"firstname,omitempty"` - Groups *[]string `json:"groups,omitempty"` - Keys *string `json:"keys,omitempty"` - LastName *string `json:"lastname,omitempty"` + Comment *string `json:"comment,omitempty"` + Email *string `json:"email,omitempty"` + Enabled *types.CustomBool `json:"enable,omitempty"` + ExpirationDate *int64 `json:"expire,omitempty"` + FirstName *string `json:"firstname,omitempty"` + Groups *[]string `json:"groups,omitempty"` + Keys *string `json:"keys,omitempty"` + LastName *string `json:"lastname,omitempty"` } // UserListResponseBody contains the body from a user list response. @@ -54,26 +54,26 @@ type UserListResponseBody struct { // UserListResponseData contains the data from an user list response. type UserListResponseData struct { - Comment *string `json:"comment,omitempty"` - Email *string `json:"email,omitempty"` - Enabled *types.CustomBool `json:"enable,omitempty"` - ExpirationDate *types.CustomTimestamp `json:"expire,omitempty"` - FirstName *string `json:"firstname,omitempty"` - Groups *[]string `json:"groups,omitempty"` - ID string `json:"userid"` - Keys *string `json:"keys,omitempty"` - LastName *string `json:"lastname,omitempty"` + Comment *string `json:"comment,omitempty"` + Email *string `json:"email,omitempty"` + Enabled *types.CustomBool `json:"enable,omitempty"` + ExpirationDate *int64 `json:"expire,omitempty"` + FirstName *string `json:"firstname,omitempty"` + Groups *[]string `json:"groups,omitempty"` + ID string `json:"userid"` + Keys *string `json:"keys,omitempty"` + LastName *string `json:"lastname,omitempty"` } // UserUpdateRequestBody contains the data for an user update request. type UserUpdateRequestBody struct { - Append *types.CustomBool `json:"append,omitempty" url:"append,omitempty"` - Comment *string `json:"comment,omitempty" url:"comment,omitempty"` - Email *string `json:"email,omitempty" url:"email,omitempty"` - Enabled *types.CustomBool `json:"enable,omitempty" url:"enable,omitempty,int"` - ExpirationDate *types.CustomTimestamp `json:"expire,omitempty" url:"expire,omitempty,unix"` - FirstName *string `json:"firstname,omitempty" url:"firstname,omitempty"` - Groups []string `json:"groups,omitempty" url:"groups,omitempty,comma"` - Keys *string `json:"keys,omitempty" url:"keys,omitempty"` - LastName *string `json:"lastname,omitempty" url:"lastname,omitempty"` + Append *types.CustomBool `json:"append,omitempty" url:"append,omitempty"` + Comment *string `json:"comment,omitempty" url:"comment,omitempty"` + Email *string `json:"email,omitempty" url:"email,omitempty"` + Enabled *types.CustomBool `json:"enable,omitempty" url:"enable,omitempty,int"` + ExpirationDate *int64 `json:"expire,omitempty" url:"expire,omitempty,int"` + FirstName *string `json:"firstname,omitempty" url:"firstname,omitempty"` + Groups []string `json:"groups,omitempty" url:"groups,omitempty,comma"` + Keys *string `json:"keys,omitempty" url:"keys,omitempty"` + LastName *string `json:"lastname,omitempty" url:"lastname,omitempty"` } diff --git a/proxmoxtf/datasource/user.go b/proxmoxtf/datasource/user.go index 08c5bf38..f3be9028 100644 --- a/proxmoxtf/datasource/user.go +++ b/proxmoxtf/datasource/user.go @@ -178,7 +178,7 @@ func userRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.D diags = append(diags, diag.FromErr(err)...) if v.ExpirationDate != nil { - t := time.Time(*v.ExpirationDate) + t := time.Unix(*v.ExpirationDate, 0) if t.Unix() > 0 { err = d.Set( mkDataSourceVirtualEnvironmentUserExpirationDate, diff --git a/proxmoxtf/datasource/users.go b/proxmoxtf/datasource/users.go index 4f799fd8..3e901191 100644 --- a/proxmoxtf/datasource/users.go +++ b/proxmoxtf/datasource/users.go @@ -138,7 +138,7 @@ func usersRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag. } if v.ExpirationDate != nil { - t := time.Time(*v.ExpirationDate) + t := time.Unix(*v.ExpirationDate, 0) if t.Unix() > 0 { expirationDates[i] = t.UTC().Format(time.RFC3339) diff --git a/proxmoxtf/resource/user.go b/proxmoxtf/resource/user.go index b972334c..c3863876 100644 --- a/proxmoxtf/resource/user.go +++ b/proxmoxtf/resource/user.go @@ -132,6 +132,7 @@ func User() *schema.Resource { Type: schema.TypeString, Description: "The user's password", Optional: true, + Sensitive: true, }, mkResourceVirtualEnvironmentUserUserID: { Type: schema.TypeString, @@ -168,7 +169,7 @@ func userCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag return diag.FromErr(err) } - expirationDateCustom := types.CustomTimestamp(expirationDate) + expirationDateCustom := expirationDate.Unix() firstName := d.Get(mkResourceVirtualEnvironmentUserFirstName).(string) groups := d.Get(mkResourceVirtualEnvironmentUserGroups).(*schema.Set).List() groupsCustom := make([]string, len(groups)) @@ -303,7 +304,7 @@ func userRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.D if user.ExpirationDate != nil { err = d.Set( mkResourceVirtualEnvironmentUserExpirationDate, - time.Time(*user.ExpirationDate).Format(time.RFC3339), + time.Unix(*user.ExpirationDate, 0).UTC().Format(time.RFC3339), ) } else { err = d.Set(mkResourceVirtualEnvironmentUserExpirationDate, time.Unix(0, 0).UTC().Format(time.RFC3339)) @@ -363,7 +364,7 @@ func userUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag return diag.FromErr(err) } - expirationDateCustom := types.CustomTimestamp(expirationDate) + expirationDateCustom := expirationDate.Unix() firstName := d.Get(mkResourceVirtualEnvironmentUserFirstName).(string) groups := d.Get(mkResourceVirtualEnvironmentUserGroups).(*schema.Set).List() groupsCustom := make([]string, len(groups))