I am trying to install the following provider https://github.com/marqeta/terraform-provider-dfd
Followed the installation steps . Attached the folder structure.
But getting error when trying to run terraform initFolder Structure
-> dfd-demo
-main.tf
-terraform-provider-dfd_v0.0.2
dfd-demo % terraform init
Initializing the backend...
Initializing provider plugins...
- Finding latest version of hashicorp/dfd...
╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/dfd: provider registry registry.terraform.io does not have a provider named
│ registry.terraform.io/hashicorp/dfd
│
│ 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/dfd, run the following command:
│ terraform providers
╵
dfd-demo %
Related
My problem
I am having trouble defining the provider for my module.
Terraform fails to find the provider's plugin when I run terraform init and it shows the wrong provider for my module when I run terraform providers.
Setup
I am using Terraform version 1.3.7 on Debian 11.
Here's an example of what I am trying to do.
I have a main.tf where is my main configuration and modules. In this example I use a single module for creating a docker container.
.
├── main.tf
└── modules/
└── container_module/
└── main.tf
In the root module project/main.tf file, I define the provider and call the module:
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "3.0.1"
}
}
}
provider "docker" {
host = "unix:///var/run/docker.sock"
}
module "container" {
source = "./modules/container_module"
}
In the modules/container_module/main.tf, I create the docker container resource:
resource "docker_image" "debian" {
name = "debian:latest"
}
resource "docker_container" "foo" {
image = docker_image.debian.image_id
name = "foo"
}
What I expect to happen
When I run terraform init, it should download the provider's plugin from kreuzwerker/docker.
What actually happens
Instead, terraform downloads the plugin from kreuzwerker/docker once, then attempt to download it again from hashicorp/docker.
Here's the command's output:
terraform init
Initializing modules...
- container in modules/container_module
Initializing the backend...
Initializing provider plugins...
- Finding latest version of hashicorp/docker...
- Finding kreuzwerker/docker versions matching "3.0.1"...
- Installing kreuzwerker/docker v3.0.1...
- Installed kreuzwerker/docker v3.0.1 (self-signed, key ID BD080C4571C6104C)
Partner and community providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://www.terraform.io/docs/cli/plugins/signing.html
╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/docker: provider registry registry.terraform.io does not have a provider named
│ registry.terraform.io/hashicorp/docker
│
│ Did you intend to use kreuzwerker/docker? If so, you must specify that source address in each module which requires that provider. To see which modules are currently depending on
│ hashicorp/docker, run the following command:
│ terraform providers
╵
When I run terraform providers I get two different sources depending on the file:
terraform providers
Providers required by configuration:
.
├── provider[registry.terraform.io/kreuzwerker/docker] 3.0.1
└── module.container
└── provider[registry.terraform.io/hashicorp/docker]
According to the documentation, the child modules should inherit the provider from their parent:
Default Behavior: Inherit Default Providers:
If the child module does not declare any configuration aliases, the providers argument is optional. If you omit it, a child module inherits all of the default provider configurations from its parent module. (Default provider configurations are ones that don't use the alias argument.)
I have already checked this
Do terraform modules need required_providers?
This answer confirms the provider inheritence.
Terraform provider's resources not available in other tf files:
This question didn't help.
Terraform, providers miss inherits on module
This answer to this similar question says that I should add required_providers in the child module, but it is for an older version and it contradicts what I saw elsewhere.
I have the same issue when I create a providers.tf file in the root directory.
My question
How should I declare my provider so that the child module can inherit the provider from the root module?
kreuzwerker/docker is not a hashicorp provider. Thus as explained here, you have to explicitly define required_providers in each module, as such providers are not inherited.
I downloaded Terraform recently and now I'm trying to practice on my local machine, hence the need for me to use the hashicorp/local as provider. However, after creating a simple local.tf file in my terraform-local-file directory and running terraform init as root, I get an error.
This is my local.tf file.
resource "local_file" "love" {
filename="/root/love.txt"
content="I love Jesus Christ, because He first loved me."
}
terraform {
required_providers {
local = {
source = "hashicorp/local"
version = "2.3.0"
}
}
required_version = ">= 1.1.0"
}
This is the error I got:
root#OZIRICHIGO41022-wsl:~/terraform-local-file# terraform init
Initializing the backend...
Initializing provider plugins...
- Finding latest version of hashicorp/local...
╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider
│ hashicorp/local: could not connect to registry.terraform.io: Failed to request
│ discovery document: Get
│ "https://registry.terraform.io/.well-known/terraform.json": dial tcp: lookup
│ registry.terraform.io on 172.25.48.1:53: read udp
│ 172.25.53.6:53112->172.25.48.1:53: i/o timeout
Now, I have tried getting answers from Hashicorp's website, but I could not fully understand how to implement the suggested solutions provided there. So please let your answer be beginner-friendly because I'm just starting to learn Terraform and quite new to tech altogether. I'll appreciate any help I can get. Thanks!
I have written below backend configuration in terraform:
terraform {
backend "s3" {
bucket = "${var.application_name}"
region = "${var.AWS_REGION}"
key = "tf-scripts/${var.application_name}-tfstate"
}
}
while running terraform init, I am getting below error message:
terraform init
Initializing the backend...
╷
│ Error: Variables not allowed
│
│ on backend.tf line 4, in terraform:
│ 4: bucket = "${var.application_name}"
│
│ Variables may not be used here.
╵
╷
│ Error: Variables not allowed
│
│ on backend.tf line 5, in terraform:
│ 5: region = "${var.AWS_REGION}"
│
│ Variables may not be used here.
╵
╷
│ Error: Variables not allowed
│
│ on backend.tf line 6, in terraform:
│ 6: key = "tf-scripts/${var.application_name}-tfstate"
│
│ Variables may not be used here.
Can anyone assist me on achieving the same?
If you want to pass variables you could do something like this:
echo "yes" | terraform init -backend-config="${backend_env}" -backend-config="key=global/state/${backend_config}/terraform.tfstate" -backend-config="region=us-east-1" -backend-config="encrypt=true" -backend-config="kms_key_id=${kmykeyid}" -backend-config="dynamodb_table=iha-test-platform-db-${backend_config}"
Now the trick here is that when you initialize it has to be done at the command line level. Terraform can not do this as mentioned already by other community members, it's just the way it is. that said you can modify the commands for initializing and pass it through as environment variables on your host or pull in variables from another source.
in this example, I declared the variables using a container through AWS Codebuild but you can use any method as long as the variable is defined prior to initialization. Let me know if you need help with this, the documentation isn't very clear and the folks on StackOverflow have been amazing at addressing this but for beginners, it's been hard to understand how this all comes together.
terraform v1.0.3 installed via brew on Mac OS
It's my first time using Terraform with a "vshpere" provider. When I do a terraform init on my plan, I get the following error.
provider "vsphere" {
user = var.vsphere_user
password = var.vsphere_password
vsphere_server = var.vsphere_server
}
module "exa_v30_01" {
source = "../modules/vm"
vsphere_user = var.vsphere_user
vsphere_password = var.vsphere_password
template_name = var.template_name
vm_name = var.vm_name
}
$ terraform init
Initializing modules...
Initializing the backend...
Initializing provider plugins...
- Finding latest version of hashicorp/vsphere...
- Finding latest version of hashicorp/vmsphere...
- Installing hashicorp/vsphere v2.0.2...
- Installed hashicorp/vsphere v2.0.2 (signed by HashiCorp)
╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider
│ hashicorp/vmsphere: provider registry registry.terraform.io does
│ not have a provider named registry.terraform.io/hashicorp/vmsphere
│
│ 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/vmsphere, run the following command:
│ terraform providers
╵
$ terraform providers
Providers required by configuration:
.
├── provider[registry.terraform.io/hashicorp/vsphere]
└── module.exa_v30_01
├── provider[registry.terraform.io/hashicorp/vsphere]
└── provider[registry.terraform.io/hashicorp/vmsphere]
How do I solve this? I googled and searched here, but nothing relating to VSphpere. Any clues? Thanks
UPDATE:
I see Force Terraform to install providers from local disk only, disabling Terraform Registry, but that's for a terraform version upgrade.
The error message is correct. There is not provider called vmsphere. Maybe you wanted vsphere provider? Your module exa_v30_01 seems to be using wrong providers somewhere.
I'm trying to upgrade from terraform 0.12 to 0.13.
it seems to have no specific problem of syntax when I run terraform 0.13upgrade nothing is changed.
only a file version.tf is added
+terraform {
+ required_providers {
+ aws = {
+ source = "hashicorp/aws"
+ }
+ }
+ required_version = ">= 0.13"
+}
and when I run terraform plan I got
Error: Could not load plugin
Plugin reinitialization required. Please run "terraform init".
Plugins are external binaries that Terraform uses to access and manipulate
resources. The configuration provided requires plugins which can't be located,
don't satisfy the version constraints, or are otherwise incompatible.
Terraform automatically discovers provider requirements from your
configuration, including providers used in child modules. To see the
requirements and constraints, run "terraform providers".
2 problems:
- Failed to instantiate provider "registry.terraform.io/-/aws" to obtain
schema: unknown provider "registry.terraform.io/-/aws"
- Failed to instantiate provider "registry.terraform.io/-/template" to obtain
schema: unknown provider "registry.terraform.io/-/template"
running terraform providers shows
Providers required by configuration:
.
├── provider[registry.terraform.io/hashicorp/aws]
├── module.bastion
│ ├── provider[registry.terraform.io/hashicorp/template]
│ └── provider[registry.terraform.io/hashicorp/aws]
└── module.vpc
└── provider[registry.terraform.io/hashicorp/aws] >= 2.68.*
Providers required by state:
provider[registry.terraform.io/-/aws]
provider[registry.terraform.io/-/template]
So my guess is form some reason I have -/aws instead of hashicorp/aws in my tfstate, however I can't find this specific string at all in the tfstate.
I tried:
running terraform init
terraform init -reconfigure
deleting the .terraform folder
deleting the ~/.terraform.d folder
So I'm running out of ideas on how to solve this problem
I followed the steps here
terraform state replace-provider registry.terraform.io/-/template registry.terraform.io/hashicorp/template
terraform state replace-provider registry.terraform.io/-/aws registry.terraform.io/hashicorp/aws
and it fixed my problem.