diff --git a/internal/format/templates/pretty.tmpl b/internal/format/templates/pretty.tmpl
index 3b0ce27..368a478 100644
--- a/internal/format/templates/pretty.tmpl
+++ b/internal/format/templates/pretty.tmpl
@@ -37,11 +37,8 @@
{{- if .Settings.ShowResources -}}
{{- with .Module.Resources }}
{{- range . }}
- {{- if eq (len .URL) 0 }}
- {{- printf "resource.%s (%s)" .Spec .GetMode | colorize "\033[36m" }}
- {{- else -}}
- {{- printf "resource.%s (%s)" .Spec .GetMode | colorize "\033[36m" }} ({{ .URL}})
- {{- end }}
+ {{- $url := ternary .URL (printf " (%s)" .URL) "" }}
+ {{- printf "resource.%s (%s)" .Spec .GetMode | colorize "\033[36m" }}{{ $url }}
{{ end -}}
{{ end -}}
{{- printf "\n\n" -}}
@@ -77,4 +74,4 @@
{{ colorize "\033[90m" . }}
{{ end -}}
{{- printf "\n\n" -}}
-{{ end -}}
+{{ end -}}
\ No newline at end of file
diff --git a/internal/format/testdata/json/json-Base.golden b/internal/format/testdata/json/json-Base.golden
index 29de44d..8c47aad 100644
--- a/internal/format/testdata/json/json-Base.golden
+++ b/internal/format/testdata/json/json-Base.golden
@@ -320,34 +320,34 @@
{
"type": "resource",
"name": "foo",
- "providerName": "null",
- "provicerSource": "hashicorp/null",
+ "provider": "null",
+ "source": "hashicorp/null",
"mode": "managed",
"version": "latest"
},
{
"type": "private_key",
"name": "baz",
- "providerName": "tls",
- "provicerSource": "hashicorp/tls",
+ "provider": "tls",
+ "source": "hashicorp/tls",
"mode": "managed",
"version": "latest"
},
{
"type": "caller_identity",
"name": "current",
- "providerName": "aws",
- "provicerSource": "hashicorp/aws",
+ "provider": "aws",
+ "source": "hashicorp/aws",
"mode": "data",
"version": "latest"
},
{
"type": "caller_identity",
"name": "ident",
- "providerName": "aws",
- "provicerSource": "hashicorp/aws",
+ "provider": "aws",
+ "source": "hashicorp/aws",
"mode": "data",
"version": "latest"
}
]
-}
+}
\ No newline at end of file
diff --git a/internal/format/testdata/json/json-EscapeCharacters.golden b/internal/format/testdata/json/json-EscapeCharacters.golden
index bc77e7b..4cf9664 100644
--- a/internal/format/testdata/json/json-EscapeCharacters.golden
+++ b/internal/format/testdata/json/json-EscapeCharacters.golden
@@ -320,34 +320,34 @@
{
"type": "resource",
"name": "foo",
- "providerName": "null",
- "provicerSource": "hashicorp/null",
+ "provider": "null",
+ "source": "hashicorp/null",
"mode": "managed",
"version": "latest"
},
{
"type": "private_key",
"name": "baz",
- "providerName": "tls",
- "provicerSource": "hashicorp/tls",
+ "provider": "tls",
+ "source": "hashicorp/tls",
"mode": "managed",
"version": "latest"
},
{
"type": "caller_identity",
"name": "current",
- "providerName": "aws",
- "provicerSource": "hashicorp/aws",
+ "provider": "aws",
+ "source": "hashicorp/aws",
"mode": "data",
"version": "latest"
},
{
"type": "caller_identity",
"name": "ident",
- "providerName": "aws",
- "provicerSource": "hashicorp/aws",
+ "provider": "aws",
+ "source": "hashicorp/aws",
"mode": "data",
"version": "latest"
}
]
-}
+}
\ No newline at end of file
diff --git a/internal/format/testdata/json/json-OnlyResources.golden b/internal/format/testdata/json/json-OnlyResources.golden
index 8200a5d..af2303a 100644
--- a/internal/format/testdata/json/json-OnlyResources.golden
+++ b/internal/format/testdata/json/json-OnlyResources.golden
@@ -10,34 +10,34 @@
{
"type": "resource",
"name": "foo",
- "providerName": "null",
- "provicerSource": "hashicorp/null",
+ "provider": "null",
+ "source": "hashicorp/null",
"mode": "managed",
"version": "latest"
},
{
"type": "private_key",
"name": "baz",
- "providerName": "tls",
- "provicerSource": "hashicorp/tls",
+ "provider": "tls",
+ "source": "hashicorp/tls",
"mode": "managed",
"version": "latest"
},
{
"type": "caller_identity",
"name": "current",
- "providerName": "aws",
- "provicerSource": "hashicorp/aws",
+ "provider": "aws",
+ "source": "hashicorp/aws",
"mode": "data",
"version": "latest"
},
{
"type": "caller_identity",
"name": "ident",
- "providerName": "aws",
- "provicerSource": "hashicorp/aws",
+ "provider": "aws",
+ "source": "hashicorp/aws",
"mode": "data",
"version": "latest"
}
]
-}
+}
\ No newline at end of file
diff --git a/internal/format/testdata/toml/toml-Base.golden b/internal/format/testdata/toml/toml-Base.golden
index 2611658..14f3b60 100644
--- a/internal/format/testdata/toml/toml-Base.golden
+++ b/internal/format/testdata/toml/toml-Base.golden
@@ -296,31 +296,31 @@ footer = "## This is an example of a footer\n\nIt looks exactly like a header, b
[[resources]]
type = "resource"
name = "foo"
- providerName = "null"
- providerSource = "hashicorp/null"
+ provider = "null"
+ source = "hashicorp/null"
mode = "managed"
version = "latest"
[[resources]]
type = "private_key"
name = "baz"
- providerName = "tls"
- providerSource = "hashicorp/tls"
+ provider = "tls"
+ source = "hashicorp/tls"
mode = "managed"
version = "latest"
[[resources]]
type = "caller_identity"
name = "current"
- providerName = "aws"
- providerSource = "hashicorp/aws"
+ provider = "aws"
+ source = "hashicorp/aws"
mode = "data"
version = "latest"
[[resources]]
type = "caller_identity"
name = "ident"
- providerName = "aws"
- providerSource = "hashicorp/aws"
+ provider = "aws"
+ source = "hashicorp/aws"
mode = "data"
version = "latest"
\ No newline at end of file
diff --git a/internal/format/testdata/toml/toml-OnlyResources.golden b/internal/format/testdata/toml/toml-OnlyResources.golden
index 1ff1e8f..7f7f16e 100644
--- a/internal/format/testdata/toml/toml-OnlyResources.golden
+++ b/internal/format/testdata/toml/toml-OnlyResources.golden
@@ -9,31 +9,31 @@ requirements = []
[[resources]]
type = "resource"
name = "foo"
- providerName = "null"
- providerSource = "hashicorp/null"
+ provider = "null"
+ source = "hashicorp/null"
mode = "managed"
version = "latest"
[[resources]]
type = "private_key"
name = "baz"
- providerName = "tls"
- providerSource = "hashicorp/tls"
+ provider = "tls"
+ source = "hashicorp/tls"
mode = "managed"
version = "latest"
[[resources]]
type = "caller_identity"
name = "current"
- providerName = "aws"
- providerSource = "hashicorp/aws"
+ provider = "aws"
+ source = "hashicorp/aws"
mode = "data"
version = "latest"
[[resources]]
type = "caller_identity"
name = "ident"
- providerName = "aws"
- providerSource = "hashicorp/aws"
+ provider = "aws"
+ source = "hashicorp/aws"
mode = "data"
- version = "latest"
+ version = "latest"
\ No newline at end of file
diff --git a/internal/format/testdata/xml/xml-Base.golden b/internal/format/testdata/xml/xml-Base.golden
index 8187a4d..7e5b1c8 100644
--- a/internal/format/testdata/xml/xml-Base.golden
+++ b/internal/format/testdata/xml/xml-Base.golden
@@ -320,32 +320,32 @@
resource
foo
- null
- hashicorp/null
+ null
+ hashicorp/null
managed
latest
private_key
baz
- tls
- hashicorp/tls
+ tls
+ hashicorp/tls
managed
latest
caller_identity
current
- aws
- hashicorp/aws
+ aws
+ hashicorp/aws
data
latest
caller_identity
ident
- aws
- hashicorp/aws
+ aws
+ hashicorp/aws
data
latest
diff --git a/internal/format/testdata/xml/xml-OnlyResources.golden b/internal/format/testdata/xml/xml-OnlyResources.golden
index 98ab2b6..ad10a5e 100644
--- a/internal/format/testdata/xml/xml-OnlyResources.golden
+++ b/internal/format/testdata/xml/xml-OnlyResources.golden
@@ -10,34 +10,34 @@
resource
foo
- null
- hashicorp/null
+ null
+ hashicorp/null
managed
latest
private_key
baz
- tls
- hashicorp/tls
+ tls
+ hashicorp/tls
managed
latest
caller_identity
current
- aws
- hashicorp/aws
+ aws
+ hashicorp/aws
data
latest
caller_identity
ident
- aws
- hashicorp/aws
+ aws
+ hashicorp/aws
data
latest
-
+
\ No newline at end of file
diff --git a/internal/format/testdata/yaml/yaml-Base.golden b/internal/format/testdata/yaml/yaml-Base.golden
index 349fa2e..94a498b 100644
--- a/internal/format/testdata/yaml/yaml-Base.golden
+++ b/internal/format/testdata/yaml/yaml-Base.golden
@@ -266,25 +266,25 @@ requirements:
resources:
- type: resource
name: foo
- providerName: "null"
- providerSource: hashicorp/null
+ provider: "null"
+ source: hashicorp/null
mode: managed
version: latest
- type: private_key
name: baz
- providerName: tls
- providerSource: hashicorp/tls
+ provider: tls
+ source: hashicorp/tls
mode: managed
version: latest
- type: caller_identity
name: current
- providerName: aws
- providerSource: hashicorp/aws
+ provider: aws
+ source: hashicorp/aws
mode: data
version: latest
- type: caller_identity
name: ident
- providerName: aws
- providerSource: hashicorp/aws
+ provider: aws
+ source: hashicorp/aws
mode: data
- version: latest
+ version: latest
\ No newline at end of file
diff --git a/internal/format/testdata/yaml/yaml-OnlyResources.golden b/internal/format/testdata/yaml/yaml-OnlyResources.golden
index 85ef85e..d000f11 100644
--- a/internal/format/testdata/yaml/yaml-OnlyResources.golden
+++ b/internal/format/testdata/yaml/yaml-OnlyResources.golden
@@ -8,25 +8,25 @@ requirements: []
resources:
- type: resource
name: foo
- providerName: "null"
- providerSource: hashicorp/null
+ provider: "null"
+ source: hashicorp/null
mode: managed
version: latest
- type: private_key
name: baz
- providerName: tls
- providerSource: hashicorp/tls
+ provider: tls
+ source: hashicorp/tls
mode: managed
version: latest
- type: caller_identity
name: current
- providerName: aws
- providerSource: hashicorp/aws
+ provider: aws
+ source: hashicorp/aws
mode: data
version: latest
- type: caller_identity
name: ident
- providerName: aws
- providerSource: hashicorp/aws
+ provider: aws
+ source: hashicorp/aws
mode: data
- version: latest
+ version: latest
\ No newline at end of file
diff --git a/internal/terraform/module.go b/internal/terraform/module.go
index 2e47fb6..fedcb71 100644
--- a/internal/terraform/module.go
+++ b/internal/terraform/module.go
@@ -428,12 +428,14 @@ func loadResources(tfmodule *tfconfig.Module) []*Resource {
if rv, ok := tfmodule.RequiredProviders[r.Provider.Name]; ok {
version = resourceVersion(rv.VersionConstraints)
}
+
var source string
if len(tfmodule.RequiredProviders[r.Provider.Name].Source) > 0 {
source = tfmodule.RequiredProviders[r.Provider.Name].Source
} else {
source = fmt.Sprintf("%s/%s", "hashicorp", r.Provider.Name)
}
+
rType := strings.TrimPrefix(r.Type, r.Provider.Name+"_")
key := fmt.Sprintf("%s.%s.%s.%s", r.Provider.Name, r.Mode, rType, r.Name)
discovered[key] = &Resource{
@@ -443,6 +445,10 @@ func loadResources(tfmodule *tfconfig.Module) []*Resource {
ProviderName: r.Provider.Name,
ProviderSource: source,
Version: types.String(version),
+ Position: Position{
+ Filename: r.Pos.Filename,
+ Line: r.Pos.Line,
+ },
}
}
}
@@ -532,7 +538,7 @@ func sortItems(tfmodule *Module, sortby *SortBy) {
sort.Sort(providersSortedByPosition(tfmodule.Providers))
}
- // Always sort resources
+ // resources (always sorted)
sort.Sort(resourcesSortedByType(tfmodule.Resources))
// modules
diff --git a/internal/terraform/resource.go b/internal/terraform/resource.go
index 9886d92..d057b84 100644
--- a/internal/terraform/resource.go
+++ b/internal/terraform/resource.go
@@ -22,10 +22,11 @@ import (
type Resource struct {
Type string `json:"type" toml:"type" xml:"type" yaml:"type"`
Name string `json:"name" toml:"name" xml:"name" yaml:"name"`
- ProviderName string `json:"providerName" toml:"providerName" xml:"providerName" yaml:"providerName"`
- ProviderSource string `json:"provicerSource" toml:"providerSource" xml:"providerSource" yaml:"providerSource"`
+ ProviderName string `json:"provider" toml:"provider" xml:"provider" yaml:"provider"`
+ ProviderSource string `json:"source" toml:"source" xml:"source" yaml:"source"`
Mode string `json:"mode" toml:"mode" xml:"mode" yaml:"mode"`
Version types.String `json:"version" toml:"version" xml:"version" yaml:"version"`
+ Position Position `json:"-" toml:"-" xml:"-" yaml:"-"`
}
// Spec returns the resource spec addresses a specific resource in the config.
@@ -66,23 +67,6 @@ func (r *Resource) URL() string {
return fmt.Sprintf("https://registry.terraform.io/providers/%s/%s/docs/%s/%s", r.ProviderSource, r.Version, kind, r.Type)
}
-type resources []*Resource
-
-func (rr resources) convert() []*terraformsdk.Resource {
- list := []*terraformsdk.Resource{}
- for _, r := range rr {
- list = append(list, &terraformsdk.Resource{
- Type: r.Type,
- Name: r.Name,
- ProviderName: r.ProviderName,
- ProviderSource: r.ProviderSource,
- Version: fmt.Sprintf("%v", r.Version.Raw()),
- })
- }
-
- return list
-}
-
type resourcesSortedByType []*Resource
func (a resourcesSortedByType) Len() int { return len(a) }
@@ -96,3 +80,24 @@ func (a resourcesSortedByType) Less(i, j int) bool {
}
return a[i].Mode > a[j].Mode
}
+
+type resources []*Resource
+
+func (rr resources) convert() []*terraformsdk.Resource {
+ list := []*terraformsdk.Resource{}
+ for _, r := range rr {
+ list = append(list, &terraformsdk.Resource{
+ Type: r.Type,
+ Name: r.Name,
+ ProviderName: r.ProviderName,
+ ProviderSource: r.ProviderSource,
+ Version: fmt.Sprintf("%v", r.Version.Raw()),
+ Position: terraformsdk.Position{
+ Filename: r.Position.Filename,
+ Line: r.Position.Line,
+ },
+ })
+ }
+
+ return list
+}