diff --git a/internal/exec/terraform.go b/internal/exec/terraform.go index 7b3153fd4..b782d325e 100644 --- a/internal/exec/terraform.go +++ b/internal/exec/terraform.go @@ -238,6 +238,19 @@ func ExecuteTerraform(info schema.ConfigAndStacksInfo) error { } } + // Run `terraform init` before running other commands + runTerraformInit := true + if info.SubCommand == "init" || + info.SubCommand == "clean" || + (info.SubCommand == "deploy" && !cliConfig.Components.Terraform.DeployRunInit) { + runTerraformInit = false + } + + if info.SkipInit { + u.LogDebug(cliConfig, "Skipping over 'terraform init' due to '--skip-init' flag being passed") + runTerraformInit = false + } + // Set `TF_IN_AUTOMATION` ENV var to `true` to suppress verbose instructions after terraform commands // https://developer.hashicorp.com/terraform/cli/config/environment-variables#tf_in_automation info.ComponentEnvList = append(info.ComponentEnvList, "TF_IN_AUTOMATION=true") @@ -260,28 +273,11 @@ func ExecuteTerraform(info schema.ConfigAndStacksInfo) error { } } - // Run `terraform init` before running other commands - runTerraformInit := true - if info.SubCommand == "init" || - info.SubCommand == "clean" || - (info.SubCommand == "deploy" && !cliConfig.Components.Terraform.DeployRunInit) { - runTerraformInit = false - } - - if info.SkipInit { - u.LogDebug(cliConfig, "Skipping over 'terraform init' due to '--skip-init' flag being passed") - runTerraformInit = false - } - if runTerraformInit { initCommandWithArguments := []string{"init"} if info.SubCommand == "workspace" || cliConfig.Components.Terraform.InitRunReconfigure { initCommandWithArguments = []string{"init", "-reconfigure"} } - - // Before executing `terraform init`, delete the `.terraform/environment` file from the component directory - cleanTerraformWorkspace(componentPath) - err = ExecuteShellCommand( cliConfig, info.Command, @@ -363,9 +359,6 @@ func ExecuteTerraform(info schema.ConfigAndStacksInfo) error { allArgsAndFlags = append(allArgsAndFlags, []string{varFileFlag, varFile}...) } case "init": - // Before executing `terraform init`, delete the `.terraform/environment` file from the component directory - cleanTerraformWorkspace(componentPath) - if cliConfig.Components.Terraform.InitRunReconfigure { allArgsAndFlags = append(allArgsAndFlags, []string{"-reconfigure"}...) } diff --git a/internal/exec/terraform_utils.go b/internal/exec/terraform_utils.go index db92103d6..2228208d0 100644 --- a/internal/exec/terraform_utils.go +++ b/internal/exec/terraform_utils.go @@ -1,9 +1,6 @@ package exec import ( - "os" - "path" - "github.com/pkg/errors" "github.com/cloudposse/atmos/pkg/schema" @@ -17,12 +14,3 @@ func checkTerraformConfig(cliConfig schema.CliConfiguration) error { return nil } - -// cleanTerraformWorkspace deletes the `.terraform/environment` file from the component directory. -// The `.terraform/environment` file contains the name of the currently selected workspace, -// helping Terraform identify the active workspace context for managing your infrastructure. -// We delete the file to prevent the Terraform prompt asking o select the default or the -// previously used workspace. This happens when different backends are used for the same component. -func cleanTerraformWorkspace(componentPath string) { - _ = os.Remove(path.Join(componentPath, ".terraform", "environment")) -} diff --git a/pkg/utils/file_utils.go b/pkg/utils/file_utils.go index 2cdb7204f..4c0d752a1 100644 --- a/pkg/utils/file_utils.go +++ b/pkg/utils/file_utils.go @@ -197,21 +197,20 @@ func SearchConfigFile(path string) (string, bool) { // IsURL checks if a string is a URL func IsURL(s string) bool { - u, err := url.Parse(s) + url, err := url.Parse(s) if err != nil { return false } - validSchemes := []string{"http", "https"} schemeValid := false for _, scheme := range validSchemes { - if u.Scheme == scheme { + if url.Scheme == scheme { schemeValid = true break } } - return schemeValid + } // GetFileNameFromURL extracts the file name from a URL @@ -219,19 +218,16 @@ func GetFileNameFromURL(rawURL string) (string, error) { if rawURL == "" { return "", fmt.Errorf("empty URL provided") } - parsedURL, err := url.Parse(rawURL) if err != nil { return "", err } - // Extract the path from the URL urlPath := parsedURL.Path - - // Get the base name of the path fileName := path.Base(urlPath) if fileName == "/" || fileName == "." { return "", fmt.Errorf("unable to extract filename from URL: %s", rawURL) } + // Get the base name of the path return fileName, nil } diff --git a/website/package-lock.json b/website/package-lock.json index 42286b623..8ffdc2112 100644 --- a/website/package-lock.json +++ b/website/package-lock.json @@ -30,7 +30,7 @@ "marked": "^14.1.3", "node-fetch": "^3.3.2", "posthog-docusaurus": "^2.0.1", - "posthog-js": "^1.180.1", + "posthog-js": "^1.178.0", "prism-react-renderer": "^2.4.0", "raw-loader": "^4.0.2", "react": "^18.3.1", @@ -13652,9 +13652,9 @@ } }, "node_modules/posthog-js": { - "version": "1.180.1", - "resolved": "https://registry.npmjs.org/posthog-js/-/posthog-js-1.180.1.tgz", - "integrity": "sha512-LV65maVrpqkAh0wu32YvU7FpCSEjg6o+sZFYCs1+6tnEa9VvXuz8J6ReLiyRpJABI4j1qX/PB2jaVY5tDbLalQ==", + "version": "1.178.0", + "resolved": "https://registry.npmjs.org/posthog-js/-/posthog-js-1.178.0.tgz", + "integrity": "sha512-ILD4flNh72d5dycc4ZouKORlaVr+pDzl5TlZr1JgP0NBAoduHjhE7XZYwk7zdYkry7u0qAIpfv2306zJCW2vGg==", "license": "MIT", "dependencies": { "core-js": "^3.38.1", diff --git a/website/package.json b/website/package.json index 6fc1cddcd..bdec0e610 100644 --- a/website/package.json +++ b/website/package.json @@ -36,7 +36,7 @@ "marked": "^14.1.3", "node-fetch": "^3.3.2", "posthog-docusaurus": "^2.0.1", - "posthog-js": "^1.180.1", + "posthog-js": "^1.178.0", "prism-react-renderer": "^2.4.0", "raw-loader": "^4.0.2", "react": "^18.3.1",