I have a working terraform script which I would like to add a null_resource local_exec command to. But when I do, it fails. Here's the block:
resource "null_resource" "es_lincoln" {
provisioner "local-exec" {
command = "echo $(pwd) > somefile.txt"
}
}
and when I uncomment it and try to execute a plan
I get this error:
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".
Failed to instantiate provider "registry.terraform.io/hashicorp/null" to
obtain schema: unknown provider "registry.terraform.io/hashicorp/null"
After googling for a while, I can't seem to find anyone else with this problem. Why is my Terraform attempting to match "null_resource" with a provider when it should just run its local-exec provisioner?
terraform init
is required if you change provider requirements or modules change.
Providers are required for each resource type, in this case null_resource
requires the null
provider.
If you change your code in such a way that a new provider is required, as in this case you uncommented your resource to make it active, then terraform init
is required to run again. You can see the changes in the .terraform
directory in the terraform script directory.
It should be noted that if you add a second null_resource
, you would not have to re-run terraform init
again. -- unless you add a module ;-)