Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
leg100 committed Aug 20, 2024
1 parent 8c20d67 commit b1b7fbe
Show file tree
Hide file tree
Showing 75 changed files with 172 additions and 5 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ A terminal user interface for terraform power users.
* Supports terraform, tofu and terragrunt
* Supports terragrunt dependencies
* Supports workspaces
* Calculate costs using infracost
* Automatically loads workspace variable files
* Backend agnostic (s3, cloud, etc)

Expand Down Expand Up @@ -128,6 +129,7 @@ Press `w` to go to the workspaces page.
|`a`|Run `terraform apply`|✓|
|`d`|Run `terraform apply -destroy`|✓|
|`C`|Run `terraform workspace select`|✗|
|`$`|Run `infracost breakdown`|✓|

### State

Expand Down Expand Up @@ -291,6 +293,18 @@ A task can be canceled at any stage. If it is `running` then the current terrafo

When a workspace is loaded into Pug for the first time, a task is created to invoke `terraform state pull`, which retrieves workspace's state, and then the state is loaded into Pug. The task is also triggered after any task that alters the state, such as an apply or moving a resource in the state.

## Infracost integration

NOTE: Requires `infracost` to be installed on your machine, along with configured API key.

Pug integrates with infracost to provide cost estimation. Select workspaces on the workspace page and press `$` to run calculate their costs:

![Infracost output screenshot](./demo/infracost_output.png)

Once the task has finished, the costs are visible on the workspaces page:

![Worksapces with costs screenshot](./demo/workspaces_with_cost.png)

## Tofu support

To use tofu, set `--program=tofu`. Ensure it is installed first.
Expand Down
Binary file modified demo/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions demo/do_cost_money/modules/a/.terraform.lock.hcl

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

1 change: 1 addition & 0 deletions demo/do_cost_money/modules/a/dev.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
instance_type = "m7g.2xlarge"
21 changes: 21 additions & 0 deletions demo/do_cost_money/modules/a/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
terraform {
backend "local" {}
}

# Configure the AWS Provider
provider "aws" {
region = "us-east-1"
}

resource "aws_instance" "web" {
ami = data.aws_ami.ubuntu.id
instance_type = var.instance_type

tags = {
Name = "HelloWorld"
}
}

variable "instance_type" {
default = "t3.micro"
}
9 changes: 9 additions & 0 deletions demo/do_cost_money/modules/b/.terraform.lock.hcl

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

17 changes: 17 additions & 0 deletions demo/do_cost_money/modules/b/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
terraform {
backend "local" {}
}

# Configure the AWS Provider
provider "aws" {
region = "us-east-1"
}

resource "aws_instance" "web" {
ami = data.aws_ami.ubuntu.id
instance_type = "t3.micro"

tags = {
Name = "HelloWorld"
}
}
9 changes: 9 additions & 0 deletions demo/do_cost_money/modules/c/.terraform.lock.hcl

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

17 changes: 17 additions & 0 deletions demo/do_cost_money/modules/c/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
terraform {
backend "local" {}
}

# Configure the AWS Provider
provider "aws" {
region = "us-east-1"
}

resource "aws_instance" "web" {
ami = data.aws_ami.ubuntu.id
instance_type = "t3.micro"

tags = {
Name = "HelloWorld"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file modified demo/filter.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 demo/infracost_output.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 modified demo/logs.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 modified demo/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 demo/money.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions demo/money.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Output demo/money.gif

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

Hide
Type `TF_CLI_CONFIG_FILE=$PWD/mirror/mirror.tfrc go run main.go -w demo/workspaces_that_cost_money` Enter
Sleep 1s
Show

# show unintialized modules
Sleep 1s

# init all modules
Ctrl+a Sleep 0.5s Type "i"
# we're taken to the init task group page, wait for a few seconds for tasks to finish (it takes longer because it is copying hefty aws provider about
Sleep 3s

# go to workspaces
Type "w" Sleep 2s
# select all workspaces
Ctrl+a Sleep 0.5s
# calculate cost
Type "$"
# user is taken to infracost task page, watch output for a few seconds
Sleep 5s
# take screen shot of infracost output (sleep to ensure page doesn't switch too soon)
Screenshot demo/infracost_output.png Sleep 0.5s

# go back to workspaces
Type "w" Sleep 0.5s
# take screen shot of workspaces (sleep to ensure page doesn't switch too soon)
Screenshot demo/workspaces_with_cost.png Sleep 0.5s
Sleep 2s
Binary file modified demo/state.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 modified demo/task_group.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 modified demo/task_groups.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 modified demo/tasks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 33 additions & 1 deletion demo/vhs.tape
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Set Framerate 24
Set Padding 5

Hide
Type `TF_CLI_CONFIG_FILE=$PWD/mirror/mirror.tfrc go run main.go -w demo` Enter
Type `TF_CLI_CONFIG_FILE=$PWD/mirror/mirror.tfrc go run main.go -w demo/dont_cost_money` Enter
Sleep 1s
Show

Expand Down Expand Up @@ -159,3 +159,35 @@ Type "l"
# take screenshot of logs
Screenshot demo/logs.png
Sleep 2s

# quit app and restart, this time with workspaces that cost money, to demonstrate infracost integration
Hide
Ctrl+c Type "y"
Type `TF_CLI_CONFIG_FILE=$PWD/mirror/mirror.tfrc go run main.go -w demo/do_cost_money` Enter
Sleep 1s
Show

# show unintialized modules
Sleep 1s

# init all modules
Ctrl+a Sleep 0.5s Type "i"
# we're taken to the init task group page, wait for a few seconds for tasks to finish (it takes longer because it is copying hefty aws provider about
Sleep 5s

# go to workspaces
Type "w" Sleep 2s
# select all workspaces
Ctrl+a Sleep 0.5s
# calculate cost
Type "$"
# user is taken to infracost task page, watch output for a few seconds
Sleep 5s
# take screen shot of infracost output (sleep to ensure page doesn't switch too soon)
Screenshot demo/infracost_output.png Sleep 0.5s

# go back to workspaces
Type "w" Sleep 0.5s
# take screen shot of workspaces (sleep to ensure page doesn't switch too soon)
Screenshot demo/workspaces_with_cost.png Sleep 0.5s
Sleep 2s
Binary file modified demo/workspaces.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 demo/workspaces_with_cost.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions hacks/reset_demo.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
find demo/modules -name .terraform -exec rm -rf {} \; > /dev/null 2>&1 || true
find demo/modules -name terraform.tfstate -exec rm {} \; > /dev/null 2>&1 || true
find demo/modules -name terraform.tfstate.* -exec rm {} \; > /dev/null 2>&1 || true
find demo/modules -name environment -exec rm {} \; > /dev/null 2>&1 || true
find demo/ -name .terraform -exec rm -rf {} \; > /dev/null 2>&1 || true
find demo/ -name terraform.tfstate -exec rm {} \; > /dev/null 2>&1 || true
find demo/ -name terraform.tfstate.* -exec rm {} \; > /dev/null 2>&1 || true
find demo/ -name environment -exec rm {} \; > /dev/null 2>&1 || true

0 comments on commit b1b7fbe

Please sign in to comment.