0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

DatadogのカスタムロールをTerraformで作るときの「permission ID」の探し方メモ

Posted at

どうも!株式会社ShowcaseGigでSREとして働いている @atsusics です

この記事は99%ChatGptに書いてもらっています


Datadog Provider のドキュメントには、カスタムロールを作るサンプルとしてこんなコードが載っています。

# Source the permissions
data "datadog_permissions" "bar" {}

# Create a new Datadog role
resource "datadog_role" "foo" {
  name = "foo"
  permission {
    id = data.datadog_permissions.bar.permissions.monitors_downtime
  }
  permission {
    id = data.datadog_permissions.bar.permissions.monitors_write
  }
}

ただ、permission の ID をどう調べるの? が最初パッと分からなかったので、API で一覧を引いて選ぶやり方を残しておきます。
(データソース datadog_permissions を使えば ID をハードコードせずに済みますが、どんな権限が存在するかを確認するときや、一時的に ID を直書きしたいときにも役立ちます)


権限一覧を API で取得する

1) curl

# USサイト例(Datadog US1)
curl -s -X GET "https://api.datadoghq.com/api/v2/permissions" \
  -H "Accept: application/json" \
  -H "DD-API-KEY: ${DD_API_KEY}" \
  -H "DD-APPLICATION-KEY: ${DD_APP_KEY}" \
  | jq . > permissions.json

参考: 取得結果のサンプル(抜粋)

{
  "data": [
    {
      "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
      "type": "permissions",
      "attributes": {
        "created": "2024-05-03T17:35:35.030875Z",
        "description": "View LLM Observability.",
        "display_name": "LLM Observability Read",
        "display_type": "read",
        "group_name": "LLM Observability",
        "name": "llm_observability_read",
        "restricted": false
      }
    },
    {
      "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
      "type": "permissions",
      "attributes": {
        "created": "2024-08-13T16:25:39.351685Z",
        "description": "Create, Update, and Delete LLM Observability resources including User Defined Evaluations, OOTB Evaluations, and User Defined Topics.",
        "display_name": "LLM Observability Write",
        "display_type": "write",
        "group_name": "LLM Observability",
        "name": "llm_observability_write",
        "restricted": false
      }
    },
  ]
}

まとめ

  • 何の権限があるか分からない → GET /api/v2/permissions を見る
  • Terraform では data.datadog_permissions で name から安全に参照
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?