【发布时间】:2023-01-19 03:59:54
【问题描述】:
我正在尝试创建 Terraform 文档中提到的 EC2 实例。
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
}
provider "aws" {
access_key = "Acxxxxxxxxxxxxxxxxx"
secret_key = "UxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxO"
region = "ap-south-1"
}
resource "aws_instance" "app_server" {
ami = "ami-076e3a557efe1aa9c"
instance_type = "t2.micro"
tags = {
Name = "ExampleAppServerInstance"
}
}
但面临问题配置 Terraform AWS Provider 时出错:加载配置:凭证类型 source_profile 配置文件默认.
我尝试导出 cmd 并配置默认配置文件,但对我没有任何作用。
我在这里做错了什么?
【问题讨论】:
-
请不要将代码或错误作为屏幕截图发布,而是使用格式正确的代码块。
-
您使用的 Terraform 版本是什么?
-
还要检查 aws cli 是否正常工作。尝试运行“aws s3 ls”。或者与 aws ec2 相关的 aws cli 命令。
-
如果您之前的配置不起作用,我建议您删除
.terraform目录并再次运行terraform init。此外,您是否在代码中的任何位置定义了带有required_providers的terraform块? -
虽然这看起来确实是正确的配置,但我建议不要在 terraform 中配置凭据。考虑让 Terraform 期望环境已经具有所需的访问权限。也就是说,在共享配置中设置您的配置,然后在运行 terraform
export AWS_PROFILE=some-profile之前。
标签: terraform devops terraform-provider-aws aws-devops