Skip to content

Commit

Permalink
Merge branch 'feature/dev-2821-atmos-terraform-help-should-also-show-…
Browse files Browse the repository at this point in the history
…terraform-help' of https://github.com/cloudposse/atmos into feature/dev-2821-atmos-terraform-help-should-also-show-terraform-help
  • Loading branch information
samtholiya committed Dec 26, 2024
2 parents 51bbb79 + 636fb16 commit 7608538
Show file tree
Hide file tree
Showing 29 changed files with 163 additions and 117 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ jobs:
- name: Acceptance tests
timeout-minutes: 10
run: |
make testacc
run: make testacc

docker:
name: "Docker Lint"
Expand Down
3 changes: 2 additions & 1 deletion cmd/cmd_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"os"
"path"
"path/filepath"
"strings"
"time"
Expand Down Expand Up @@ -404,7 +405,7 @@ func printMessageForMissingAtmosConfig(atmosConfig schema.AtmosConfiguration) {
u.PrintMessageInColor("atmos.yaml", c1)
fmt.Println(" CLI config file was not found.")
fmt.Print("\nThe default Atmos stacks directory is set to ")
u.PrintMessageInColor(filepath.Join(atmosConfig.BasePath, atmosConfig.Stacks.BasePath), c1)
u.PrintMessageInColor(path.Join(atmosConfig.BasePath, atmosConfig.Stacks.BasePath), c1)
fmt.Println(",\nbut the directory does not exist in the current path.")
} else {
// If Atmos found an `atmos.yaml` config file, but it defines invalid paths to Atmos stacks and components
Expand Down
6 changes: 3 additions & 3 deletions cmd/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"path"
"runtime"

"github.com/charmbracelet/glamour"
Expand Down Expand Up @@ -59,7 +59,7 @@ var docsCmd = &cobra.Command{
}

// Construct the full path to the Terraform component by combining the Atmos base path, Terraform base path, and component name
componentPath := filepath.Join(atmosConfig.BasePath, atmosConfig.Components.Terraform.BasePath, info.Component)
componentPath := path.Join(atmosConfig.BasePath, atmosConfig.Components.Terraform.BasePath, info.Component)
componentPathExists, err := u.IsDirectory(componentPath)
if err != nil {
u.LogErrorAndExit(schema.AtmosConfiguration{}, err)
Expand All @@ -68,7 +68,7 @@ var docsCmd = &cobra.Command{
u.LogErrorAndExit(schema.AtmosConfiguration{}, fmt.Errorf("Component '%s' not found in path: '%s'", info.Component, componentPath))
}

readmePath := filepath.Join(componentPath, "README.md")
readmePath := path.Join(componentPath, "README.md")
if _, err := os.Stat(readmePath); err != nil {
if os.IsNotExist(err) {
u.LogErrorAndExit(schema.AtmosConfiguration{}, fmt.Errorf("No README found for component: %s", info.Component))
Expand Down
3 changes: 2 additions & 1 deletion internal/exec/atlantis_generate_repo_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package exec

import (
"fmt"
"path"
"path/filepath"
"reflect"
"strings"
Expand Down Expand Up @@ -338,7 +339,7 @@ func ExecuteAtlantisGenerateRepoConfig(
}

// Absolute path to the terraform component
terraformComponentPath := filepath.Join(
terraformComponentPath := path.Join(
atmosConfig.BasePath,
atmosConfig.Components.Terraform.BasePath,
terraformComponent,
Expand Down
6 changes: 3 additions & 3 deletions internal/exec/aws_eks_update_kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package exec

import (
"fmt"
"path/filepath"
"path"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -158,11 +158,11 @@ func ExecuteAwsEksUpdateKubeconfig(kubeconfigContext schema.AwsEksUpdateKubeconf

configAndStacksInfo.ComponentType = "terraform"
configAndStacksInfo, err = ProcessStacks(atmosConfig, configAndStacksInfo, true, true)
shellCommandWorkingDir = filepath.Join(atmosConfig.TerraformDirAbsolutePath, configAndStacksInfo.ComponentFolderPrefix, configAndStacksInfo.FinalComponent)
shellCommandWorkingDir = path.Join(atmosConfig.TerraformDirAbsolutePath, configAndStacksInfo.ComponentFolderPrefix, configAndStacksInfo.FinalComponent)
if err != nil {
configAndStacksInfo.ComponentType = "helmfile"
configAndStacksInfo, err = ProcessStacks(atmosConfig, configAndStacksInfo, true, true)
shellCommandWorkingDir = filepath.Join(atmosConfig.HelmfileDirAbsolutePath, configAndStacksInfo.ComponentFolderPrefix, configAndStacksInfo.FinalComponent)
shellCommandWorkingDir = path.Join(atmosConfig.HelmfileDirAbsolutePath, configAndStacksInfo.ComponentFolderPrefix, configAndStacksInfo.FinalComponent)
if err != nil {
return err
}
Expand Down
14 changes: 7 additions & 7 deletions internal/exec/describe_affected_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,9 @@ func executeDescribeAffected(
}

// Update paths to point to the cloned remote repo dir
atmosConfig.StacksBaseAbsolutePath = filepath.Join(remoteRepoFileSystemPath, basePath, atmosConfig.Stacks.BasePath)
atmosConfig.TerraformDirAbsolutePath = filepath.Join(remoteRepoFileSystemPath, basePath, atmosConfig.Components.Terraform.BasePath)
atmosConfig.HelmfileDirAbsolutePath = filepath.Join(remoteRepoFileSystemPath, basePath, atmosConfig.Components.Helmfile.BasePath)
atmosConfig.StacksBaseAbsolutePath = path.Join(remoteRepoFileSystemPath, basePath, atmosConfig.Stacks.BasePath)
atmosConfig.TerraformDirAbsolutePath = path.Join(remoteRepoFileSystemPath, basePath, atmosConfig.Components.Terraform.BasePath)
atmosConfig.HelmfileDirAbsolutePath = path.Join(remoteRepoFileSystemPath, basePath, atmosConfig.Components.Helmfile.BasePath)

atmosConfig.StackConfigFilesAbsolutePaths, err = u.JoinAbsolutePathWithPaths(
filepath.Join(remoteRepoFileSystemPath, basePath, atmosConfig.Stacks.BasePath),
Expand Down Expand Up @@ -1182,9 +1182,9 @@ func isComponentFolderChanged(

switch componentType {
case "terraform":
componentPath = filepath.Join(atmosConfig.BasePath, atmosConfig.Components.Terraform.BasePath, component)
componentPath = path.Join(atmosConfig.BasePath, atmosConfig.Components.Terraform.BasePath, component)
case "helmfile":
componentPath = filepath.Join(atmosConfig.BasePath, atmosConfig.Components.Helmfile.BasePath, component)
componentPath = path.Join(atmosConfig.BasePath, atmosConfig.Components.Helmfile.BasePath, component)
}

componentPathAbs, err := filepath.Abs(componentPath)
Expand Down Expand Up @@ -1220,7 +1220,7 @@ func areTerraformComponentModulesChanged(
changedFiles []string,
) (bool, error) {

componentPath := filepath.Join(atmosConfig.BasePath, atmosConfig.Components.Terraform.BasePath, component)
componentPath := path.Join(atmosConfig.BasePath, atmosConfig.Components.Terraform.BasePath, component)

componentPathAbs, err := filepath.Abs(componentPath)
if err != nil {
Expand All @@ -1241,7 +1241,7 @@ func areTerraformComponentModulesChanged(
continue
}

modulePath := filepath.Join(path.Dir(moduleConfig.Pos.Filename), moduleConfig.Source)
modulePath := path.Join(path.Dir(moduleConfig.Pos.Filename), moduleConfig.Source)

modulePathAbs, err := filepath.Abs(modulePath)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions internal/exec/helmfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package exec
import (
"fmt"
"os"
"path/filepath"
"path"

"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -78,20 +78,20 @@ func ExecuteHelmfile(info schema.ConfigAndStacksInfo) error {
}

// Check if the component exists as a helmfile component
componentPath := filepath.Join(atmosConfig.HelmfileDirAbsolutePath, info.ComponentFolderPrefix, info.FinalComponent)
componentPath := path.Join(atmosConfig.HelmfileDirAbsolutePath, info.ComponentFolderPrefix, info.FinalComponent)
componentPathExists, err := u.IsDirectory(componentPath)
if err != nil || !componentPathExists {
return fmt.Errorf("'%s' points to the Helmfile component '%s', but it does not exist in '%s'",
info.ComponentFromArg,
info.FinalComponent,
filepath.Join(atmosConfig.Components.Helmfile.BasePath, info.ComponentFolderPrefix),
path.Join(atmosConfig.Components.Helmfile.BasePath, info.ComponentFolderPrefix),
)
}

// Check if the component is allowed to be provisioned (`metadata.type` attribute)
if (info.SubCommand == "sync" || info.SubCommand == "apply" || info.SubCommand == "deploy") && info.ComponentIsAbstract {
return fmt.Errorf("abstract component '%s' cannot be provisioned since it's explicitly prohibited from being deployed "+
"by 'metadata.type: abstract' attribute", filepath.Join(info.ComponentFolderPrefix, info.Component))
"by 'metadata.type: abstract' attribute", path.Join(info.ComponentFolderPrefix, info.Component))
}

// Print component variables
Expand Down Expand Up @@ -196,7 +196,7 @@ func ExecuteHelmfile(info schema.ConfigAndStacksInfo) error {
u.LogDebug(atmosConfig, "Stack: "+info.StackFromArg)
} else {
u.LogDebug(atmosConfig, "Stack: "+info.StackFromArg)
u.LogDebug(atmosConfig, "Stack path: "+filepath.Join(atmosConfig.BasePath, atmosConfig.Stacks.BasePath, info.Stack))
u.LogDebug(atmosConfig, "Stack path: "+path.Join(atmosConfig.BasePath, atmosConfig.Stacks.BasePath, info.Stack))
}

workingDir := constructHelmfileComponentWorkingDir(atmosConfig, info)
Expand Down
6 changes: 3 additions & 3 deletions internal/exec/oci_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"path"

"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
Expand All @@ -30,7 +30,7 @@ func processOciImage(atmosConfig schema.AtmosConfiguration, imageName string, de
defer removeTempDir(atmosConfig, tempDir)

// Temp tarball file name
tempTarFileName := filepath.Join(tempDir, uuid.New().String()) + ".tar"
tempTarFileName := path.Join(tempDir, uuid.New().String()) + ".tar"

// Get the image reference from the OCI registry
ref, err := name.ParseReference(imageName)
Expand Down Expand Up @@ -91,7 +91,7 @@ func processOciImage(atmosConfig schema.AtmosConfiguration, imageName string, de

// Extract the layers into the destination directory
for _, l := range manifest.Layers {
layerPath := filepath.Join(tempDir, l)
layerPath := path.Join(tempDir, l)

err = extractTarball(atmosConfig, layerPath, destDir)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions internal/exec/stack_processor_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func ProcessYAMLConfigFile(

found := false
for _, extension := range extensions {
testPath := filepath.Join(basePath, imp+extension)
testPath := path.Join(basePath, imp+extension)
if _, err := os.Stat(testPath); err == nil {
impWithExt = imp + extension
found = true
Expand All @@ -372,12 +372,12 @@ func ProcessYAMLConfigFile(
} else if ext == u.YamlFileExtension || ext == u.YmlFileExtension {
// Check if there's a template version of this file
templatePath := impWithExt + u.TemplateExtension
if _, err := os.Stat(filepath.Join(basePath, templatePath)); err == nil {
if _, err := os.Stat(path.Join(basePath, templatePath)); err == nil {
impWithExt = templatePath
}
}

impWithExtPath := filepath.Join(basePath, impWithExt)
impWithExtPath := path.Join(basePath, impWithExt)

if impWithExtPath == filePath {
errorMessage := fmt.Sprintf("invalid import in the manifest '%s'\nThe file imports itself in '%s'",
Expand Down Expand Up @@ -2180,7 +2180,7 @@ func ProcessBaseComponentConfig(
if checkBaseComponentExists {
// Check if the base component exists as Terraform/Helmfile component
// If it does exist, don't throw errors if it is not defined in YAML config
componentPath := filepath.Join(componentBasePath, baseComponent)
componentPath := path.Join(componentBasePath, baseComponent)
componentPathExists, err := u.IsDirectory(componentPath)
if err != nil || !componentPathExists {
return errors.New("The component '" + component + "' inherits from the base component '" +
Expand Down
6 changes: 3 additions & 3 deletions internal/exec/stack_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package exec

import (
"fmt"
"path/filepath"
"path"
"strings"

cfg "github.com/cloudposse/atmos/pkg/config"
Expand Down Expand Up @@ -164,9 +164,9 @@ func BuildComponentPath(

if stackComponentSection, ok := componentSectionMap[cfg.ComponentSectionName].(string); ok {
if componentType == "terraform" {
componentPath = filepath.Join(atmosConfig.BasePath, atmosConfig.Components.Terraform.BasePath, stackComponentSection)
componentPath = path.Join(atmosConfig.BasePath, atmosConfig.Components.Terraform.BasePath, stackComponentSection)
} else if componentType == "helmfile" {
componentPath = filepath.Join(atmosConfig.BasePath, atmosConfig.Components.Helmfile.BasePath, stackComponentSection)
componentPath = path.Join(atmosConfig.BasePath, atmosConfig.Components.Helmfile.BasePath, stackComponentSection)
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/exec/terraform_generate_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package exec

import (
"fmt"
"path/filepath"
"path"

"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -75,7 +75,7 @@ func ExecuteTerraformGenerateBackendCmd(cmd *cobra.Command, args []string) error
}

// Write backend config to file
var backendFilePath = filepath.Join(
var backendFilePath = path.Join(
atmosConfig.BasePath,
atmosConfig.Components.Terraform.BasePath,
info.ComponentFolderPrefix,
Expand Down
5 changes: 3 additions & 2 deletions internal/exec/terraform_generate_backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package exec
import (
"errors"
"fmt"
"path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -160,7 +161,7 @@ func ExecuteTerraformGenerateBackends(
}

// Path to the terraform component
terraformComponentPath := filepath.Join(
terraformComponentPath := path.Join(
atmosConfig.BasePath,
atmosConfig.Components.Terraform.BasePath,
terraformComponent,
Expand Down Expand Up @@ -290,7 +291,7 @@ func ExecuteTerraformGenerateBackends(

processedTerraformComponents[terraformComponent] = terraformComponent

backendFilePath = filepath.Join(
backendFilePath = path.Join(
terraformComponentPath,
"backend.tf",
)
Expand Down
3 changes: 2 additions & 1 deletion internal/exec/terraform_generate_varfiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package exec
import (
"errors"
"fmt"
"path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -159,7 +160,7 @@ func ExecuteTerraformGenerateVarfiles(
}

// Absolute path to the terraform component
terraformComponentPath := filepath.Join(
terraformComponentPath := path.Join(
atmosConfig.BasePath,
atmosConfig.Components.Terraform.BasePath,
terraformComponent,
Expand Down
5 changes: 3 additions & 2 deletions internal/exec/terraform_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"os"
"path"
"path/filepath"
"time"

Expand Down Expand Up @@ -87,7 +88,7 @@ func execTerraformOutput(atmosConfig schema.AtmosConfiguration, component string

// Auto-generate backend file
if atmosConfig.Components.Terraform.AutoGenerateBackendFile {
backendFileName := filepath.Join(componentPath, "backend.tf.json")
backendFileName := path.Join(componentPath, "backend.tf.json")

u.LogTrace(atmosConfig, "\nWriting the backend config to file:")
u.LogTrace(atmosConfig, backendFileName)
Expand Down Expand Up @@ -120,7 +121,7 @@ func execTerraformOutput(atmosConfig schema.AtmosConfiguration, component string
providersSection, ok := sections["providers"].(map[string]any)

if ok && len(providersSection) > 0 {
providerOverrideFileName := filepath.Join(componentPath, "providers_override.tf.json")
providerOverrideFileName := path.Join(componentPath, "providers_override.tf.json")

u.LogTrace(atmosConfig, "\nWriting the provider overrides to file:")
u.LogTrace(atmosConfig, providerOverrideFileName)
Expand Down
8 changes: 4 additions & 4 deletions internal/exec/validate_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package exec
import (
"fmt"
"os"
"path/filepath"
"path"

"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
Expand Down Expand Up @@ -197,11 +197,11 @@ func validateComponentInternal(
switch schemaType {
case "jsonschema":
{
filePath = filepath.Join(atmosConfig.BasePath, atmosConfig.Schemas.JsonSchema.BasePath, schemaPath)
filePath = path.Join(atmosConfig.BasePath, atmosConfig.Schemas.JsonSchema.BasePath, schemaPath)
}
case "opa":
{
filePath = filepath.Join(atmosConfig.BasePath, atmosConfig.Schemas.Opa.BasePath, schemaPath)
filePath = path.Join(atmosConfig.BasePath, atmosConfig.Schemas.Opa.BasePath, schemaPath)
}
}

Expand All @@ -228,7 +228,7 @@ func validateComponentInternal(
}
case "opa":
{
modulePathsAbsolute, err := u.JoinAbsolutePathWithPaths(filepath.Join(atmosConfig.BasePath, atmosConfig.Schemas.Opa.BasePath), modulePaths)
modulePathsAbsolute, err := u.JoinAbsolutePathWithPaths(path.Join(atmosConfig.BasePath, atmosConfig.Schemas.Opa.BasePath), modulePaths)
if err != nil {
return false, err
}
Expand Down
Loading

0 comments on commit 7608538

Please sign in to comment.