-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cb356c3
Showing
6 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# terraform-roulette | ||
|
||
Terraform if it was inspired by roulette. | ||
|
||
50% chance of your `plan` or `apply` being an auto approved apply (great job!), 25% chance of your stack being destroyed. | ||
|
||
Should only be used for Friday deploys. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package cli | ||
|
||
import ( | ||
"os" | ||
"terraform-roulette/roulette" | ||
) | ||
|
||
func RunCli() { | ||
command := os.Args[1] | ||
args := os.Args[2:] | ||
|
||
roulette.Play(command, args) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module terraform-roulette | ||
|
||
go 1.22.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package main | ||
|
||
import ( | ||
"terraform-roulette/cli" | ||
) | ||
|
||
func main() { | ||
cli.RunCli() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package roulette | ||
|
||
import ( | ||
"math/rand" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
var options = map[string]int{ | ||
"destroy": 25, | ||
"apply --auto-approve": 50, | ||
} | ||
|
||
func assertTerraformCommand(command string) { | ||
cmd := exec.Command("terraform", command, "--help") | ||
cmd.Stderr = os.Stderr | ||
|
||
err := cmd.Run() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func execTerraform(commands []string, args []string) { | ||
cmdArgs := append(commands, args...) | ||
cmd := exec.Command("terraform", cmdArgs...) | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
cmd.Stdin = os.Stdin | ||
|
||
err := cmd.Run() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func spinTheWheel(commands []string) []string { | ||
for option, weight := range options { | ||
if rand.Intn(100) < weight { | ||
commands = strings.Split(option, " ") | ||
break | ||
} | ||
} | ||
|
||
return commands | ||
} | ||
|
||
func Play(command string, args []string) { | ||
assertTerraformCommand(command) | ||
|
||
commands := strings.Split(command, " ") | ||
|
||
if !strings.HasPrefix(command, "apply") { | ||
execTerraform(commands, args) | ||
os.Exit(0) | ||
} | ||
|
||
commands = spinTheWheel(commands) | ||
|
||
execTerraform(commands, args) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"version": 4, | ||
"terraform_version": "1.6.6", | ||
"serial": 1, | ||
"lineage": "8350fc6f-2ab4-d272-2831-303c17f399ee", | ||
"outputs": {}, | ||
"resources": [], | ||
"check_results": null | ||
} |