繁体   English   中英

Terraform AWS | 错误:配置 Terraform AWS 提供商时出错:找不到 Terraform AWS 提供商的有效凭证源

[英]Terraform AWS | Error: error configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found

刚开始将 IntelliJ 与 AWS 一起使用,在使用 terraform apply 命令后弹出此错误,代码只是 EC2 实例的简单部署。

Error: error configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found.
│ 
│ Please see https://registry.terraform.io/providers/hashicorp/aws
│ for more information about providing credentials.
│
│ Error: failed to refresh cached credentials, no EC2 IMDS role found, operation error ec2imds: GetMetadata, request send failed, Get "http://169.254.169.2
54/latest/meta-data/iam/security-credentials/": dial tcp 169.254.169.254:80: i/o timeout
│
│
│   with provider["registry.terraform.io/hashicorp/aws"],
│   on main.tf line 1, in provider "aws":
│    1: provider "aws" {
│
╵

AWS Explorer 的凭证是正确的使用管理员组中的 IAM 用户。 Terraform 安装了 Terraform 的 IntelliJ 插件并安装了 AWS 使用 Windows 在 IntelliJ 和 AWS 之间建立了连接 10 无法在 Windows 上使用管理操作 我觉得 Terraform 和 AWS 无法连接(如错误所述),但我不明白为什么。 有什么想法可以部署这个实例吗? 任何帮助表示赞赏。 我在这里回答您可能有的任何问题。 我希望部署一个 EC2 实例。 我试过创建一个新项目,重新安装 IntelliJ,使用其他 IDE,如 VS Code。

所以我不得不跑:

$ export AWS_ACCESS_KEY_ID=(your access key id)
$ export AWS_SECRET_ACCESS_KEY=(your secret access key)

在 IntelliJ 的 Ubuntu 终端中使用我的密钥,它成功了!

或者,您可以按如下方式配置您的提供商块:

provider "aws" {
  region                  = "aws_region_to_create_resources"
  profile                 = "aws_profile_to_use"
}

或者,如果您的 aws 凭据文件位于默认 $HOME/.aws 以外的其他路径中:

provider "aws" {
  region                  = "aws_region_to_create_resources"
  shared_credentials_file = "path_to_aws_credentials_file"
  profile                 = "aws_profile_to_use"
}

指定配置文件的优点是允许您针对不同的环境使用不同的 AWS 账户。 您也可以使用该方法将同一个terraform模块中的资源通过别名部署到不同的账号或地域。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM