Terraform 错误配置 AWS 提供商后端问题

Terraform error configuring AWS provider backend issue

我在后端配置的 terraform 中遇到过这个问题。 运行 Terraform 计划时出现此错误。

错误:配置 Terraform AWS Provider 时出错:找不到 Terraform AWS Provider 的有效凭证源。 │ │ 请看https://registry.terraform.io/providers/hashicorp/aws │ 有关提供凭据的更多信息。 │ │ 错误:刷新缓存凭证失败,找不到EC2 IMDS角色,操作错误ec2imds​​: GetMetadata, request send failed, Get "http://169.254.169.254/latest/meta-data/iam/security-credentials/": dial tcp 169.254.169.254:80 : i/o超时

 with provider["registry.terraform.io/hashicorp/aws"].west,

│ 在 providers.tf 第 5 行,在提供商“aws”中: │ 5: 提供商“aws”{ │ ╵

这是代码,没有 google 页面可以帮助解决这个错误。我将不胜感激任何帮助,我将永远感激不已谢谢

terraform {
  `enter code here`backend "remote" {
organization = "Gnome2"

workspaces {
  name = "terraform-begin"
}

}

required_providers {
aws = {
  source  = "hashicorp/aws"
  version = "4.8.0"
}

} }

 provider "aws" {
  region = "us-east-1"
  }

  provider "aws" {
  alias  = "west"
  region = "us-west-1"
  }
  module "vpc" {
  source = "terraform-aws-modules/vpc/aws"
  providers = {
  aws = aws.west

}

  name = "my-vpc"
  cidr = "10.0.0.0/16"

  azs             = ["us-east-1a", "us-east-1b", "us-east-1c"]
  private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
  public_subnets  = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]

  enable_nat_gateway = true
  enable_vpn_gateway = true

  tags = {
      Terraform   = "true"
      Environment = "dev"
 }

}

您可以使用 aws CLI 连接到您的 was 帐户吗?比如列出您的 AWS s3 存储桶?根据错误,我认为您没有通过在 CLI 上执行 aws configure 来配置 aws。这将要求您具有设置的访问密钥 ID 和秘密。