You don’t pass your variables to the script, so the script cannot interpolate $1, $2 and $3. Either you pass the variables to the script in their correct position or you can use your environment variables in the script.
Environment variables are environment variables and treated as such. And if they should be used, maybe uppercase would be the better choice.
But no matter if upper or lowercase the $1 is a positional parameter meaning first parameter sent to the script. How should Packer know that db_user should be the first in line?
You script is wrong, too. You should pass you commands to the mysql client.
mysql -u root <<< 'CREATE...'
mysql -u root <<< 'UPDATE...'
Or using a heredoc
mysql -u root <<<EOF
CREATE...
UPDATE...
EOF
If command not found is your problem, maybe the mysql binary isn’t installed at all, or - due to your wrong script syntax - Packer wants to execute CREATE on the shell, not the mysql client.
The script is not wrong outside of Packer, which is the reason for this post. It looks like I need to manually add the end of line (EOF) in Packer as you have done above to resolve the problem. I will try that.
As for the environment variables, I do not actually want to use those as that is a security problem, but many posts are telling people to do that and indicating that structure creates positional parameters, which apparently does not. Will be adding this to my security class.
I was trying to make the code functional, not adhere to coding standards.