Terraform 给出错误无法加载插件架构

问题描述 投票:0回答:8

我有下面的代码,用于通过 terraform 在 aws 中创建 s3 存储桶和云前端,但 terraform 给出错误。 我正在使用适用于 Windows 的最新版本 terraform cli exe。 主要.tf 请找到 main.tf 文件的以下代码:

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
    }
}

请查看以下错误消息:

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...

请帮助解决问题,我是地形新手。 P.S. 此错误是在 terraform plan

时生成的
amazon-s3 terraform terraform-provider-aws
8个回答
15
投票

我也遇到过同样的问题。但错误有点不同。我正在关注 HashiCups 提供商示例。

当初始化无法升级或检测到损坏的缓存提供程序时,或者如果您更改了版本但仅运行

terraform init
时,它会在缓存中找到版本并决定使用它,就会发生这种情况。删除terraform目录和lock文件,然后再次init
terraform init -upgrade

如果您在 Apple M1 芯片上运行它,您可能还需要设置:

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


5
投票

使用

chmod
向提供者授予执行权限,就成功了。感谢您的文章@dpiada!

示例:

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

3
投票

我也遇到了同样的问题。

我的问题是在重新安装操作系统后产生的。 为了找到我的解决方案,我也看到了这篇文章:在此处输入链接描述

我通过以下步骤解决它

rm -rf .terraform

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

terraform 重新创建文件夹“.terraform”并更新您的 aws 提供程序插件。


2
投票

我是 terraform 的初学者,我也遇到了同样的问题,所以我希望这能有所帮助。我遇到了同样的错误“无法加载插件架构”,并且我弄乱了

.terraform.lock.hcl
.terraform
文件。 这就是我所做的

  1. 我在安装 terraform 和 aws 的路径创建了新项目,它位于“桌面”.. 不知道有没有必要
  2. 然后我创建了新的两个文件
    provider.tf
    main.tf
    然后我在终端中输入
    terraform init
    之后,它会自动生成这些文件:
    .terraform
    .terraform.lock.hcl
    我没有对它们做任何改变。然后在终端中运行
    terraform plan

这是我的

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"
}

这是

main.tf

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

您可能还会遇到以下一些其他问题: 创建

provider.tf
main.tf
之后,在终端中运行
terraform init
后,您会得到“无更改”,那么您应该在终端中运行命令之前保存文件。


1
投票

我今天遇到了类似的问题,在 terraform plan、apply 或 destroy 命令中遇到了相同的错误。 在徒劳地寻找简单的解决方案之后,我决定运行 terraform init 并解决了该错误。我能够运行 terraform destroy 来成功销毁 52 个资源。唷!


0
投票

我面临着同样的问题,对我来说问题是我从

/home
运行 terraform plan,其中分区安装点启用了“noexec”。

您可以简单地从其他地方运行您的 terraform 或从当前安装点禁用“noexec”:

vi etc/fstab
编辑并删除 noexec 标志,更改

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

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

并使用

mount -o remount /home

重新挂载 /home

希望有帮助。


0
投票

我也遇到这个问题了。我之前使用过 Terraform 的

time_static
资源(链接此处),运行了一个应用,然后不再需要它并将其从我的 Terraform 代码中删除,然后尝试运行一个计划并收到此错误。

为我解决的问题是运行

terraform state list
,在我的 Terraform 状态中找到
time_static
资源,然后在
terraform state rm
资源上找到
time_static
,然后删除我的
.terraform
目录,运行
terraform init
然后运行
terraform plan
这有效了


0
投票

通过禁用我的防火墙 ESET Internet Security 来解决这个问题。然后通过将其置于“学习模式”,运行 terraform 命令(terraform plan),然后允许弹出并想要连接的 terraform 提供程序 exe 来解决。

© www.soinside.com 2019 - 2024. All rights reserved.