設定檔
適合誰閱讀: 你要手工編寫或檢查 InvenTag 的設定檔。
讀完後你可以: 寫出載入器能接受的帳戶檔案、標籤對應檔案和服務描述檔案。
關於範本(報告版面配置、標籤策略、執行設定),見範本參考。
設定範本能做帳戶檔案能做的一切,只是不能存放存取金鑰,並且每個帳戶都需要 profile_name 或 role_arn。它的校驗更嚴格,因此新的設定請優先使用它。
所有檔案都可以是 YAML(.yaml、.yml)或 JSON(.json)。不掃描也可以檢查它們:
inventag --accounts-file accounts.yaml --tag-mappings tags.yaml \
--validate-config-only --skip-credential-validation
這條命令唯讀取檔案,不呼叫 AWS。
InvenTag 以 UTF-8 讀取這些檔案,帶不帶位元組順序標記(BOM)都可以。空檔案、寫了兩次的鍵, 或頂層不是對應的檔案,都會以結束代碼 1 停止執行,並給出指明該檔案的訊息。
帳戶檔案
與 --accounts-file 一起使用。
accounts:
- account_id: "123456789012" # required, in quotes
account_name: Production # optional, shown in reports
role_arn: arn:aws:iam::123456789012:role/InvenTagReadOnly
external_id: optional-external-id # only if the trust policy needs it
regions: [us-east-1, eu-west-1] # optional; empty = every enabled region
services: [] # optional; empty = all services
- account_id: "210987654321"
account_name: Development
profile_name: dev-readonly # an AWS CLI profile instead of a role
settings: # optional
max_concurrent_accounts: 4
account_processing_timeout: 1800 # seconds, at least 60
output_directory: bom_output
帳戶可以指定一種獲取憑證的方式。沒有指定的帳戶會使用你目前的憑證(如果它們屬於該帳戶);否則 InvenTag 會嘗試在該帳戶中擔任角色 InvenTagCrossAccountRole(或用 --cross-account-role 給出的名稱)。
| 欄位 | 用途 |
|---|---|
profile_name | 一個 AWS CLI 設定檔,例如 IAM Identity Center 設定檔。 |
role_arn | InvenTag 使用你目前的憑證擔任的角色。 |
access_key_id 和 secret_access_key(以及可選的 session_token) | 寫在檔案中的金鑰。應避免使用:任何能讀取該檔案的人都拿到了金鑰。其他使用者能讀取這樣的檔案時,InvenTag 會發出警告。 |
settings 中的值會覆蓋對應的命令列引數。
settings 只接受 max_concurrent_accounts、account_processing_timeout 和 output_directory。InvenTag 會忽略其他任何鍵(例如 concurrency),並給出指出該鍵名的警告。要在檔案中設定 --concurrency,請使用設定範本的 spec.concurrency 欄位,或直接輸入該引數。
帳戶 ID 相同的第二個條目,以及 InvenTag 不認識的鍵(例如 profil_name),都會給出一條指出它的警告,--validate-config-only 也會輸出這些警告。檔案仍會被接受。
要在每個帳戶中使用同一個角色名稱,請省略 role_arn,並在命令中加上
--cross-account-role InvenTagReadOnly。
損壞的帳戶檔案會在掃描之前就讓執行停止。例如,沒有加引號的帳戶 ID(範例資料):
inventag - WARNING - - Account 1: no credentials given; InvenTag will assume the --cross-account-role role (default InvenTagCrossAccountRole) in this account, or use the default credentials only if they belong to this account
inventag - ERROR - ❌ Accounts configuration is invalid:
inventag - ERROR - - Account 1: 'account_id' must be a non-empty string
inventag - ERROR - ❌ Some configuration files have validation errors
echo $?
1
現成的範例在儲存庫的
examples/
資料夾中,例如 accounts_cross_account_roles.json 和
accounts_with_profiles.json。
標籤對應
與 --tag-mappings 一起使用。每個條目會在報告中新增一個命名欄。
該欄顯示標籤的值;如果資源沒有這個標籤,則顯示預設值。
tag_mappings:
- tag: CostCenter # required: the tag key
name: Cost Center # required: the column name
default_value: Unknown # optional: shown when the tag is missing
description: Budget that pays for the resource
required: false
case_sensitive: false
該列出現在預設工作簿中(不使用 --template 時)。使用 --template 時它不會出現,並會給出警告:請改用報告範本中的 tag_columns。
使用版面配置檔案(--excel-template、--word-template)時,把欄名新增到 extra_fields。
請使用頂層鍵 tag_mappings,其值是條目的列表。InvenTag 也接受較早的寫法,即把每個標籤鍵作為頂層鍵,並給出 column_name 值。
服務描述
與 --service-descriptions 一起使用。它會在報告中新增 service_description 欄。
沒有檔案時,InvenTag 會寫入內建描述,例如
Amazon EC2 Instance (i-0abc1234def567890) in us-east-1。
service_descriptions:
DYNAMODB:
default:
description: Application data table
EC2:
Volume:
description: Block storage
template: volume_text # optional: a text with variables
templates:
volume_text:
template: "Disk {resource_id} in {region}"
頂層鍵 service_descriptions 是必需的。在每個服務之下,每種資源型別(或 default)都需要一個 description。InvenTag 在你校驗或啟動執行時不會檢查這一點。沒有該鍵的檔案會被忽略,日誌中會有一條錯誤,並使用內建描述。
你的條目會替換內建描述,對所有服務都是如此。帶 template 的條目使用在 templates 下定義的該範本;
不帶 template 的條目按原樣使用其 description(範例中 DynamoDB 表使用的是 Application data table)。
範本可以使用 {resource_id}、{resource_type}、{service}、{region} 和 {account_id}。
你的檔案中沒有條目的服務保留內建文字。
如果範本無法填充,InvenTag 會記錄一條警告,例如
Failed to render template vpc_vpc: 'cidr_block',並使用內建備用文字。對於你自己檔案中的範本,則使用該條目的 description。
BOM 處理設定
與 --bom-config 一起使用。它是一個 YAML 或 JSON 對應,其鍵是 BOM 處理設定的欄位,例如:
enable_network_analysis: false
enable_parallel_processing: true
max_worker_threads: 4
未知的鍵會被忽略,並記錄一條列出這些鍵的警告,所以請在日誌中查詢拼錯的鍵。型別錯誤的值會以結束代碼 1 停止執行,並指明該鍵。
例如,enable_network_analysis: true 新增的工作表與 --enable-network-analysis 相同。
這個檔案用於高階調優;大多數人從來不需要它。