Skip to content

Commit

Permalink
Merge pull request dependabot#3930 from dependabot/feelepxyz/handle-u…
Browse files Browse the repository at this point in the history
…nknown-dep

Terraform: handle dependencies without a namespace
  • Loading branch information
feelepxyz authored Jun 17, 2021
2 parents b3ebaf1 + ea63e01 commit dadd9bb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
10 changes: 4 additions & 6 deletions terraform/lib/dependabot/terraform/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,11 @@ def source_from(details_hash)
end

def provider_source_from(source_address, name)
return [DEFAULT_REGISTRY, DEFAULT_NAMESPACE, name] unless source_address

matches = source_address.match(PROVIDER_SOURCE_ADDRESS)
matches = source_address&.match(PROVIDER_SOURCE_ADDRESS)
[
matches[:hostname] || DEFAULT_REGISTRY,
matches[:namespace],
matches[:name] || name
matches.try(:[], :hostname) || DEFAULT_REGISTRY,
matches.try(:[], :namespace) || DEFAULT_NAMESPACE,
matches.try(:[], :name) || name
]
end

Expand Down
11 changes: 11 additions & 0 deletions terraform/spec/dependabot/terraform/file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -647,5 +647,16 @@
expect(dependencies.count).to eq(0)
end
end

context "with a provider that doesn't have a namespace provider" do
let(:files) { project_dependency_files("provider_no_namespace") }

it "has the right details" do
dependency = dependencies.find { |d| d.name == "hashicorp/random" }

expect(dependency.version).to eq("2.2.1")
expect(dependency.requirements.first[:source][:module_identifier]).to eq("hashicorp/random")
end
end
end
end
14 changes: 14 additions & 0 deletions terraform/spec/fixtures/projects/provider_no_namespace/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
required_version = ">= 0.13.0"

required_providers {
cloudfoundry = {
source = "cloudfoundry-community/cloudfoundry"
version = ">= 0.14.2"
}
random = {
source = "random"
version = "2.2.1"
}
}
}

0 comments on commit dadd9bb

Please sign in to comment.