Skip to content

Commit

Permalink
fix(url): nameing
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Sanvoisin committed Jun 30, 2023
1 parent 058b397 commit 24c5648
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 30 deletions.
3 changes: 1 addition & 2 deletions checks/iterate.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ func Iterate() data.Check {
name := "Don't use count to create multiple resources"
relatedGuidelines := "https://padok-team.github.io/docs-terraform-guidelines/terraform/iterate_on_your_resources.html#list-iteration-count"
status := "✅"

codebasePath := viper.GetString("codebase-path")
codebasePath := viper.GetString("codebase-path") + "layers/alerting"

tf, err := tfexec.NewTerraform(codebasePath, "terragrunt")
if err != nil {
Expand Down
30 changes: 4 additions & 26 deletions checks/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@ package checks
import (
"fmt"
"guacamole/data"
"os"
"path/filepath"
"guacamole/helpers"

"github.com/hashicorp/terraform-config-inspect/tfconfig"
)

func ProviderInModule() data.Check {
name := "No provider in module"
relatedGuidelines := "https://github.com/padok-team/docs-terraform-guidelines/blob/main/terraform/donts.md#using-provider-block-in-modules"
relatedGuidelines := "https://padok-team.github.io/docs-terraform-guidelines/terraform/donts.html#using-provider-block-in-modules"
fmt.Println("Checking none prescence provider in module...")
// Find recusively all the modules in the current directory
modules, err := getModules()
modules, err := helpers.GetModules()
if err != nil {
fmt.Println("Error:", err)
}
modulesInError := []Module{}
modulesInError := []data.Module{}
// For each module, check if the provider is defined
for _, module := range modules {
moduleConf, diags := tfconfig.LoadModule(module.FullPath)
Expand Down Expand Up @@ -46,24 +45,3 @@ func ProviderInModule() data.Check {
Status: "✅",
}
}

type Module struct {
Name string
FullPath string
}

func getModules() ([]Module, error) {
root := "/Users/benjaminsanvoisin/dev/wizzair/aws-network/modules"
modules := []Module{}
//Get all subdirectories in root path
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
fmt.Println("Error:", err)
}
if info.IsDir() && path != root {
modules = append(modules, Module{Name: info.Name(), FullPath: path})
}
return nil
})
return modules, err
}
5 changes: 3 additions & 2 deletions checks/naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ package checks
import (
"fmt"
"guacamole/data"
"guacamole/helpers"
"strings"

"github.com/hashicorp/terraform-config-inspect/tfconfig"
)

func Naming() data.Check {
name := "Stuttering in the naming of the resources"
relatedGuidelines := "https://github.com/padok-team/docs-terraform-guidelines/blob/main/terraform/terraform_naming.md"
relatedGuidelines := "https://padok-team.github.io/docs-terraform-guidelines/terraform/terraform_naming.html#resource-andor-data-source-naming"
fmt.Println("Checking naming convention...")
modules, err := getModules()
modules, err := helpers.GetModules()
if err != nil {
fmt.Println("Error:", err)
}
Expand Down
5 changes: 5 additions & 0 deletions data/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ type Check struct {
Status string
RelatedGuidelines string
}

type Module struct {
Name string
FullPath string
}
26 changes: 26 additions & 0 deletions helpers/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package helpers

import (
"fmt"
"guacamole/data"
"os"
"path/filepath"

"github.com/spf13/viper"
)

func GetModules() ([]data.Module, error) {
codebasePath := viper.GetString("codebase-path") + "modules/"
modules := []data.Module{}
//Get all subdirectories in root path
err := filepath.Walk(codebasePath, func(path string, info os.FileInfo, err error) error {
if err != nil {
fmt.Println("Error:", err)
}
if info.IsDir() && path != codebasePath {
modules = append(modules, data.Module{Name: info.Name(), FullPath: path})
}
return nil
})
return modules, err
}

0 comments on commit 24c5648

Please sign in to comment.