我使用下面的代码来配置 aws creds。
provider "aws" {
region = var.region_name
profile = "default"
}
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.76"
}
}
required_version = ">= 0.14.9"
}
每当我们运行时,我都会遇到以下错误
terraform plan
错误:
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: NoCredentialProviders: no valid providers in chain
│ caused by: EnvAccessKeyNotFound: failed to find credentials in the environment.
│ SharedCredsLoad: failed to load profile, default.
│ EC2RoleRequestError: no EC2 instance role found
│ caused by: RequestError: send request failed
│ caused by: Get "http://169.254.169.254/latest/meta-data/iam/security-credentials/": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
我尝试按照https://registry.terraform.io/providers/hashicorp/aws/latest/docs/guides/version-4-upgrade#changes-to-authentication升级我的aws提供程序版本,它开始工作如下:
provider "aws" {
region = var.region_name
profile = "default"
}
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
required_version = ">= 0.14.9"
}
如果您想使用
profile
,则需要正确设置配置文件(例如 ~/.aws/credentials 和 ~/.aws/config)。
否则您可以使用
进行设置provider "aws" {
region = "us-west-2"
access_key = "my-access-key"
secret_key = "my-secret-key"
}
并传递秘密,例如通过 terraform 云中的变量集。