Is it possible to generate /etc/shadow hashed password?

Hi, I’d like to generate a hash of a password to put in /etc/shadow. The raw text password already exists as a variable, I just want to convert it into a string compatible with useradd -p or similar.

Here’s what I tried that didn’t work, just to show you what I’m trying to do.

locals {
  crypted_password = format("$6$%s$%s", substr(replace(uuidv4(), "-", ""), 0, 16), sha512(var.ssh_connection_password))
}

I think the problem is, I’d need to do 5000 rounds of sha512.
Thanks!