Skip to content

Cannot define provider functions that are dependent on the provider configuration #1093

@valentindeaconu

Description

@valentindeaconu

Module version

github.com/hashicorp/terraform-plugin-framework v1.13.0

Relevant provider source code

https://github.com/valentindeaconu/terraform-provider-func/blob/a282896fd2da6427afb2340d21f575c30cc61121/internal/provider/provider.go#L111-L202

https://github.com/valentindeaconu/terraform-provider-func/blob/a282896fd2da6427afb2340d21f575c30cc61121/internal/provider/provider.go#L226-L250

Terraform Configuration Files

terraform {
  required_providers {
    func = {
      source  = "valentindeaconu/func"
      version = "0.1.0"
    }
  }
}

provider "func" {
  library {
    source = "file://${path.module}/library.js"
  }
}

output "results" {
  value = {
    sum = provider::func::sum(10, 5) # Expected result => 15
  }
}

Debug Output

https://gist.github.com/valentindeaconu/157501a91c011f3c719baed846076802

Expected Behavior

I am expecting Terraform to initially call the provider's Configure method, so the ProviderData is initialised, then call the Functions method, to get the provider's functions. Or, at least, call the Functions twice (at least once after the Configure method), as it does for Resources and DataSources methods and leave the graceful failure handling to the provider developer.

Actual Behavior

The Functions method gets called only once, and since the Functions slice is only known after parsing the provider configuration, it is empty at the time of the call, making Terraform crash.

Steps to Reproduce

  1. terraform init
  2. terraform plan

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions