-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stacks: run #3762
Merged
Merged
Stacks: run #3762
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
7c1fbdf
Add run cli command
denis256 ac6e359
Merge remote-tracking branch 'origin/main' into tg-798-stack-run-cli
denis256 9eb1223
added functions to validate terragrunt stack directory
denis256 703bf7d
stack run execution
denis256 edd8edd
Merge remote-tracking branch 'origin/main' into tg-798-stack-run-cli
denis256 5462d37
add generate execution
denis256 3edf387
stacks run test
denis256 50e9b8f
Merge remote-tracking branch 'origin/main' into tg-798-stack-run-cli
denis256 5883097
stcks tests
denis256 65a0d94
Improve basic test to generate local files
denis256 2132674
terraform source update
denis256 8160340
updated text file generation
denis256 6eade55
collection of text files
denis256 7beb65d
stack inputs
denis256 481f8eb
Add basic apply test
denis256 ecf2e4a
Add stack destroy flag
denis256 3aee53e
Add integration test for destroy and plan
denis256 c4e8375
Add helper marker
denis256 5f7329e
Lint fixes
denis256 0b96550
name update
denis256 5acca4a
Merge remote-tracking branch 'origin/main' into tg-798-stack-run-cli
denis256 ba6314d
description update
denis256 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -9,6 +9,8 @@ import ( | |
"path/filepath" | ||
"strings" | ||
|
||
runall "github.com/gruntwork-io/terragrunt/cli/commands/run-all" | ||
|
||
"github.com/gruntwork-io/terragrunt/internal/experiment" | ||
|
||
"github.com/gruntwork-io/terragrunt/config" | ||
|
@@ -19,7 +21,7 @@ import ( | |
) | ||
|
||
const ( | ||
stackCacheDir = ".terragrunt-stack" | ||
stackDir = ".terragrunt-stack" | ||
defaultStackFile = "terragrunt.stack.hcl" | ||
dirPerm = 0755 | ||
) | ||
|
@@ -34,8 +36,31 @@ func RunGenerate(ctx context.Context, opts *options.TerragruntOptions) error { | |
return generateStack(ctx, opts) | ||
} | ||
|
||
// Run execute stack command. | ||
func Run(ctx context.Context, opts *options.TerragruntOptions) error { | ||
stacksEnabled := opts.Experiments[experiment.Stacks] | ||
if !stacksEnabled.Enabled { | ||
return errors.New("stacks experiment is not enabled use --experiment stacks to enable it") | ||
} | ||
|
||
if err := RunGenerate(ctx, opts); err != nil { | ||
return err | ||
} | ||
|
||
// prepare options for execution | ||
// navigate to stack directory | ||
opts.WorkingDir = filepath.Join(opts.WorkingDir, stackDir) | ||
// remove 0 element from args | ||
opts.TerraformCliArgs = opts.TerraformCliArgs[1:] | ||
opts.TerraformCommand = opts.TerraformCliArgs[0] | ||
opts.OriginalTerraformCommand = strings.Join(opts.TerraformCliArgs, " ") | ||
|
||
return runall.Run(ctx, opts) | ||
} | ||
|
||
func generateStack(ctx context.Context, opts *options.TerragruntOptions) error { | ||
opts.TerragruntStackConfigPath = filepath.Join(opts.WorkingDir, defaultStackFile) | ||
opts.Logger.Infof("Generating stack from %s", opts.TerragruntStackConfigPath) | ||
stackFile, err := config.ReadStackConfigFile(ctx, opts) | ||
|
||
if err != nil { | ||
|
@@ -48,13 +73,16 @@ func generateStack(ctx context.Context, opts *options.TerragruntOptions) error { | |
|
||
return nil | ||
} | ||
|
||
func processStackFile(ctx context.Context, opts *options.TerragruntOptions, stackFile *config.StackConfigFile) error { | ||
baseDir := filepath.Join(opts.WorkingDir, stackCacheDir) | ||
baseDir := filepath.Join(opts.WorkingDir, stackDir) | ||
if err := os.MkdirAll(baseDir, dirPerm); err != nil { | ||
return errors.New(fmt.Errorf("failed to create base directory: %w", err)) | ||
} | ||
|
||
for _, unit := range stackFile.Units { | ||
opts.Logger.Infof("Processing unit %s", unit.Name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be in info? |
||
|
||
destPath := filepath.Join(baseDir, unit.Path) | ||
dest, err := filepath.Abs(destPath) | ||
|
||
|
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,9 @@ | ||
|
||
resource "local_file" "file" { | ||
content = "chick" | ||
filename = "${path.module}/test.txt" | ||
} | ||
|
||
output "output" { | ||
value = local_file.file.filename | ||
} |
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,4 @@ | ||
|
||
terraform { | ||
source = "." | ||
} |
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 @@ | ||
|
||
resource "local_file" "file" { | ||
content = "chicken" | ||
filename = "${path.module}/test.txt" | ||
} | ||
|
||
output "output" { | ||
value = local_file.file.filename | ||
} |
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,4 @@ | ||
|
||
terraform { | ||
source = "." | ||
} |
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 @@ | ||
|
||
resource "local_file" "file" { | ||
content = "father" | ||
filename = "${path.module}/test.txt" | ||
} | ||
|
||
output "output" { | ||
value = local_file.file.filename | ||
} |
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,4 @@ | ||
|
||
terraform { | ||
source = "." | ||
} |
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 @@ | ||
|
||
resource "local_file" "file" { | ||
content = "mother" | ||
filename = "${path.module}/test.txt" | ||
} | ||
|
||
output "output" { | ||
value = local_file.file.filename | ||
} |
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,4 @@ | ||
|
||
terraform { | ||
source = "." | ||
} |
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 @@ | ||
unit "unit1" { | ||
source = "units/app" | ||
path = "unit1" | ||
} | ||
|
||
unit "unit2" { | ||
source = "units/app" | ||
path = "unit2" | ||
} |
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 @@ | ||
variable "content" { | ||
type = string | ||
} | ||
|
||
variable "filename" { | ||
type = string | ||
default = "file.txt" | ||
} | ||
|
||
resource "local_file" "file" { | ||
content = var.content | ||
filename = "${path.module}/${var.filename}" | ||
} | ||
|
||
output "output" { | ||
value = local_file.file.filename | ||
} |
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,8 @@ | ||
|
||
terraform { | ||
source = "." | ||
} | ||
|
||
inputs = { | ||
content = "content" | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be in info?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without an info message, it is not clear what is happening, the user doesn't see any message and it is not clear which units got processed