microset
microset

Reputation: 398

Terraform Gives errors Failed to load plugin schemas

I have below code which I am using for create s3 bucket and cloud front in aws through terraform but terraform gives error. I am using latest version of terraform cli exe for windows. Main.tf Please find below code of main.tf file :

terraform {
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "3.70.0"
    }
  }
}

provider "aws" {
    access_key = "${var.aws_access_key}"
    secret_key = "${var.aws_secret_key}"
    region = "${var.aws_region}"
}

resource "aws_s3_bucket" "mybucket" {
    bucket = "${var.bucket_name}"
    acl = "public-read"

    website {
        redirect_all_requests_to = "index.html"
    }

    cors_rule {
        allowed_headers = ["*"]
        allowed_methods = ["PUT","POST"]
        allowed_origins = ["*"]
        expose_headers = ["ETag"]
        max_age_seconds = 3000
    }

    policy = <<EOF
{
    "Version": "2008-10-17",
    "Statement": [
        {
            "Sid": "PublicReadForGetBucketObjects",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::${var.bucket_name}/*"
        }
    ]
}
EOF
}

resource "aws_cloudfront_distribution" "distribution" {
    origin {
        domain_name = "${aws_s3_bucket.mybucket.website_endpoint}"
        origin_id   = "S3-${aws_s3_bucket.mybucket.bucket}"

        custom_origin_config  {
            http_port = 80
            https_port = 443
            origin_protocol_policy = "match-viewer"
            origin_ssl_protocols = ["TLSv1", "TLSv1.1", "TLSv1.2"]
        }
    }
    default_root_object = "index.html"
    enabled             = true

    custom_error_response {
        error_caching_min_ttl = 3000
        error_code            = 404
        response_code         = 200
        response_page_path    = "/index.html"
    }

    default_cache_behavior {
        allowed_methods  = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
        cached_methods   = ["GET", "HEAD"]
        target_origin_id = "S3-${aws_s3_bucket.mybucket.bucket}"

        forwarded_values {
            query_string = true

            cookies {
                forward = "none"
            }
      }

        viewer_protocol_policy = "allow-all"
        min_ttl                = 0
        default_ttl            = 3600
        max_ttl                = 86400
    }

    # Restricts who is able to access this content
    restrictions {
        geo_restriction {
            # type of restriction, blacklist, whitelist or none
            restriction_type = "none"
        }
    }

    # SSL certificate for the service.
    viewer_certificate {
        cloudfront_default_certificate = true
    }
}

Please find below error message:

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/aws: failed to retrieve schema
│ from provider "registry.terraform.io/hashicorp/aws": Plugin did not respond: The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).GetProviderSchema call. The
│ plugin logs may contain more details...

Please help to resolve the issue , I'm new in terraforms. P.S. This error generated while terraform plan

Upvotes: 11

Views: 48983

Answers (8)

Paintoshi
Paintoshi

Reputation: 986

Worked around it by disabling my firewall, ESET Internet Security. Then solved by putting it into "learning mode", run a terraform command (terraform plan) and then allowing the terraform provider exe that popped up and wanted to connect.

Upvotes: 0

Wally_E
Wally_E

Reputation: 63

Using chmod to grant exec permissions to the providers, did the trick. Thank you for the article @dpiada!

Example:

chmod +x .terraform/providers/registry.terraform.io/hashicorp/local/2.4.0/linux_amd64/terraform-provider-local_v2.4.0_x5
chmod +x .terraform/providers/registry.terraform.io/hashicorp/azurerm/3.55.0/linux_amd64/terraform-provider-azurerm_v3.55.0_x5

Upvotes: 6

dpiada
dpiada

Reputation: 51

I had the same problem.

My problem was generated after re-install OS. To arrive my solution I saw this article too: enter link description here

I resolve it with following steps

rm -rf .terraform

terraform init -backend-config="profile=##your_aws_profile"

terraform recreates folder `.terraform' and update your aws provider plugin.

Upvotes: 4

blim747
blim747

Reputation: 81

I also got this issue too. I previously used Terraform's time_static resource (link here), ran an apply, then no longer needed it and removed it from my Terraform code, then tried to run a plan and got this error.

What fixed it for me was running terraform state list, finding the time_static resource in my Terraform state, then terraform state rm on the time_static resource, then deleted my .terraform directory, ran terraform init then terraform plan and this worked

Upvotes: 0

Iammathh
Iammathh

Reputation: 1

I was facing the same problem and for me the issue was that I was running terraform plan from /home where the partition mount point had "noexec" enabled.

You can simply run your terraform from somewhere else or disable the "noexec" from current mount point:

vi etc/fstab to edit and remove the noexec flag, change

/dev/mapper/VG00-LVhome /home ext4 defaults,noexec,nosuid

To

/dev/mapper/VG00-LVhome /home ext4 defaults,nosuid

And remount /home with mount -o remount /home

I hope it helps.

Upvotes: 0

deleonab
deleonab

Reputation: 11

I had a similar problem today, where I was getting the same error with terraform plan, apply or destroy commands. After looking for easy solutions in vain, I decided to run terraform init and it solved the error. I was able to run terraform destroy to successfully destroy 52 resources. Phew!

Upvotes: 1

Yusuf Amr
Yusuf Amr

Reputation: 587

I'm a beginner at terraform and I had same problem, so I hope this can help. I had same error "Failed to load plugin schemas" and I made a mess with .terraform.lock.hcl .terraform files. Here's what I did

  1. I created new project at the path where I installed terraform and aws, and it was at “desktop” .. I don't know if that was necessary or not.
  2. Then I created new two files provider.tf, and main.tf then I typed in terminal terraform init after that, it will automatically generate those files: .terraform .terraform.lock.hcl and I didn't change something on them. then run terraform plan in terminal.

here's my provider.tf

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
    }
  }
}

provider "aws" {
  region = "us-east-1"
  shared_config_files      = ["~/.aws/config"]
  shared_credentials_files = ["~/.aws/credentials"]
  profile                  = "terraform-user"
}

and here's main.tf

resource "aws_vpc" "vpc" {
    cidr_block = "10.123.0.0/16"
    enable_dns_hostnames = true
    enable_dns_support = true
    tags = {
        Name = "vpc"
    }
}
 

here's some other problems you may face too: after you create provider.tf and main.tf then after running terraform init in terminal you get "no change", then you should save files before you run the commands in terminal.

Upvotes: 2

Aniket Kariya
Aniket Kariya

Reputation: 1960

I had faced the same issue. The error was a little different tho. I was following the HashiCups provider example.

It happens when initializing it fails to upgrade or detect corrupt cached providers, or if you have changed the version but when you only run terraform init it finds the version in cache and decides to go with it. Delete the terraform directory and lock file, and then init again terraform init -upgrade

If you're on running it on Apple M1 chip, you might as well need to set this:

export GODEBUG=asyncpreemptoff=1;

https://discuss.hashicorp.com/t/terraform-aws-provider-panic-plugin-did-not-respond/23396 https://github.com/hashicorp/terraform/issues/26104

Upvotes: 25

Related Questions