【问题标题】:How can I find a right ID about an existing resource in AWS in order to import to Terraform resource?如何在 AWS 中找到有关现有资源的正确 ID 以便导入到 Terraform 资源?
【发布时间】:2020-01-24 02:07:29
【问题描述】:

通过 Terraform 部署到 AWS 时出现重复的现有资源错误。

Error: Error creating IAM Role SecuritySearchAPITaskRole: EntityAlreadyExists: Role with name SecuritySearchAPITaskRole already exists.
    status code: 409, request id: cf5ae1f4-de6a-11e9-a7b1-d3cdff4db013

  on deploy/modules/ecs-fargate-service/iam.tf line 1, in resource "aws_iam_role" "task":
   1: resource "aws_iam_role" "task" {

根据上述错误,它是一个名为 SecuritySearchAPITaskRole 的现有 IAM 角色。我认为解决方案是将此资源导入我的本地 terraform 状态,但如何找出我需要使用的资源 ID。我可以在 AWS IAM 控制台上找到这个角色,但它似乎没有 ID。我还尝试运行terraform plan,这给了我:

  + resource "aws_iam_role" "task" {
      + arn                   = (known after apply)
      + assume_role_policy    = jsonencode(
            {
              + Statement = [
                  + {
                      + Action    = "sts:AssumeRole"
                      + Effect    = "Allow"
                      + Principal = {
                          + Service = "ecs-tasks.amazonaws.com"
                        }
                    },
                ]
              + Version   = "2012-10-17"
            }
        )
      + create_date           = (known after apply)
      + description           = "Task role for the SecuritySearchAPI service"
      + force_detach_policies = false
      + id                    = (known after apply)
      + max_session_duration  = 3600
      + name                  = "SecuritySearchAPITaskRole"
      + path                  = "/"
      + tags                  = {
          + "Application"            = "Security Search"
          + "Client"                 = "IRESS"
          + "DataClassification"     = "NoData"
          + "Name"                   = "SecuritySearchAPI Task Role"
          + "Owner"                  = "platform"
          + "Product"                = "SharedServices"
          + "Schedule"               = "False"
          + "Service"                = "Search"
          + "TaggingStandardVersion" = "3"
        }
      + unique_id             = (known after apply)
    }

你可以看到id =known after apply`没有被创建。如何找到 IAM 角色的 ID?

【问题讨论】:

    标签: amazon-web-services terraform


    【解决方案1】:

    好的,我找到了这个文档https://www.terraform.io/docs/providers/aws/r/iam_role.html#import,我可以在terraform import 命令中使用role name 作为ID。

    【讨论】:

      猜你喜欢
      • 2020-04-29
      • 2021-04-17
      • 2019-06-16
      • 2020-01-23
      • 2020-08-27
      • 2023-01-02
      • 2021-01-04
      • 2021-09-21
      • 2021-07-19
      相关资源
      最近更新 更多