Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
renovate
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
Renovate Bot
renovate
Commits
7b21f347
Unverified
Commit
7b21f347
authored
1 year ago
by
Michael Kriese
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
fix(terraform): return null for files without deps (#22731)
parent
45c2d13f
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/modules/manager/terraform/extract.spec.ts
+11
-0
11 additions, 0 deletions
lib/modules/manager/terraform/extract.spec.ts
lib/modules/manager/terraform/extract.ts
+9
-4
9 additions, 4 deletions
lib/modules/manager/terraform/extract.ts
with
20 additions
and
4 deletions
lib/modules/manager/terraform/extract.spec.ts
+
11
−
0
View file @
7b21f347
...
@@ -40,6 +40,17 @@ describe('modules/manager/terraform/extract', () => {
...
@@ -40,6 +40,17 @@ describe('modules/manager/terraform/extract', () => {
expect
(
await
extractPackageFile
(
'
nothing here
'
,
'
1.tf
'
,
{})).
toBeNull
();
expect
(
await
extractPackageFile
(
'
nothing here
'
,
'
1.tf
'
,
{})).
toBeNull
();
});
});
it
(
'
returns null for no deps
'
,
async
()
=>
{
// ModuleExtractor matches `module` at any position.
const
src
=
codeBlock
`
data "sops_file" "secrets" {
source_file = "
\$
{path.module}/secrets.enc.json"
}
`
;
expect
(
await
extractPackageFile
(
src
,
'
1.tf
'
,
{})).
toBeNull
();
});
it
(
'
extracts modules
'
,
async
()
=>
{
it
(
'
extracts modules
'
,
async
()
=>
{
const
res
=
await
extractPackageFile
(
modules
,
'
modules.tf
'
,
{});
const
res
=
await
extractPackageFile
(
modules
,
'
modules.tf
'
,
{});
expect
(
res
?.
deps
).
toHaveLength
(
18
);
expect
(
res
?.
deps
).
toHaveLength
(
18
);
...
...
This diff is collapsed.
Click to expand it.
lib/modules/manager/terraform/extract.ts
+
9
−
4
View file @
7b21f347
import
is
from
'
@sindresorhus/is
'
;
import
is
from
'
@sindresorhus/is
'
;
import
{
logger
}
from
'
../../../logger
'
;
import
{
logger
}
from
'
../../../logger
'
;
import
type
{
ExtractConfig
,
PackageFileContent
}
from
'
../types
'
;
import
type
{
ExtractConfig
,
PackageDependency
,
PackageFileContent
,
}
from
'
../types
'
;
import
type
{
DependencyExtractor
}
from
'
./base
'
;
import
{
resourceExtractors
}
from
'
./extractors
'
;
import
{
resourceExtractors
}
from
'
./extractors
'
;
import
*
as
hcl
from
'
./hcl
'
;
import
*
as
hcl
from
'
./hcl
'
;
import
{
import
{
...
@@ -15,7 +20,7 @@ export async function extractPackageFile(
...
@@ -15,7 +20,7 @@ export async function extractPackageFile(
):
Promise
<
PackageFileContent
|
null
>
{
):
Promise
<
PackageFileContent
|
null
>
{
logger
.
trace
({
content
},
`terraform.extractPackageFile(
${
packageFile
}
)`
);
logger
.
trace
({
content
},
`terraform.extractPackageFile(
${
packageFile
}
)`
);
const
passedExtractors
=
[];
const
passedExtractors
:
DependencyExtractor
[]
=
[];
for
(
const
extractor
of
resourceExtractors
)
{
for
(
const
extractor
of
resourceExtractors
)
{
if
(
checkFileContainsDependency
(
content
,
extractor
.
getCheckList
()))
{
if
(
checkFileContainsDependency
(
content
,
extractor
.
getCheckList
()))
{
passedExtractors
.
push
(
extractor
);
passedExtractors
.
push
(
extractor
);
...
@@ -36,7 +41,7 @@ export async function extractPackageFile(
...
@@ -36,7 +41,7 @@ export async function extractPackageFile(
.
toString
()}
]`
.
toString
()}
]`
);
);
const
dependencies
=
[];
const
dependencies
:
PackageDependency
[]
=
[];
const
hclMap
=
await
hcl
.
parseHCL
(
content
,
packageFile
);
const
hclMap
=
await
hcl
.
parseHCL
(
content
,
packageFile
);
if
(
is
.
nullOrUndefined
(
hclMap
))
{
if
(
is
.
nullOrUndefined
(
hclMap
))
{
logger
.
debug
({
packageFile
},
'
failed to parse HCL file
'
);
logger
.
debug
({
packageFile
},
'
failed to parse HCL file
'
);
...
@@ -51,5 +56,5 @@ export async function extractPackageFile(
...
@@ -51,5 +56,5 @@ export async function extractPackageFile(
}
}
dependencies
.
forEach
((
value
)
=>
delete
value
.
managerData
);
dependencies
.
forEach
((
value
)
=>
delete
value
.
managerData
);
return
{
deps
:
dependencies
};
return
dependencies
.
length
?
{
deps
:
dependencies
}
:
null
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment