diff --git a/tool/tsh/common/tsh.go b/tool/tsh/common/tsh.go index 2ad2cbdf390b1..c2ec3ed83e165 100644 --- a/tool/tsh/common/tsh.go +++ b/tool/tsh/common/tsh.go @@ -3862,8 +3862,15 @@ func getAutoResourceRequest(ctx context.Context, tc *client.TeleportClient, requ req.SetDryRun(true) req.SetRequestReason("Dry run, this request will not be created. If you see this, there is a bug.") if err := tc.WithRootClusterClient(ctx, func(clt authclient.ClientI) error { - req, err = clt.CreateAccessRequestV2(ctx, req) - return trace.Wrap(err) + dryRunReq, err := clt.CreateAccessRequestV2(ctx, req) + if err != nil { + return trace.Wrap(err) + } + // Copying the computed roles here is not strictly necessary but avoids requiring + // the server to recompute the roles when the real request is created, which can be + // an expensive operation. + req.SetRoles(dryRunReq.GetRoles()) + return nil }); err != nil { return nil, trace.Wrap(err) }