Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions opentofu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ OpenTofu support for [`dependabot-core`][core-repo].
[dependabot-core-dev] ~ $ cd opentofu && rspec
```

3. Run against an existing repo:
```
bin/dry-run.rb opentofu diofeher/dependabot-example --dep="specific-dependency"
```

### Configuration

To enable OpenTofu support, add to your `dependabot.yml`:
Expand Down
11 changes: 10 additions & 1 deletion opentofu/lib/dependabot/opentofu/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def ecosystem
private

# rubocop:disable Metrics/PerceivedComplexity
# rubocop:disable Metrics/MethodLength
sig { params(dependency_set: Dependabot::FileParsers::Base::DependencySet).void }
def parse_opentofu_files(dependency_set)
opentofu_files.each do |file|
Expand Down Expand Up @@ -93,12 +94,20 @@ def parse_opentofu_files(dependency_set)
required_providers = opentofu.fetch("required_providers", {})
required_providers.each do |provider|
provider.each do |name, details|
dependency_set << build_provider_dependency(file, name, details)
Dependabot.logger.info("Building provider dependency for #{name} in #{file.name}")
dep = build_provider_dependency(file, name, details)
if dep.name == "builtin/terraform"
Dependabot.logger.info("Skipping builtin/terraform provider as it's not possible to update it")
next
end

dependency_set << dep
end
end
end
end
end
# rubocop:enable Metrics/MethodLength

sig { params(dependency_set: Dependabot::FileParsers::Base::DependencySet).void }
def parse_terragrunt_files(dependency_set)
Expand Down
23 changes: 23 additions & 0 deletions opentofu/spec/dependabot/opentofu/file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,29 @@
end
end

context "with a terraform.io/builtin/terraform provider" do
let(:files) { project_dependency_files("provider_with_builtin_terraform") }

it "skips the builtin/terraform provider" do
expect(dependencies.length).to eq(2)
# Should not include builtin/terraform provider
expect(dependencies.find { |d| d.name == "builtin/terraform" }).to be_nil
# Should include other providers
expect(dependencies.find { |d| d.name == "hashicorp/http" }).not_to be_nil
expect(dependencies.find { |d| d.name == "hashicorp/aws" }).not_to be_nil
end

it "parses other providers correctly" do
http_provider = dependencies.find { |d| d.name == "hashicorp/http" }
expect(http_provider.version).to eq("2.1.0")
expect(http_provider.requirements.first[:requirement]).to eq("~> 2.0")

aws_provider = dependencies.find { |d| d.name == "hashicorp/aws" }
expect(aws_provider.version).to eq("3.37.0")
expect(aws_provider.requirements.first[:requirement]).to eq("3.37.0")
end
end

context "with a private module with directory suffix" do
let(:files) { project_dependency_files("private_module_with_dir_suffix") }

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
terraform {
required_version = ">= 1.0"

required_providers {
terraform = {
source = "terraform.io/builtin/terraform"
}

http = {
source = "hashicorp/http"
version = "~> 2.0"
}

aws = {
source = "hashicorp/aws"
version = "3.37.0"
}
}
}

provider "aws" {
region = "eu-west-1"
}

Loading