有没有办法在 terraform 中导入 iam-roles?

dev*_*sai 5 terraform terraform-provider-aws

我想将现有的 aws 资源 iam-role“DEVOPS”导入到我的 terraform 管理中。

尽管资源存在,但我收到以下错误 -

错误:无法导入不存在的远程对象

在尝试将现有对象导入到 aws_iam_role.okta_devops_role 时,提供程序检测到不存在具有给定 ID 的对象。只能导入预先存在的对象;检查 ID 是否正确以及它是否与提供者配置的区域或端点关联,或者使用“terraform apply”为此资源创建新的远程对象。

我在 main.tf 中创建了空资源 -> aws_iam_role.devops_role

eat*_*ood 6

您应该能够通过执行以下操作来导入现有 IAM 角色资源:

  1. 为您的资源创建存根,main.tf如下所示:
resource "aws_iam_role" "DEVOPS" {
  # stub
}
Run Code Online (Sandbox Code Playgroud)
  1. 运行导入命令:
terraform import aws_iam_role.DEVOPS DEVOPS
Run Code Online (Sandbox Code Playgroud)
  1. 完成后,显示资源并更新您在步骤 1 中创建的资源存根:
terraform show
Run Code Online (Sandbox Code Playgroud)

这是文档的链接


小智 -4

无法导入未通过 terraform 配置的现有资源。

As terraform do refer to the resource via terraform state file and detects the configuration drift

Still, you can give a try to:-

https://github.com/GoogleCloudPlatform/terraformer#use-with-aws
Run Code Online (Sandbox Code Playgroud)

  • 这是不正确的。Terraform 确实具有导入功能。 (3认同)