Skip to content

Commit

Permalink
Terraform 1.10 (#3605)
Browse files Browse the repository at this point in the history
* terraform 1.10 usage

* Version update

* Usage of Terraform 1.10.1

* Version update

* Updated supported versions

* Markdown updated

* fix: Bumping tested Terraform version to 1.10.2

* choco version update

* TF version update

* Readme update

* Env vars printing

* Add outputs cache cleanup

* outputs fetching fix

* simplified pinting

* Added cleaning of output cache

* test setting test values

* env vars setting

* updated tests

* Destroy test update

* Versions documentation update

* Cleanup

* Add integration test for relative path

* Simplified version check

* Add test for ephereal vars

* Strict lint updates

---------

Co-authored-by: Yousif Akbar <[email protected]>
  • Loading branch information
denis256 and yhakbar authored Mar 3, 2025
1 parent 79a24f1 commit b3d8e5e
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env: &env
GRUNTWORK_INSTALLER_VERSION: v0.0.39
MODULE_CI_VERSION: v0.57.0
OPENTOFU_VERSION: "1.9.0"
TERRAFORM_VERSION: "1.9.7"
TERRAFORM_VERSION: "1.10.5"
TFLINT_VERSION: "0.47.0"
TOFU_ENGINE_VERSION: "v0.0.11"

Expand Down
1 change: 1 addition & 0 deletions docs/_docs/04_reference/07-supported-versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The officially supported versions are:

| Terraform Version | Terragrunt Version |
|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1.10.x | >= [0.74.0](https://github.com/gruntwork-io/terragrunt/releases/tag/v0.74.0) |
| 1.9.x | >= [0.60.0](https://github.com/gruntwork-io/terragrunt/releases/tag/v0.60.0) |
| 1.8.x | >= [0.57.0](https://github.com/gruntwork-io/terragrunt/releases/tag/v0.57.0) |
| 1.7.x | >= [0.56.0](https://github.com/gruntwork-io/terragrunt/releases/tag/v0.56.0) |
Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/ephemeral-inputs/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
variable "test" {
type = string
default = "test_value"
ephemeral = true
}

output "output" {
value = ephemeralasnull(var.test)
}

resource "local_file" "file" {
content = "test"
filename = "${path.module}/test.txt"
}
4 changes: 4 additions & 0 deletions test/fixtures/ephemeral-inputs/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

inputs = {
test = "test input 46521694"
}
25 changes: 25 additions & 0 deletions test/helpers/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,10 +658,35 @@ func ExpectedWrongCommandErr(command string) error {
return run.WrongTerraformCommand(command)
}

// IsTerraform checks if the wrapped binary currently in use is the Terraform binary.
func IsTerraform() bool {
return WrappedBinary() == TerraformBinary
}

// IsTerraform110OrHigher checks if the installed Terraform binary is version 1.10.0 or higher.
func IsTerraform110OrHigher() bool {
const (
requiredMajor = 1
requiredMinor = 10
)

if !IsTerraform() {
return false
}

output, err := exec.Command(WrappedBinary(), "-version").Output()
if err != nil {
return false
}

matches := regexp.MustCompile(`Terraform v(\d+)\.(\d+)\.`).FindStringSubmatch(string(output))

major, _ := strconv.Atoi(matches[1])
minor, _ := strconv.Atoi(matches[2])

return major > requiredMajor || (major == requiredMajor && minor >= requiredMinor)
}

func FindFilesWithExtension(dir string, ext string) ([]string, error) {
var files []string

Expand Down
3 changes: 3 additions & 0 deletions test/integration_destroy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ func TestStorePlanFilesRunAllDestroy(t *testing.T) {
helpers.CleanupTerraformFolder(t, tmpEnvPath)
testPath := util.JoinPath(tmpEnvPath, testFixtureOutDir)

dependencyPath := util.JoinPath(tmpEnvPath, testFixtureOutDir, "dependency")
helpers.RunTerragrunt(t, fmt.Sprintf("terragrunt apply -auto-approve --terragrunt-non-interactive --terragrunt-log-level trace --terragrunt-working-dir %s --terragrunt-out-dir %s", dependencyPath, tmpDir))

// plan and apply
_, _, err := helpers.RunTerragruntCommandWithOutput(t, fmt.Sprintf("terragrunt run-all plan --terragrunt-non-interactive --terragrunt-log-level trace --terragrunt-working-dir %s --terragrunt-out-dir %s", testPath, tmpDir))
require.NoError(t, err)
Expand Down
38 changes: 36 additions & 2 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const (
textFixtureDisjointSymlinks = "fixtures/stack/disjoint-symlinks"
testFixtureLogStreaming = "fixtures/streaming"
testFixtureCLIFlagHints = "fixtures/cli-flag-hints"
testFixtureEphemeralInputs = "fixtures/ephemeral-inputs"

terraformFolder = ".terraform"

Expand Down Expand Up @@ -528,12 +529,12 @@ func TestLogStdoutLevel(t *testing.T) {
tmpEnvPath := helpers.CopyEnvironment(t, testFixtureLogStdoutLevel)
rootPath := util.JoinPath(tmpEnvPath, testFixtureLogStdoutLevel)

stdout, _, err := helpers.RunTerragruntCommandWithOutput(t, "terragrunt apply -auto-approve --terragrunt-log-level trace --terragrunt-non-interactive -no-color --terragrunt-no-color --terragrunt-log-format=pretty --terragrunt-working-dir "+rootPath)
stdout, _, err := helpers.RunTerragruntCommandWithOutput(t, "terragrunt apply -auto-approve --terragrunt-non-interactive -no-color --terragrunt-no-color --terragrunt-log-format=pretty --terragrunt-working-dir "+rootPath)
require.NoError(t, err)

assert.Contains(t, stdout, "STDOUT "+wrappedBinary()+": Changes to Outputs")

stdout, _, err = helpers.RunTerragruntCommandWithOutput(t, "terragrunt destroy -auto-approve --terragrunt-log-level trace --terragrunt-non-interactive -no-color --terragrunt-no-color --terragrunt-log-format=pretty --terragrunt-working-dir "+rootPath)
stdout, _, err = helpers.RunTerragruntCommandWithOutput(t, "terragrunt destroy -auto-approve --terragrunt-non-interactive -no-color --terragrunt-no-color --terragrunt-log-format=pretty --terragrunt-working-dir "+rootPath)
require.NoError(t, err)

assert.Contains(t, stdout, "STDOUT "+wrappedBinary()+": Changes to Outputs")
Expand Down Expand Up @@ -3763,6 +3764,9 @@ func TestStorePlanFilesRunAllPlanApply(t *testing.T) {
tmpEnvPath := helpers.CopyEnvironment(t, testFixtureOutDir)
helpers.CleanupTerraformFolder(t, tmpEnvPath)
testPath := util.JoinPath(tmpEnvPath, testFixtureOutDir)
dependencyPath := util.JoinPath(tmpEnvPath, testFixtureOutDir, "dependency")

helpers.RunTerragrunt(t, fmt.Sprintf("terragrunt apply -auto-approve --terragrunt-non-interactive --terragrunt-log-level trace --terragrunt-working-dir %s --terragrunt-out-dir %s", dependencyPath, tmpDir))

// run plan with output directory
_, output, err := helpers.RunTerragruntCommandWithOutput(t, fmt.Sprintf("terragrunt run-all plan --terragrunt-non-interactive --terragrunt-log-level trace --terragrunt-working-dir %s --terragrunt-out-dir %s", testPath, tmpDir))
Expand All @@ -3789,6 +3793,9 @@ func TestStorePlanFilesRunAllPlanApplyRelativePath(t *testing.T) {
helpers.CleanupTerraformFolder(t, tmpEnvPath)
testPath := util.JoinPath(tmpEnvPath, testFixtureOutDir)

dependencyPath := util.JoinPath(tmpEnvPath, testFixtureOutDir, "dependency")
helpers.RunTerragrunt(t, fmt.Sprintf("terragrunt apply -auto-approve --terragrunt-non-interactive --terragrunt-log-level trace --terragrunt-working-dir %s --terragrunt-out-dir %s", dependencyPath, testPath))

// run plan with output directory
_, _, err := helpers.RunTerragruntCommandWithOutput(t, fmt.Sprintf("terragrunt run-all plan --terragrunt-non-interactive --terragrunt-log-level trace --terragrunt-working-dir %s --terragrunt-out-dir %s", testPath, "test"))
require.NoError(t, err)
Expand Down Expand Up @@ -3892,6 +3899,9 @@ func TestPlanJsonPlanBinaryRunAll(t *testing.T) {
helpers.CleanupTerraformFolder(t, tmpEnvPath)
testPath := util.JoinPath(tmpEnvPath, testFixtureOutDir)

dependencyPath := util.JoinPath(tmpEnvPath, testFixtureOutDir, "dependency")
helpers.RunTerragrunt(t, fmt.Sprintf("terragrunt apply -auto-approve --terragrunt-non-interactive --terragrunt-log-level trace --terragrunt-working-dir %s --terragrunt-out-dir %s", dependencyPath, tmpDir))

// run plan with output directory
_, _, err := helpers.RunTerragruntCommandWithOutput(t, fmt.Sprintf("terragrunt run-all plan --terragrunt-non-interactive --terragrunt-log-level trace --terragrunt-working-dir %s --terragrunt-json-out-dir %s --terragrunt-out-dir %s", testPath, tmpDir, tmpDir))
require.NoError(t, err)
Expand Down Expand Up @@ -3927,6 +3937,9 @@ func TestTerragruntRunAllPlanAndShow(t *testing.T) {
helpers.CleanupTerraformFolder(t, tmpEnvPath)
testPath := util.JoinPath(tmpEnvPath, testFixtureOutDir)

dependencyPath := util.JoinPath(tmpEnvPath, testFixtureOutDir, "dependency")
helpers.RunTerragrunt(t, fmt.Sprintf("terragrunt apply -auto-approve --terragrunt-non-interactive --terragrunt-log-level trace --terragrunt-working-dir %s --terragrunt-out-dir %s", dependencyPath, tmpDir))

// run plan and apply
_, _, err := helpers.RunTerragruntCommandWithOutput(t, fmt.Sprintf("terragrunt run-all plan --terragrunt-non-interactive --terragrunt-log-level trace --terragrunt-working-dir %s --terragrunt-out-dir %s", testPath, tmpDir))
require.NoError(t, err)
Expand Down Expand Up @@ -4152,3 +4165,24 @@ func TestLogFormatBare(t *testing.T) {
assert.Contains(t, stdout, "Initializing the backend...")
assert.NotContains(t, stdout, "STDO[0000] Initializing the backend...")
}

func TestTF110EphemeralVars(t *testing.T) {
t.Parallel()
if !helpers.IsTerraform110OrHigher() {
t.Skip("This test requires Terraform 1.10 or higher")

return
}

tmpEnvPath := helpers.CopyEnvironment(t, testFixtureEphemeralInputs)
helpers.CleanupTerraformFolder(t, tmpEnvPath)
testPath := util.JoinPath(tmpEnvPath, testFixtureEphemeralInputs)

stdout, _, err := helpers.RunTerragruntCommandWithOutput(t, "terragrunt plan --terragrunt-non-interactive --terragrunt-working-dir "+testPath)
require.NoError(t, err)
assert.Contains(t, stdout, "Plan: 1 to add, 0 to change, 0 to destroy")

stdout, _, err = helpers.RunTerragruntCommandWithOutput(t, "terragrunt apply --auto-approve --terragrunt-non-interactive --terragrunt-working-dir "+testPath)
require.NoError(t, err)
assert.Contains(t, stdout, "Apply complete! Resources: 1 added, 0 changed, 0 destroyed")
}

0 comments on commit b3d8e5e

Please sign in to comment.