Skip to content

Introduce dynamic provider sources#38405

Open
matejrisek wants to merge 13 commits into
mainfrom
matejrisek/providers/dynamic_sources
Open

Introduce dynamic provider sources#38405
matejrisek wants to merge 13 commits into
mainfrom
matejrisek/providers/dynamic_sources

Conversation

@matejrisek
Copy link
Copy Markdown
Member

@matejrisek matejrisek commented Apr 20, 2026

Introduce dynamic provider source and version - meaning we can now specify variables for required provider` sources and versions.

Example of what should be possible with these changes:

terraform {
  required_providers {
    tfcoremock = {
      source  = "${var.tfcoremock_src}"
      version = "${var.tfcoremock_ver}"
    }
  }
}

variable "tfcoremock_src" {
  type = string
  const = true
}

variable "tfcoremock_ver" {
  type = string
  const = true
}

Potential future improvements:

  • We might get rid of the "legacy" string only resolution and treat everything as an expression to get rid of the old codepath. The reason we don't do it here is because there's a lot of tests failing that need to be changed for that. Not to cause more noise in this already sizable PR I decided not to include those changes here. Also we reduce blast radius by keeping the old behavior in case unforeseen issues occur in the new codepath.

Target Release

1.16.x

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

@matejrisek matejrisek changed the title Matejrisek/providers/dynamic sources Introduce dynamic provider sources Apr 21, 2026
@matejrisek matejrisek marked this pull request as ready for review April 23, 2026 10:20
@matejrisek matejrisek requested a review from a team as a code owner April 23, 2026 10:20
@matejrisek matejrisek requested review from dbanck and jbardin April 23, 2026 10:21
@lucasew
Copy link
Copy Markdown

lucasew commented May 10, 2026

Or you could just use dependency injection on modules perhaps? Having versions static there is useful for stuff like Renovate to work well.

matejrisek added 11 commits May 28, 2026 15:44
This type will hold expressions found in the source and version
variables of the required provider block.
If it encounters an expression holding a variable - the function will
now store that expression in the map that is part of the return contract
for the function.
Ignore the newly added map to make things compile.
Add tests later.
@dbanck dbanck force-pushed the matejrisek/providers/dynamic_sources branch from 156e929 to eb015e9 Compare May 28, 2026 13:44
dbanck added 2 commits May 28, 2026 16:10
"github.com/zclconf/go-cty/cty"
)

type nodeResolveProviderRequirements struct {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this node should also implement a Name() method

//
// Skip the "legacy" pure string resolution of the version
// attribute.
if vars := kv.Value.Variables(); len(vars) > 0 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in the long run we always want to capture the expression and get rid of the "legacy" path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants