0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-08-22 11:28:33 +00:00

fix(token): do not reset user token value in TF state during update (#1857)

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
Pavel Boldyrev 2025-03-28 14:54:45 -04:00 committed by GitHub
parent de65997de4
commit 2da4e3de1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 7 deletions

View File

@ -115,7 +115,7 @@ func TestAccResourceUserToken(t *testing.T) {
require.NoError(t, err)
t.Cleanup(func() {
err := te.AccessClient().DeleteUser(context.Background(), userID)
err = te.AccessClient().DeleteUser(context.Background(), userID)
require.NoError(t, err)
})
},
@ -148,9 +148,7 @@ func TestAccResourceUserToken(t *testing.T) {
"privileges_separation": "false",
"token_name": tokenName,
"user_id": userID,
}),
test.NoResourceAttributesSet("proxmox_virtual_environment_user_token.user_token", []string{
"value",
"value": fmt.Sprintf("%s!%s=.*", userID, tokenName),
}),
),
},
@ -167,10 +165,10 @@ func TestAccResourceUserToken(t *testing.T) {
"privileges_separation": "false",
"token_name": tokenName,
"user_id": userID,
"value": fmt.Sprintf("%s!%s=.*", userID, tokenName),
}),
test.NoResourceAttributesSet("proxmox_virtual_environment_user_token.user_token", []string{
"expiration_date",
"value",
}),
),
},
@ -178,6 +176,9 @@ func TestAccResourceUserToken(t *testing.T) {
ResourceName: "proxmox_virtual_environment_user_token.user_token",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"value",
},
},
},
},

View File

@ -108,6 +108,11 @@ func (r *userTokenResource) Schema(
"and can't be retrieved at import.",
Computed: true,
Sensitive: true,
PlanModifiers: []planmodifier.String{
// the attribute can't be retrieved after token creation, so during update we have to use value
// from state (i.e. populated at create) if available.
stringplanmodifier.UseStateForUnknown(),
},
},
},
}
@ -254,8 +259,6 @@ func (r *userTokenResource) Update(ctx context.Context, req resource.UpdateReque
return
}
plan.Value = types.StringNull()
resp.State.Set(ctx, plan)
}