Terraform 错误 EntityAlreadyExists:名为 iam_for_lambda 的角色已经存在 [英] Terraform error EntityAlreadyExists: Role with name iam_for_lambda already exists

查看:22
本文介绍了Terraform 错误 EntityAlreadyExists:名为 iam_for_lambda 的角色已经存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行命令 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆