Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: finalize readme and include script #53

Merged
merged 3 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.idea
packages/cli/lib/logs/*
packages/cli/lib/settings.txt
51 changes: 32 additions & 19 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,41 @@
## Setup

### Step 1: Installation
In order to use tfvm on windows, you must be able to run powershell scripts.
To enable powershell scripts to run on your machine, **run the following command in a powershell window**. (You do *not* need admin access to run this command)
In order to use tfvm on windows, you must be able to run Powershell scripts, even if you call tfvm from another shell.
To enable Powershell scripts to run on your machine, **run the following command in a Powershell window**
(You do *not* need admin access to run this command):
```shell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
```

Next, install tfvm. You will need to have node installed.

**TODO: add official installation instructions after publishing to npm.** (for now, `npm i -g tfvm-windows` works)
Next, install tfvm. You will need to have node (≥v14) installed.
```shell
npm i -g @byu-oit/tfvm
```

> If you frequently change versions of node and you wish to use tfvm in other node versions, you will need to re-install tfvm in this way for each version.
> If you frequently change versions of node and you wish to use tfvm in other node versions, you will need to re-install
> tfvm in this way for each version.
>
> Fortunately, any installed terraform versions and your selected terraform version will be maintained for each node version that you switch to, as they are stored on your system and not in node's files.
> Fortunately, any installed terraform versions and your selected terraform version will be maintained for each node
> version that you switch to, as they are stored on your system and not in node's files.

### Step 2: Delete existing terraform setup
tfvm will auto-create directories and a variable in your 'Path' system environment variable for terraform setup. This will conflict with anything you already have.
1. If you already have terraform set up on your computer, delete your entry for your terraform directory in your system path.
tfvm will auto-create directories and a variable in your 'Path' system environment variable for terraform setup.
This will conflict with any terraform paths you already have.
1. If you already have terraform set up on your computer, delete your entry for your terraform directory in your user path.
2. You could leave your terraform.exe file(s), but you might as well delete them. tfvm will download its own files.

### Step 3: Run tfvm for the first time
1. Open up any command line
2. Run any tfvm command. If you know what version you want to use first, you can run `tfvm install <that version>` and then `tfvm use <that version>`.
2. Run any tfvm command. If you know what version you want to use first, you can run `tfvm install <that version>`
and then `tfvm use <that version>`.
If you don't have a version in mind, you could run something like `tfvm install latest`.
> You should see some lines appear saying that tfvm has automatically added a directory pointing to its terraform installation folder to your Path. This means it is working correctly
3. Restart your terminal(s) where you want to use terraform so that your system path can be refreshed and your CLI can actually find terraform.
Any terminals (including those built into IDEs) that were open before you installed tfvm will have to be restarted to use the versions of terraform that tfvm install.
> You should see some lines appear saying that tfvm has automatically added a directory pointing to its terraform
installation folder to your Path. This means it is working correctly
3. Restart your terminal(s) where you want to use terraform so that your system path can be refreshed and your
CLI can actually find terraform.
Any terminals (including those built into IDEs) that were open before you installed tfvm will have to be restarted
to use the versions of terraform that tfvm install.
This may require you to also restart your IDE if you are using a terminal from within your IDE.
4. In your new terminal, run `terraform --version` to verify that you are using the version of terraform that you installed with tfvm.

Expand All @@ -56,26 +65,30 @@ Run `tfvm` in any command line, followed by one of these commands:
- `help`: prints usage information. Run `tfvm help <command>` to see information about the other tfvm commands.

## FAQ
**Q:** Why use this app instead of one of the other terrform version managers you can find?
**Q:** Why use this app instead of one of the other terraform version managers you can find?
<br>
**A:** It is the simplest to use for Windows and is fully cross-compatible. Most don't support windows, and those that do are unintuitive. This one is simple and works, especially for beginners to terraform.
**A:** It is the simplest to use for Windows and doesn't require administrator permissions.
Many terraform version managers don't support windows, and those that do are unintuitive.
This one is simple and works well, especially for beginners to terraform.

**Q:** I'm getting this error when running tfvm in powershell: `File C:\Program Files\nodejs\tfvm.ps1 cannot be loaded because running scripts is disabled on this system.`
**Q:** I'm getting this error when running tfvm in powershell: `File C:\Users\<username>\nodejs\tfvm.ps1 cannot be
loaded because running scripts is disabled on this system.`
<br>
**A:** Most custom CLI apps will throw this error in Powershell. Run this command to update your powershell execution policy:
**A:** Most custom CLI apps will throw this error. Run this command in Powershell to update your powershell execution policy:
```shell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
```

**Q:** What terraform versions are supported?
<br>
**A:** tfvm will install and use any major version that is available in the [Hashicorp Terraform Releases archive](https://releases.hashicorp.com/terraform/).
**A:** tfvm will install and use any major version that is available in the
[Hashicorp Terraform Releases archive](https://releases.hashicorp.com/terraform/).
At this time, tfvm will not allow you to select alpha, beta, or rc releases.

**Q:** I'm seeing weird behavior or errors. Where can I view tfvm's logs for debugging?
<br>
**A:** The logs are stored in the same directory as tfvm's other source files.
Go to your node folder (or nvm folder, if applicable) and go to 'node_modules/tfvm-windows/logs'.
Go to your node folder (or nvm folder, if applicable) and go to 'node_modules/@byu-oit/tfvm/lib/logs'.

> <sup>To generate more detailed logs, run tfvm with the `LOG_LEVEL` environment variable set to `debug` or `trace`.
Alternatively, you can also use the `--log-level <level>` or `-l <level>` argument.
Expand Down
23 changes: 23 additions & 0 deletions packages/cli/lib/scripts/addToPath.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This script attempts to add terraform to the system and local paths.
# It will not add it if it already exists.
# It will not add it to the system path if the shell it is being run from does not have admin rights

$userName = $env:UserName
$path2add = ";C:\Users\$userName\AppData\Roaming\terraform"
$userPath = [Environment]::GetEnvironmentVariable('Path', 'User');

# attempts to add to local path
If (!$userPath.contains($path2add)) {
$userPath += $path2add
$userPath = $userPath -join ';'
[Environment]::SetEnvironmentVariable('Path', $userPath, 'User');
}

# this code adds to system path, if we ever need it
#$systemPath = [Environment]::GetEnvironmentVariable('Path', 'machine');
#If (!$systemPath.contains($path2add)) {
# echo '1'
# $systemPath += $path2add
# $systemPath = $systemPath -join ';'
# [Environment]::SetEnvironmentVariable('Path', $systemPath, 'Machine');
#}