I’ve needed a random ID to use as a suffix for a resource name that will not be changed on each apply.

random_id solved the problem.

Keeper value will “freeze” the random id and will force it to change only when any(?) of the keeper changed.

resource "random_id" "domain_name_suffix" {
  byte_length = 4
 
  keepers = {
    name_prefix = local.name_prefix
  }
}
 
# Create User Pool Domain to enable self-service sign-up
resource "aws_cognito_user_pool_domain" "main" {
  domain       = "${local.name_prefix}-domain-${random_id.domain_name_suffix.hex}"
  user_pool_id = aws_cognito_user_pool.main.id
}