Skip to content

Commit

Permalink
chore: update readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
leg100 committed Apr 29, 2024
1 parent faf691a commit 49a71ed
Show file tree
Hide file tree
Showing 18 changed files with 154 additions and 18 deletions.
45 changes: 27 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ A TUI application for terraform power users.
* Perform tasks in parallel (plan, apply, init, etc)
* Manage state resources
* Task queueing
* Supports tofu as well as terraform
* Supports workspaces
* Backend agnostic

Expand Down Expand Up @@ -64,14 +65,10 @@ Or download and unzip a [GitHub release](https://github.com/leg100/pug/releases)

## Getting started

Pug requires `terraform` to be installed on your system (or `tofu` via `--program=tofu`).
Pug requires `terraform` to be installed on your system.

The first time you run `pug`, it'll recursively search sub-directories in the current working directory for terraform root modules.

For each module it finds, it'll attempt to run `terraform workspace list`, to search for workspaces belonging to the module.

For each workspace it finds, it'll attempt to run `terraform show -json`, to retrieve the workspace's state.

To get started with some pre-existing root modules, clone this repo, change into the `./demos/getting_started` directory, and start pug:

```bash
Expand All @@ -83,35 +80,35 @@ pug

At startup, pug lists your root modules:

![list root modules](./demos/getting_started/modules.gif)

Initialize module `modules/a` by pressing `i`:
![list root modules](./demos/getting_started/modules.png)

![init](./demos/getting_started/init.gif)
Initialize module `modules/a` by pressing `i`. That takes you to the task view, which includes the output from `terraform init`:

That takes you to the task view, which includes the output from `terraform init`.
![init](./demos/getting_started/init.png)

Press `m` to show the corresponding module page for the task:

![module](./demos/getting_started/module.gif)
![module](./demos/getting_started/module.png)

You'll be presented with multiple tabs. To cycle through tabs press the `tab` key.

On the `workspaces` tab, press `p` to create a plan:
On the `workspaces` tab, press `p` to create a plan. That takes you to the `plan` tab in the run view, showing the output from `terraform plan`:

![plan](./demos/getting_started/plan.gif)
![plan](./demos/getting_started/plan.png)

That takes you to the `plan` tab in the run view, showing the output from `terraform plan`. A run is composed of a plan, and optionally an apply. Once the plan has complete, press `a` to apply the plan:
A run is composed of a plan, and optionally an apply. Once the plan has completed, press `a` to apply:

![apply](./demos/getting_started/apply.gif)
![confirm](./demos/getting_started/confirm.png)

That takes you to the `apply` tab on the run view, showing the output from `terraform apply`.
You're presented with a prompt to confirm whether you want to proceed with an apply. Press `y` to confirm. That takes you to the `apply` tab on the run view, showing the output from `terraform apply`:

![apply](./demos/getting_started/apply.png)

Note that pug automatically pulls state after a workspace is loaded for the first time, and after an apply completes.

To see the state resources for the workspace, press `w` and cycle through the tabs to the `resources` tab.
To see the state resources for the workspace, press `w` and cycle through the tabs to the `resources` tab:

![resources](./demos/getting_started/resources.gif)
![resources](./demos/getting_started/resources.png)

This is the end of the getting started walkthrough.

Expand Down Expand Up @@ -164,3 +161,15 @@ A task starts in the `pending` state. It enters the `queued` state only if it is
An exception to this rule are tasks which are classified as *immediate*. Immediate tasks enter the running state regardless of available capacity. At time of writing only the `terraform workspace select` task is classified as such.

A task can further be classed as *exclusive*. These tasks are globally mutually exclusive and cannot run concurrently. The only task classified as such is the `init` task, and only when you have enabled the [provider plugin cache](https://developer.hashicorp.com/terraform/cli/config/config-file#provider-plugin-cache) (the plugin cache does not permit concurrent writes).

## Automatic tasks

Pug automatically creates particular tasks.

For each module it finds, it'll create a task that invokes `terraform workspace list`, to search for workspaces belonging to the module. Any workspaces it finds are loaded into pug.

For each workspace it finds, it'll create a task that invokes `terraform show -json`, to retrieve the workspace's state.

## Tofu support

To use tofu instead of terraform, set `--program=tofu`.
Binary file added demos/getting_started/apply.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions demos/getting_started/configs/a/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions demos/getting_started/configs/a/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
terraform {
backend "local" {}
}

resource "random_pet" "pet" {
count = 10

keepers = {
now = timestamp()
}
}

output "pets" {
value = random_pet.pet[*].id
}
10 changes: 10 additions & 0 deletions demos/getting_started/configs/b/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions demos/getting_started/configs/b/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
terraform {
backend "local" {}
}

resource "random_pet" "pet" {
count = 10

keepers = {
now = timestamp()
}
}

output "pets" {
value = random_pet.pet[*].id
}
10 changes: 10 additions & 0 deletions demos/getting_started/configs/c/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions demos/getting_started/configs/c/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
terraform {
backend "local" {}
}

resource "random_pet" "pet" {
count = 10

keepers = {
now = timestamp()
}
}

output "pets" {
value = random_pet.pet[*].id
}
Binary file added demos/getting_started/confirm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demos/getting_started/getting_started.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions demos/getting_started/getting_started.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Output demos/getting_started/getting_started.gif

Set Shell "bash"
Set FontSize 14
Set Width 1200
Set Height 800
Set Framerate 24
Set Padding 5

Hide
Type "demos/getting_started/reset.sh" Enter
Type `TF_CLI_CONFIG_FILE=$PWD/mirror/mirror.tfrc go run main.go -w demos/getting_started/configs` Enter
Sleep 1s
Show

# list of modules
Screenshot demos/getting_started/modules.png
# sleep a bit because otherwise vhs seems to take a screenshot of the init in
# the next step....
Sleep 0.5s

# init module a
Type "i" Sleep 0.5s
Screenshot demos/getting_started/init.png

# go to module a's page
Type "m" Sleep 0.5s
Screenshot demos/getting_started/module.png

# create a plan
Type "p" Sleep 0.5s
Screenshot demos/getting_started/plan.png

# apply plan
Type "a" Sleep 0.5s
Screenshot demos/getting_started/confirm.png

Type "y" Sleep 0.5s
Screenshot demos/getting_started/apply.png

# wait for apply to finish and state to be reloaded
Sleep 3s

# go to workspace page and cycle through tabs to the resources tab
Type "w" Sleep 0.5s Tab Tab
Screenshot demos/getting_started/resources.png
Binary file added demos/getting_started/init.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demos/getting_started/module.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demos/getting_started/modules.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demos/getting_started/plan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions demos/getting_started/reset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

find ./demos/getting_started -name .terraform -exec rm -rf {} \; > /dev/null 2>&1 || true
find ./demos/getting_started -name terraform.tfstate* -exec rm -rf {} \; > /dev/null 2>&1 || true
find ./demos/getting_started -name .pug -exec rm -rf {} \; > /dev/null 2>&1 || true
Binary file added demos/getting_started/resources.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions demos/modules/modules.tape
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Hide
Type "demos/modules/reset.sh" Enter
Type `TF_CLI_CONFIG_FILE=$PWD/mirror/mirror.tfrc go run main.go -w demos/modules/configs` Enter
Sleep 1s
Screenshot demos/modules/modules_listing.png
Show

Sleep 1s
Expand Down

0 comments on commit 49a71ed

Please sign in to comment.