Terraform 错误 EntityAlreadyExists:名为 iam_for_lambda 的角色已存在 [英] Terraform error EntityAlreadyExists: Role with name iam_for_lambda already exists
问题描述
运行命令terraform apply
时出现以下错误,因为角色已经存在.
When running the command terraform apply
the following error occurred because the role already exists.
Error: Error creating IAM Role iam_for_lambda: EntityAlreadyExists: Role with name iam_for_lambda already exists.
status code: 409, request id: 204c6c00-0b1d-4fb9-bf9c-fca48c67d669
on main.tf line 1, in resource "aws_iam_role" "iam_for_lambda":
1: resource "aws_iam_role" "iam_for_lambda" {
我可以使用条件/技巧来检查角色是否已经存在?
can I use conditions/tricks to check without error if the role already exists?
推荐答案
我猜你自己解决了这个问题,因为这个问题已经存在一年了,但如果资源出于正当理由存在,你可以让你的代码使用通过导入所有权:
I'm guessing you worked this out yourself, since the question is a year old, but if the resource exists for legitimate reasons, you can have your code take ownership by importing it:
terraform import aws_iam_role.iam_for_lambda iam_for_lambda
现在,当你运行 Terraform 时,它会认为它已经创建了资源,如果你更新你的代码,rolle 也会得到更新.
Now, when you run Terraform, it will think it already created the resource, and if you update your code, the rolle gets the updates too.
话虽如此,您可能不应该尝试创建一个已经存在的角色.即使您使用 terraform import
来获取资源的所有权,如果您的代码正在修改也属于另一个模块的角色,您可能会得到奇怪的结果.
That being said, you should probably not try to create a role that already exists. Even if you use terraform import
to take ownership of the resource, you might get odd results if your code is modifying a role that is also owned by another module.
这篇关于Terraform 错误 EntityAlreadyExists:名为 iam_for_lambda 的角色已存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!