Merge branch 'main' into add_scan_err_details
commit
f2097d6c58
|
@ -35,10 +35,14 @@ func NewConsole() *Console {
|
|||
|
||||
func (c *Console) Write(analysis *analyser.Analysis) error {
|
||||
if analysis.Summary().TotalDeleted > 0 {
|
||||
var sources []string
|
||||
groupedBySource := make(map[string][]*resource.Resource)
|
||||
|
||||
for _, deletedResource := range analysis.Deleted() {
|
||||
key := deletedResource.Source.Source()
|
||||
key := ""
|
||||
if deletedResource.Source != nil {
|
||||
key = deletedResource.Source.Source()
|
||||
}
|
||||
|
||||
if _, exist := groupedBySource[key]; !exist {
|
||||
groupedBySource[key] = []*resource.Resource{deletedResource}
|
||||
|
@ -48,15 +52,28 @@ func (c *Console) Write(analysis *analyser.Analysis) error {
|
|||
groupedBySource[key] = append(groupedBySource[key], deletedResource)
|
||||
}
|
||||
|
||||
for s := range groupedBySource {
|
||||
sources = append(sources, s)
|
||||
}
|
||||
sort.Strings(sources)
|
||||
|
||||
fmt.Println("Found missing resources:")
|
||||
|
||||
for source, deletedResources := range groupedBySource {
|
||||
fmt.Print(color.BlueString(" From %s\n", source))
|
||||
for _, deletedResource := range deletedResources {
|
||||
humanString := fmt.Sprintf(" - %s (%s)", deletedResource.ResourceId(), deletedResource.SourceString())
|
||||
for _, source := range sources {
|
||||
indentBase := " "
|
||||
if source != "" {
|
||||
fmt.Print(color.BlueString("%sFrom %s\n", indentBase, source))
|
||||
indentBase += indentBase
|
||||
}
|
||||
for _, deletedResource := range groupedBySource[source] {
|
||||
humanStringSource := deletedResource.ResourceType()
|
||||
if deletedResource.SourceString() != "" {
|
||||
humanStringSource = deletedResource.SourceString()
|
||||
}
|
||||
humanString := fmt.Sprintf("%s- %s (%s)", indentBase, deletedResource.ResourceId(), humanStringSource)
|
||||
|
||||
if humanAttrs := formatResourceAttributes(deletedResource); humanAttrs != "" {
|
||||
humanString += fmt.Sprintf("\n %s", humanAttrs)
|
||||
humanString += fmt.Sprintf("\n%s %s", indentBase, humanAttrs)
|
||||
}
|
||||
fmt.Println(humanString)
|
||||
}
|
||||
|
@ -79,26 +96,42 @@ func (c *Console) Write(analysis *analyser.Analysis) error {
|
|||
}
|
||||
|
||||
if analysis.Summary().TotalDrifted > 0 {
|
||||
|
||||
var sources []string
|
||||
groupedBySource := make(map[string][]analyser.Difference)
|
||||
for _, diff := range analysis.Differences() {
|
||||
key := diff.Res.Source.Source()
|
||||
for _, difference := range analysis.Differences() {
|
||||
key := ""
|
||||
if difference.Res.Source != nil {
|
||||
key = difference.Res.Source.Source()
|
||||
}
|
||||
if _, exist := groupedBySource[key]; !exist {
|
||||
groupedBySource[key] = []analyser.Difference{diff}
|
||||
groupedBySource[key] = []analyser.Difference{difference}
|
||||
continue
|
||||
}
|
||||
groupedBySource[key] = append(groupedBySource[key], diff)
|
||||
groupedBySource[key] = append(groupedBySource[key], difference)
|
||||
}
|
||||
|
||||
for s := range groupedBySource {
|
||||
sources = append(sources, s)
|
||||
}
|
||||
sort.Strings(sources)
|
||||
|
||||
fmt.Println("Found changed resources:")
|
||||
for source, differences := range groupedBySource {
|
||||
fmt.Print(color.BlueString(" From %s\n", source))
|
||||
for _, difference := range differences {
|
||||
humanString := fmt.Sprintf(" - %s (%s):", difference.Res.ResourceId(), difference.Res.SourceString())
|
||||
whiteSpace := " "
|
||||
for _, source := range sources {
|
||||
indentBase := " "
|
||||
if source != "" {
|
||||
fmt.Print(color.BlueString("%sFrom %s\n", indentBase, source))
|
||||
indentBase += indentBase
|
||||
}
|
||||
for _, difference := range groupedBySource[source] {
|
||||
humanStringSource := difference.Res.ResourceType()
|
||||
if difference.Res.SourceString() != "" {
|
||||
humanStringSource = difference.Res.SourceString()
|
||||
}
|
||||
humanString := fmt.Sprintf("%s- %s (%s):", indentBase, difference.Res.ResourceId(), humanStringSource)
|
||||
whiteSpace := indentBase + " "
|
||||
if humanAttrs := formatResourceAttributes(difference.Res); humanAttrs != "" {
|
||||
humanString += fmt.Sprintf("\n %s", humanAttrs)
|
||||
whiteSpace = " "
|
||||
humanString += fmt.Sprintf("\n%s%s", whiteSpace, humanAttrs)
|
||||
whiteSpace += " "
|
||||
}
|
||||
fmt.Println(humanString)
|
||||
for _, change := range difference.Changelog {
|
||||
|
|
|
@ -183,20 +183,6 @@ func TestHTML_Write(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}})
|
||||
a.AddDifference(analyser.Difference{
|
||||
Res: &resource.Resource{
|
||||
Id: "diff-id-3",
|
||||
Type: "aws_diff_resource",
|
||||
}, Changelog: []analyser.Change{
|
||||
{
|
||||
Change: diff.Change{
|
||||
Type: diff.UPDATE,
|
||||
Path: []string{"InstanceInitiatedShutdownBehavior"},
|
||||
From: "",
|
||||
To: nil,
|
||||
},
|
||||
},
|
||||
}})
|
||||
a.ProviderName = "AWS"
|
||||
a.ProviderVersion = "3.19.0"
|
||||
return a
|
||||
|
|
|
@ -40,11 +40,6 @@ func fakeAnalysis() *analyser.Analysis {
|
|||
}, &resource.Resource{
|
||||
Id: "deleted-id-2",
|
||||
Type: "aws_deleted_resource",
|
||||
Source: &resource.TerraformStateSource{
|
||||
State: "tfstate://delete_state.tfstate",
|
||||
Module: "module",
|
||||
Name: "name",
|
||||
},
|
||||
},
|
||||
)
|
||||
a.AddManaged(
|
||||
|
@ -57,6 +52,23 @@ func fakeAnalysis() *analyser.Analysis {
|
|||
Type: "aws_no_diff_resource",
|
||||
},
|
||||
)
|
||||
// Cover the case when a diff occur on a resource without a source
|
||||
a.AddDifference(analyser.Difference{
|
||||
Res: &resource.Resource{
|
||||
Id: "diff-id-2",
|
||||
Type: "aws_diff_resource",
|
||||
},
|
||||
Changelog: []analyser.Change{
|
||||
{
|
||||
Change: diff.Change{
|
||||
Type: diff.UPDATE,
|
||||
Path: []string{"updated", "field"},
|
||||
From: "foobar",
|
||||
To: "barfoo",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
a.AddDifference(analyser.Difference{Res: &resource.Resource{
|
||||
Id: "diff-id-1",
|
||||
Type: "aws_diff_resource",
|
||||
|
|
|
@ -515,6 +515,20 @@ input[type="search"], select {
|
|||
</div>
|
||||
<div role="rowgroup" class="table-body">
|
||||
|
||||
<div role="row" data-kind="resource-changed" class="resource-item">
|
||||
<div class="row">
|
||||
<span role="cell">
|
||||
<span data-type="resource-id">diff-id-2</span>
|
||||
<span>(aws_diff_resource)</span>
|
||||
<span style="display:none;" data-type="resource-type">aws_diff_resource</span>
|
||||
</span>
|
||||
|
||||
</div>
|
||||
<pre class="code-box">
|
||||
<code class="code-box-line"> ~ updated.field: <span class="code-box-line-delete">"foobar"</span> => <span class="code-box-line-create">"barfoo"</span><br></code>
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<div role="row" data-kind="resource-changed" class="resource-item">
|
||||
<div class="row">
|
||||
<span role="cell">
|
||||
|
@ -573,20 +587,6 @@ input[type="search"], select {
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<div role="row" data-kind="resource-changed" class="resource-item">
|
||||
<div class="row">
|
||||
<span role="cell">
|
||||
<span data-type="resource-id">diff-id-3</span>
|
||||
<span>(aws_diff_resource)</span>
|
||||
<span style="display:none;" data-type="resource-type">aws_diff_resource</span>
|
||||
</span>
|
||||
|
||||
</div>
|
||||
<pre class="code-box">
|
||||
<code class="code-box-line"> ~ InstanceInitiatedShutdownBehavior: <span class="code-box-line-delete">""</span> => <span class="code-box-line-create">null</span><br></code>
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="empty-panel is-hidden">
|
||||
|
@ -617,10 +617,10 @@ input[type="search"], select {
|
|||
<tr data-kind="resource-deleted" class="resource-item row">
|
||||
<td>
|
||||
<span data-type="resource-id">deleted-id-2</span>
|
||||
<span>(module.aws_deleted_resource.name)</span>
|
||||
<span>(aws_deleted_resource)</span>
|
||||
<span data-type="resource-type" style="display:none;">aws_deleted_resource</span>
|
||||
</td>
|
||||
<td data-type="resource-source">tfstate://delete_state.tfstate</td>
|
||||
|
||||
</tr>
|
||||
|
||||
<tr data-kind="resource-deleted" class="resource-item row">
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"summary": {
|
||||
"total_resources": 6,
|
||||
"total_changed": 1,
|
||||
"total_changed": 2,
|
||||
"total_unmanaged": 2,
|
||||
"total_missing": 2,
|
||||
"total_managed": 2
|
||||
|
@ -38,15 +38,28 @@
|
|||
},
|
||||
{
|
||||
"id": "deleted-id-2",
|
||||
"type": "aws_deleted_resource",
|
||||
"source": {
|
||||
"source": "tfstate://delete_state.tfstate",
|
||||
"namespace": "module",
|
||||
"internal_name": "name"
|
||||
}
|
||||
"type": "aws_deleted_resource"
|
||||
}
|
||||
],
|
||||
"differences": [
|
||||
{
|
||||
"res": {
|
||||
"id": "diff-id-2",
|
||||
"type": "aws_diff_resource"
|
||||
},
|
||||
"changelog": [
|
||||
{
|
||||
"type": "update",
|
||||
"path": [
|
||||
"updated",
|
||||
"field"
|
||||
],
|
||||
"from": "foobar",
|
||||
"to": "barfoo",
|
||||
"computed": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"res": {
|
||||
"id": "diff-id-1",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
Found missing resources:
|
||||
- deleted-id-2 (aws_deleted_resource)
|
||||
From tfstate://delete_state.tfstate
|
||||
- deleted-id-1 (module.aws_deleted_resource.name)
|
||||
- deleted-id-2 (module.aws_deleted_resource.name)
|
||||
From tfstate://test_state.tfstate
|
||||
- test-id-1 (module.aws_test_resource.name)
|
||||
- test-id-2 (module.aws_test_resource.name)
|
||||
|
@ -14,6 +14,8 @@ Found resources not covered by IaC:
|
|||
- unmanaged-id-1
|
||||
- unmanaged-id-2
|
||||
Found changed resources:
|
||||
- diff-id-2 (aws_diff_resource):
|
||||
~ updated.field: "foobar" => "barfoo"
|
||||
From tfstate://state.tfstate
|
||||
- diff-id-1 (module.aws_diff_resource.name):
|
||||
~ updated.field: "foobar" => "barfoo"
|
||||
|
@ -22,6 +24,6 @@ Found changed resources:
|
|||
Found 10 resource(s)
|
||||
- 20% coverage
|
||||
- 2 resource(s) managed by terraform
|
||||
- 1/2 resource(s) out of sync with Terraform state
|
||||
- 2/2 resource(s) out of sync with Terraform state
|
||||
- 4 resource(s) not managed by Terraform
|
||||
- 4 resource(s) found in a Terraform state but missing on the cloud provider
|
||||
|
|
|
@ -73,6 +73,9 @@ func (r *Resource) Src() Source {
|
|||
}
|
||||
|
||||
func (r *Resource) SourceString() string {
|
||||
if r.Source == nil {
|
||||
return ""
|
||||
}
|
||||
if r.Source.Namespace() == "" {
|
||||
return fmt.Sprintf("%s.%s", r.ResourceType(), r.Source.InternalName())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue