Terraform use local provider/plugin

Hi,
I installed Terraform v1.0.1 on linux_amd64 (Oracle Linux Srv 8.4 64bit).

I’m trying to use a local provider/plugin that I saved in the folder: /root/.terraform.d/plugins

This is my main.tf:

terraform {
    required_version    = ">= 0.12.6"
}
provider "zabbix" {
    username            = local.provider_vars.zabbix.username
    password            = local.provider_vars.zabbix.password
    url                 = local.provider_vars.zabbix.endpoint
    tls_insecure        = true
}

but when I run: terraform init
I receive this error:

Initializing the backend…

Initializing provider plugins…

  • Finding latest version of hashicorp/zabbix…

    │ Error: Failed to query available provider packages

    │ Could not retrieve the list of available versions for provider hashicorp/zabbix: provider registry
    registry.terraform.io does not have a provider named registry.terraform.io/hashicorp/zabbix

    │ All modules should specify their required_providers so that external consumers will get the correct providers when
    │ using a module. To see which modules are currently depending on hashicorp/zabbix, run the following command:
    │ terraform providers

The system try to download the provider/plugin from registry.terraform.io/hashicorp/zabbix and not load from the local folder.

How can fix this problem?
Thanks for the help

Marco

Hey there, are you logged into linux machine as root user?

If you look at the documentation here Provider Requirements - Configuration Language - Terraform by HashiCorp it needs to be under ~/.terraform.d/registry.terraform.io/hashicorp/zabbix
Note that registry.terraform.io is the directory, unless you declare your provider under terraform block with some different path like:

terraform {
      required_providers {
    zabbix = {
      source  = "some_path/zabbix"
      version = ">= 1.0"
    }
  }
}
1 Like

Hi,
thanks for your reply.

I tryed to create a folder: ~/.terraform.d/registry.terraform.io/hashicorp/zabbix and copy into the zabbix folder my plugin, but I received the same error (I commented my .terraformrc).

If I try to modify my main.ft file as below:

terraform {
    required_providers {
    zabbix = {
      source  = "/root/.terraform.d/registry.terraform.io/hashicorp/zabbix"
      version = ">= 1.0"
    }
  }
    required_version    = ">= 0.12.6"
}

provider "zabbix" {
    username            = local.provider_vars.zabbix.username
    password            = local.provider_vars.zabbix.password
    url                 = local.provider_vars.zabbix.endpoint
    tls_insecure        = true
}

I receive the error:

There are some problems with the configuration, described below.

The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.

│ Error: Invalid provider source string

│ on main.tf line 4, in terraform:
│ 4: source = “/root/.terraform.d/registry.terraform.io/hashicorp/zabbix”

│ The “source” attribute must be in the format “[hostname/][namespace/]name”

I do not have a local provider, but I can try repro this in my local machine. is zabbix available for download from somewhere?
else I shall try something else.

for me aws provider is available here manage_aws_organizations/.terraform/providers/registry.terraform.io/hashicorp/aws/3.47.0/linux_amd64/terraform-provider-aws_v3.47.0_x5

1 Like

Hi,
I solved!

I copied my plugin into:

~/.terraform.d/plugins/terraform.local/local/zabbix/1.0.0/linux_amd64/terraform-provider-zabbix_v1.0.0

Add these into may terraform code:

terraform {
  required_providers {
    zabbix = {
      source  = "terraform.local/local/zabbix"
      version = "1.0.0"
      # Other parameters...
    }
  }
}
1 Like