2

我让 Athena 能够使用 Terraform 查询 Cloudtrail s3 日志。为此,我需要在 Glue Catalog 中创建数据库和表。我正在关注这个链接

在 Terraform 中,我正在使用aws_glue_catalog_table resource. 如何在 terraform 文件中定义类型为 struct 和 Array 的列?

我尝试定义以下方式但没有奏效。

  resource "aws_glue_catalog_database" "cloud_logs" {
    name = "trail_logs_db"
  }

  resource "aws_glue_catalog_table" "cloud_table" {
    name          = "trail_logs"
    database_name = "${aws_glue_catalog_database.cloud_logs.name}"

    table_type = "EXTERNAL_TABLE"

    parameters = {
      EXTERNAL = "TRUE"
    }

    storage_descriptor {
      location      = "s3://<BUCKET NAME>/AWSLogs/<AWS ACCOUNT ID>/"
      input_format  = "com.amazon.emr.cloudtrail.CloudTrailInputFormat"
      output_format = "org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat"

      ser_de_info {
        name                  = "trail-logs"
        serialization_library = "com.amazon.emr.hive.serde.CloudTrailSerde"

        parameters {
          serialization.format = 1
        }
      }

      columns = [
        {
          name = "useridentity"
          type = "struct<type:string,
                 principalid:string,
                 arn:string,
                 accountid:string,
                 invokedby:string,
                 accesskeyid:string,
                 userName:string,>"
          comment = ""
        },
        {
          name    = "resources"
          type    = "array<STRUCT<ARN:string,
                    accountId:string,
                    type:string>>"
          comment = ""
        },
      ]
    }
  }

当我运行terraform init它会引发以下错误: Error: Error parsing test.tf: At 33:27: illegal char

4

2 回答 2

1

你想要的是一个heredoc

    {
          name = "useridentity"
          type = <<- EOT
                 struct<type:string,
                 principalid:string,
                 arn:string,
                 accountid:string,
                 invokedby:string,
                 accesskeyid:string,
                 userName:string,>
                 EOT
          comment = ""
        },
        {
          name    = "resources"
          type    = <<- EOT
                    array<STRUCT<ARN:string,
                    accountId:string,
                    type:string>>
                    EOT
          comment = ""
        },
于 2019-07-22T19:03:04.987 回答
0

找到了解决方法,但它看起来并不好。

当我将其格式化为一行时它可以工作。

  {
     name = "useridentity"
     type = "struct<type:string, principalid:string, arn:string, accountid:string,  invokedby:string, accesskeyid:string, userName:string,>"
      comment = ""
  },
  {
     name    = "resources"
     type    = "array<STRUCT<ARN:string, accountId:string, type:string>>"
     comment = ""
  },
于 2019-07-22T10:26:09.777 回答