terragrunt icon indicating copy to clipboard operation
terragrunt copied to clipboard

Terragrunt run-all show fails with "Failed to load plugin schemas"

Open svg1007 opened this issue 1 year ago • 10 comments

There is a strange behaviour (which looks like a bug), when terragrunt run-all show is trying to build the plan from the plan-file.

It's better to describe it on an example.

Let's assume we have a directory with multiple sub-directories inside, each one of them has terragrunt.hcl file.

ec2-instance/
  terragrunt.hcl
s3-bucket/
  terragrunt.hcl

But there, for the terragrunt.hcl in ec2-instance, we have a dependency block to s3-bucket.

After we will run terragrunt run-all plan -out /tmp/aws/myplan.tfpl , it will split the resources to 2 groups

Group 1
- Module /tmp/aws/s3-bucket

Group 2
- Module /tmp/aws/ec2-instance

Then it will download the required providers, and store them into each sub-directory.

s3-bucket/.terragrunt-cache/.../.terraform/providers/aws

ec2-instance/.terragrunt-cache/.../.terraform/providers/aws
ec2-instance/.terragrunt-cache/.../.terraform/providers/tls

In the result we will get the terragrunt plan output in the file myplan.tfpl.

Then we will run terragrunt run-all show /tmp/aws/myplan.tfpl to see the plan result. But it's failing unexpectedly with the error

╷
│ Error: Failed to load plugin schemas
│
│ Error while loading schemas for plugin components: Failed to obtain
│ provider schema: Could not load the schema for provider
│ registry.terraform.io/hashicorp/tls: failed to instantiate provider
│ "registry.terraform.io/hashicorp/tls" to obtain schema: unavailable
│ provider "registry.terraform.io/hashicorp/tls"..
╵
ERRO[0003] Terraform invocation failed in /tmp/aws/s3-bucket/.terragrunt-cache/LwR31ubKpGoz7AFuBPWxzPDAqL0/m7CKj5XpzJpoBHG2ClWcVRqe5Qk/my-s3  prefix=[/tmp/aws/s3-bucket]
ERRO[0003] Module /tmp/aws/s3-bucket has finished with an error: 1 error occurred:
	* [/tmp/aws/s3-bucket/.terragrunt-cache/LwR31ubKpGoz7AFuBPWxzPDAqL0/m7CKj5XpzJpoBHG2ClWcVRqe5Qk/my-s3] exit status 1
  prefix=[/tmp/aws/s3-bucket]

And here is the strange thing: hashicorp/tls provider is not required for the using s3-module, while it is required for the ec2-instance-module, which is in the 2nd group.

It seems like the plan is including all required providers and to read that by terragrunt show, it will read the whole plan file but, first, from the 1st group directory, and then - from the 2nd. Due of the 1st group directory does not contain the tls-provider, which is not required there, terragrunt returns error.

The expected behavior here is that the command terragrunt run-all show returns the output properly.

Versions

  • Terragrunt version: v0.48.0
  • Terraform version: v1.5.2
  • Environment details: MacOS Ventura (13.4.1), Apple M1 Pro

svg1007 avatar Jul 31 '23 09:07 svg1007

Hello, can be attached example code/repository where this issue occurs?

denis256 avatar Jul 31 '23 19:07 denis256

I need some time to prepare the code (the currently using I cannot share by some reasons).

svg1007 avatar Aug 03 '23 09:08 svg1007

Take a look please - I prepared the example code in this repo https://github.com/svg1007/for-github-terragrunt-show

svg1007 avatar Aug 07 '23 07:08 svg1007

Hello, on the shared repository and following commands from the readme, I get same error I noticed that is used run-all and the absolute path to plan file which usually leads to errors

I wold say to use relative path to plan files, bellow commands run fine:

terragrunt run-all plan -out plan.tfplan --terragrunt-non-interactive
terragrunt run-all show plan.tfplan --terragrunt-non-interactive

denis256 avatar Aug 08 '23 09:08 denis256

oh, I didn't know about that problem with run-all to be honest. This workaround works!

svg1007 avatar Aug 08 '23 12:08 svg1007

@denis256 , you mentioned that the absolute path to plan usually leads to errors... Is there an issue for that?

svg1007 avatar Aug 08 '23 12:08 svg1007

I've noticed the same strange behavior when run-all show fails usually every other launch with the following error. Removing this step from the GitLab pipeline has fixed the issue:

    - terragrunt run-all plan -out=${TG_ROOT}/plan.cache 
    - terragrunt run-all show ${TG_ROOT}/plan.cache
╷
│ Error: Failed to load plugin schemas
│ 
│ Error while loading schemas for plugin components: Failed to obtain
│ provider schema: Could not load the schema for provider
│ registry.terraform.io/hashicorp/random: failed to instantiate provider
│ "registry.terraform.io/hashicorp/random" to obtain schema: unavailable
│ provider "registry.terraform.io/hashicorp/random"..
╵

pavleec avatar Nov 16 '23 12:11 pavleec

I'm having the same issue when using the absolute path to the plan, is there any fix?

Maqui-LP avatar Jan 22 '24 17:01 Maqui-LP

Hm, if set absolute path, then different terraform instances will try to write in the same plan file... not sure if the result plan will be useful when it has changes from different directories

denis256 avatar Jan 22 '24 18:01 denis256