[英]Detach a policy from an IAM user using terraform
以下代码将现有 IAM 策略“ policy_1 ”附加到现有 IAM 用户“ user_1 ”
resource "aws_iam_user_policy_attachment" "test-attach" {
user = "user_1"
policy_arn = "arn:aws:iam::aws:policy/policy_1"
}
我需要有关如何使用 Terraform 从“ user_1 ”中删除相同策略的帮助。 谢谢!
我尝试了另一种“aws_iam_user_policy_detachment”,但这样的 function 不存在。 我知道这可以通过 AWS CLI 简单地使用detach-user-policy
完成,但我们要求它通过 Terraform 完成。
Terraform 创建资源,然后对其进行管理。 When you run terraform plan
or terraform apply
, terraform finds the difference between your described state and the existing state, and adds or deletes resources as needed.
您可以通过三种方式删除它。
如果您有一个包含此资源的有效 state 文件,只需删除代码并运行terraform apply
。
如果您没有管理此资源的 state 文件,则需要创建一个。 使用terraform import
开始管理此资源。
terraform import aws_iam_user_policy_attachment.test-attach user_1/arn:aws:iam::aws:policy/policy_1
terraform 导入所需的 ID 将取决于资源 - 请查看提供商的文档以了解如何找到它。
然后删除定义aws_iam_user_policy_attachment.test-attach
的代码,然后运行terraform apply
以创建新的 state,其中不包含资源。
terraform destroy
将删除本地 state 文件中的每个项目。 这是清理实验的好方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.