Terraform - 与环境关联的实例配置文件不存在
Terraform - The instance profile associated with the environment does not exist
我正在尝试创建 Elastic Beanstalk 应用程序,但我遇到了错误:
与环境关联的实例配置文件 iam_for_beanstalk 不存在。
如您在此处所见,该角色确实存在:
它是通过 Terraform 通过以下代码创建的:
resource "aws_iam_role" "beanstalk" {
name = "iam_for_beanstalk"
assume_role_policy = file("${path.module}/assumerole.json")
}
assumerole.json 看起来像这样:
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {
"Service": "elasticbeanstalk.amazonaws.com"
},
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": {
"sts:ExternalId": "elasticbeanstalk"
}
}
}]
}
下面是我尝试将其关联到新创建的应用程序的方式:
resource "aws_elastic_beanstalk_environment" "nodejs" {
application = aws_elastic_beanstalk_application.nodejs.name
name = "Whosebug"
version_label = var.app_version
solution_stack_name = "64bit Amazon Linux 2 v5.4.6 running Node.js 14"
setting {
namespace = "aws:autoscaling:launchconfiguration"
name = "IamInstanceProfile"
value = "iam_for_beanstalk"
}...
我也尝试过如下分配名称,但没有成功:
value = aws_iam_role.beanstalk.name
您还需要创建一个 aws_iam_instance_profile
资源:
resource "aws_iam_instance_profile" "beanstalk_instance_profile" {
name = "stack-overflow-example"
role = aws_iam_role.beanstalk.name
}
我正在尝试创建 Elastic Beanstalk 应用程序,但我遇到了错误:
与环境关联的实例配置文件 iam_for_beanstalk 不存在。
如您在此处所见,该角色确实存在:
它是通过 Terraform 通过以下代码创建的:
resource "aws_iam_role" "beanstalk" {
name = "iam_for_beanstalk"
assume_role_policy = file("${path.module}/assumerole.json")
}
assumerole.json 看起来像这样:
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {
"Service": "elasticbeanstalk.amazonaws.com"
},
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": {
"sts:ExternalId": "elasticbeanstalk"
}
}
}]
}
下面是我尝试将其关联到新创建的应用程序的方式:
resource "aws_elastic_beanstalk_environment" "nodejs" {
application = aws_elastic_beanstalk_application.nodejs.name
name = "Whosebug"
version_label = var.app_version
solution_stack_name = "64bit Amazon Linux 2 v5.4.6 running Node.js 14"
setting {
namespace = "aws:autoscaling:launchconfiguration"
name = "IamInstanceProfile"
value = "iam_for_beanstalk"
}...
我也尝试过如下分配名称,但没有成功:
value = aws_iam_role.beanstalk.name
您还需要创建一个 aws_iam_instance_profile
资源:
resource "aws_iam_instance_profile" "beanstalk_instance_profile" {
name = "stack-overflow-example"
role = aws_iam_role.beanstalk.name
}