Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
leg100 committed Sep 14, 2024
1 parent d72ba7c commit a1ea4ee
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 1 deletion.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,19 @@ When `terragrunt` is specified as the program executable, Pug enables "terragrun
* Modules are detected via the presence of a `terragrunt.hcl` file. (You may want to rename the top-level `terragrunt.hcl` file to something else otherwise it is mis-detected as a module).
* Module dependencies are supported. After modules are loaded, a task invokes `terragrunt graph-dependencies`, from which dependencies are parsed and configured in Pug. If you apply multiple modules Pug ensures their dependencies are respected, applying modules in topological order. If you apply a *destroy* plan for multiple modules, modules are applied in reverse topological order.
* The flag `--terragrunt-non-interactive` is added to commands.

## Multiple terraform versions

You may want to use a specific version of terraform for each module. To do so, it's recommended to use either [asdf](https://asdf-vm.com/) or [mise](https://mise.jdx.dev/), specifying the terraform version in a `.tool-versions` file in each module. Whenever you run `terraform`, directly or via Pug, the specific version for that module is used.

However, you first need to instruct `asdf` or `mise` to install specific versions of terraform. Pug's arbitrary execution feature can be used to perform this task for multiple modules.

For example, select modules and press `x`, and when prompted type `asdf install terraform`:

![Execute asdf install terraform in each module](./demo/execute_asdf_install_terraform.png)

Press enter to run that command in each module's directory:

![Executing asdf install terraform in each module](./demo/asdf_install_terraform_task_group.png)

You've now installed a version of terraform for each version specified in `.tool-versions` files.
Binary file added demo/asdf_install_terraform_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/demo.gif
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/execute_asdf_install_terraform.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/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.
28 changes: 28 additions & 0 deletions demo/multiple_versions/modules/a/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
terraform {
backend "local" {}
required_providers {
random = {
version = "= 3.6.0"
}
}
}

resource "time_sleep" "wait_three_seconds" {
create_duration = "3s"
}

resource "random_pet" "pet" {
count = 10

keepers = {
now = timestamp()
}
}

output "waited" {
value = time_sleep.wait_three_seconds.create_duration
}

output "pets" {
value = random_pet.pet[*].id
}
28 changes: 28 additions & 0 deletions demo/multiple_versions/modules/b/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
terraform {
backend "local" {}
required_providers {
random = {
version = "= 3.6.0"
}
}
}

resource "time_sleep" "wait_three_seconds" {
create_duration = "3s"
}

resource "random_pet" "pet" {
count = 10

keepers = {
now = timestamp()
}
}

output "waited" {
value = time_sleep.wait_three_seconds.create_duration
}

output "pets" {
value = random_pet.pet[*].id
}
28 changes: 28 additions & 0 deletions demo/multiple_versions/modules/c/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
terraform {
backend "local" {}
required_providers {
random = {
version = "= 3.6.0"
}
}
}

resource "time_sleep" "wait_three_seconds" {
create_duration = "3s"
}

resource "random_pet" "pet" {
count = 10

keepers = {
now = timestamp()
}
}

output "waited" {
value = time_sleep.wait_three_seconds.create_duration
}

output "pets" {
value = random_pet.pet[*].id
}
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/tasks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions demo/vhs.tape
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,31 @@ 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 3s

# quit app and restart, this time with modules with .tool-versions files, to demonstrate support for executing arbitrary programs, in this case, `asdf`
Hide
Ctrl+c Type "y"
Type `TF_CLI_CONFIG_FILE=$PWD/mirror/mirror.tfrc go run main.go -w demo/multiple_versions` Enter
Sleep 1s
Show

# show unintialized modules
Sleep 1s

# select all modules
Ctrl+a Sleep 0.5s
# install terraform for each module
Type "x" Sleep 1s
Type "asdf install terraform" Sleep 1s
# take screen shot (sleep to ensure page doesn't switch too soon)
Screenshot demo/execute_asdf_install_terraform.png Sleep 0.5s
# Execute asdf
Enter
# Show user the output of asdf downloading terraform. This takes a long time,
# so sleep a bit, then hide and wait, then show and sleep a bit more.
Sleep 2s
Hide
Sleep 8s
Show
Sleep 4s
Screenshot demo/asdf_install_terraform_task_group.png Sleep 0.5s
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.
3 changes: 3 additions & 0 deletions hacks/reset_demo.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# remove all asdf installs of terraform
asdf uninstall terraform

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
Expand Down
1 change: 0 additions & 1 deletion internal/tui/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ func (p *Prompt) View(width int) string {
// Set available width for user entered value before it horizontally
// scrolls.
p.model.Width = max(0, width-lipgloss.Width(p.model.Prompt)-paddedBorderWidth)
p.model.Placeholder = "terraform version"
// Render a prompt, surrounded by a padded red border, spanning the width of the
// terminal, accounting for width of border. Inline and MaxWidth ensures the
// prompt remains on a single line.
Expand Down

0 comments on commit a1ea4ee

Please sign in to comment.