Using terraform as a non-admin user account

After I have installed Terraform and added the environment variable on a Windows computer. I have noticed that I can only use Terraform when I run an application like PowerShell or Command Prompt as an administrator. Since my day to day account is a non-admin, I was wondering if there is a way to get it working without having to run as admin all the time, without comprising the security of the device?

There shouldn’t be any reason you have to run as an administrator. Are all the permissions on the terraform binary set correctly? What error do you see if you try to run it without being administrator?

So I created a folder called tools within my C:\ drive. I then added that location to my environment path, copied the terraform.exe into the folder and I rebooted my machine.

After rebooting, I opened Powershell as my standard user account and typed terraform -help and the error message I get is:

terraform : The term ‘terraform’ is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1

  • terraform -help
  •   + CategoryInfo          : ObjectNotFound: (terraform:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
    

When I run Powershell as an admin, it works completely fine.

Hi @jbell,

Does it work if you explicitly type out c:\tools\terraform.exe? If so, that suggests that you’ve added the tools directory to the search path environment variable only for your admin user, and not for your regular user.

Note that running programs that aren’t cmdlets which have non-trivial command line argument syntax in PowerShell doesn’t work very well. I expect it’ll work okay as long as you’re only running simple command lines like terraform plan, but PowerShell tends to corrupt quoted strings sent on the command line and that often causes trouble for more complex Terraform usage under PowerShell. Windows Command Prompt is a less troublesome choice. (The search path solution should, I think, apply to both of them if I’m right about the cause of your error.)

Hi,

Within my environment variables I have it pointing to C:\Tools\ and when I run as an admin it works fine, but not as a standard user. This happens when you try it in either Command Prompt or PowerShell.

I’ve also tried updating the environment variable path to C:\Tools\Terraform.exe and after a reboot it doesn’t work at all.

Resolved the issue, my fault entirely. When you open the environmental paths as a standard user, Windows UAC prompt will ask you to enter the admin credentials. When you do that and the window appears, the top option is to add it to the admin account paths only. Instead, I should have added it to the system path instead. After that, I am able to do use Terraform as a non-admin.