-
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
1 parent
560dfdc
commit c44eafc
Showing
17 changed files
with
412 additions
and
172 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
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
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,24 @@ | ||
#!/usr/bin/env bash -e | ||
|
||
# This is the code structure (from a basic example) | ||
cd samples/basic | ||
tree -P backend.tf . | ||
|
||
# Each depth level has a dependency on the previous one. For example: | ||
cat dev/base/data.tf | ||
cat dev/base/vpc.tf | ||
|
||
# In this case it simulates that the VPC needs first the account where it has to be created | ||
cat base/accounts.tf | ||
|
||
# Let's run terraform init through cascade recursively | ||
go run ../.. init --cascade-recursive | ||
|
||
# Now, let's run apply | ||
go run ../.. apply --cascade-recursive --auto-approve | ||
|
||
# Let's see the created "infra" | ||
tree -a -I .terraform /tmp/cascade | ||
|
||
# And the state files | ||
tree -a /tmp/cascade/.terraform/ |
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
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,17 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/atorrescogollo/terraform-cascade/internal/orchestration" | ||
"github.com/atorrescogollo/terraform-cascade/internal/usecases" | ||
) | ||
|
||
// Orchestration | ||
var projectExecutor = orchestration.NewTerraformProjectExecutorWithOS() | ||
var projectOrderResolver = orchestration.NewProjectOrderResolver() | ||
|
||
// Use cases | ||
var runRawTerraformUseCase = usecases.NewRunRawTerraformUseCase() | ||
var runRecursiveTerraformUseCase = usecases.NewRunRecursiveTerraformUseCase( | ||
*projectExecutor, | ||
*projectOrderResolver, | ||
) |
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
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
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,26 @@ | ||
package controller | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/atorrescogollo/terraform-cascade/internal/usecases" | ||
) | ||
|
||
type CascadeController struct { | ||
RunRecursiveTerraformUseCase usecases.RunRecursiveTerraformUseCase | ||
} | ||
|
||
func NewCascadeController(runRecursiveTerraformUseCase usecases.RunRecursiveTerraformUseCase) *CascadeController { | ||
return &CascadeController{ | ||
runRecursiveTerraformUseCase, | ||
} | ||
} | ||
|
||
func (c CascadeController) HandleCascade() error { | ||
// TODO: Implement cascade logic | ||
//cwd, _ := os.Getwd() | ||
//tfargs := []string{"init"} | ||
//chdir := cwd + "/samples/basic" | ||
//return c.RunRecursiveTerraformUseCase.Execute(chdir, tfargs) | ||
return fmt.Errorf("not implemented") | ||
} |
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,45 @@ | ||
package controller | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/atorrescogollo/terraform-cascade/internal/terraform" | ||
"github.com/atorrescogollo/terraform-cascade/internal/usecases" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type TerraformController struct { | ||
RunRawTerraformUseCase usecases.RunRawTerraformUseCase | ||
RunRecursiveTerraformUseCase usecases.RunRecursiveTerraformUseCase | ||
} | ||
|
||
func NewTerraformController(runRawTerraformUseCase usecases.RunRawTerraformUseCase, runRecursiveTerraformUseCase usecases.RunRecursiveTerraformUseCase) *TerraformController { | ||
return &TerraformController{ | ||
RunRawTerraformUseCase: runRawTerraformUseCase, | ||
RunRecursiveTerraformUseCase: runRecursiveTerraformUseCase, | ||
} | ||
} | ||
|
||
func (c TerraformController) Handle(recursive bool, tfargs []string) error { | ||
cwd, _ := os.Getwd() | ||
if !recursive { | ||
/* | ||
* Simply run terraform in the current directory | ||
*/ | ||
return c.RunRawTerraformUseCase.Execute(cwd, tfargs) | ||
} | ||
return c.RunRecursiveTerraformUseCase.Execute(cwd, tfargs) | ||
} | ||
|
||
func (c TerraformController) Usage(cmd *cobra.Command) error { | ||
terraformUsage := terraform.TerraformUsage() | ||
err := cmd.UsageFunc()(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println() | ||
fmt.Println(terraformUsage) | ||
return nil | ||
} |
Oops, something went wrong.