跳到主要內容
版本:v1.1.3

Template reference

Who this is for: you are writing or reviewing a template and need the exact name, type or default of a field.

What you can do after reading: write any template without guessing, and read validation errors with confidence.

File layout​

Every template is a YAML file with the same top-level fields:

YAML
format_version: 1 # optional; 1 is the only version
kind: report # report | tag-policy | config
name: acme-bom # lower-case letters, digits and hyphens
description: One sentence shown by 'templates list'
extends: standard-bom # optional: a template name or a relative path
spec: # the settings for this kind
title: Acme Cloud Inventory
  • Files end in .yaml or .yml and must be UTF-8 text, at most 256 KiB.
  • The file name should match name (acme-bom.yaml has name: acme-bom). Lookups by name use the file name.
  • Unknown fields are errors, so typos never pass silently.
  • Duplicate keys are errors.
  • Put account IDs and hex colours in quotes ("012345678901", "1F3A5F") so YAML keeps them as text.

References to other files​

extends, tag_policy, report_template and logo can point at another file:

  • A name (standard-bom) is looked up in the search folders.
  • A relative path (./policies/strict.yaml) is relative to the template that contains it, and must stay inside that template's folder. .. that leaves the folder, absolute paths, ~ and URLs are rejected.

Field reference​

This section is generated from the code (python -m inventag.templating.reference --write), so it always matches what the validator accepts.

Fields in every template​

FieldTypeDefaultWhat it does
format_versionwhole number (min 1, max 1)1Template format version. Only 1 exists today.
kindone of report, tag-policy, configrequiredWhat the template controls: report, tag-policy or config.
nametemplate namerequiredLower-case letters, digits and hyphens. Should match the file name (my-report.yaml has name: my-report).
descriptiontextemptyOne sentence shown by templates list.
extendstemplate name or relative pathnot setTemplate to inherit from, by name or by relative path. Must be the same kind.
specmappingrequiredThe settings for this kind (see below).

Report templates (kind: report)​

FieldTypeDefaultWhat it does
spec.titletextAWS Resource InventoryReport title, used on the Word cover and the Excel summary sheet.
spec.subtitletextemptyOptional line under the title.
spec.company_nametextemptyOrganisation name shown on the cover and stored in the file properties.
spec.colorsmappingsee belowHeader colours as six-digit hex values (with or without #).
spec.logorelative file pathnot setImage shown on the Word cover (PNG, JPEG, GIF or BMP). The path is relative to the template file and must stay inside its folder.
spec.logo_alt_texttextemptyAlternative text for the logo, read by screen readers. Defaults to <company_name> logo.
spec.columnslist of mappingssee the built-in standard-bomColumns for resource tables, in order.
spec.tag_columnsall, none or list of tag keysallExtra columns, one per tag key, added after columns. Either a list of tag keys, or all for every tag key found on the resources in that table, or none.
spec.tag_policytemplate name or relative pathnot setTag policy to check, by name or by relative path. A --template with a tag policy on the command line takes precedence.
spec.excelmappingsee belowExcel workbook layout.
spec.wordmappingsee belowWord document layout.
spec.colors.header_fillhex colour1F3A5FBackground of table header rows.
spec.colors.header_texthex colourFFFFFFText colour of table header rows.
spec.columns[].fieldtextrequiredResource field to show. Use dots for nested values: tags.Owner is the Owner tag, raw_data.InstanceType is a value from the AWS API response.
spec.columns[].headertextnot setColumn heading. Defaults to the field name in plain words (resource_name becomes Resource name).
spec.columns[].widthwhole number (min 4, max 120)not setExcel column width in characters. Defaults to a width that fits the content, capped by excel.max_column_width.
spec.excel.summary_sheettrue or falsetrueAdd a Summary sheet with resource counts per service.
spec.excel.layoutone of per-service, single-sheetper-serviceper-service puts each service on its own sheet. single-sheet puts every resource on one sheet with a Service column.
spec.excel.single_sheet_nametextResourcesSheet name when layout is single-sheet.
spec.excel.include_all_fieldstrue or falsefalseAlso add every other field found on the resources, after the listed columns. Useful for audits; makes wide sheets.
spec.excel.freeze_headertrue or falsetrueKeep the header row visible when scrolling.
spec.excel.autofiltertrue or falsetrueAdd filter buttons to the header row.
spec.excel.max_column_widthwhole number (min 10, max 120)50Upper limit for automatic column widths, in characters.
spec.excel.tag_compliance_sheettrue or falsetrueAdd a Tag Compliance sheet when a tag policy is active.
spec.word.orientationone of portrait, landscapeportraitPage orientation.
spec.word.sectionslist of values from cover, summary, service-summary, tag-compliance, service-tables, about["cover", "summary", "service-summary", "tag-compliance", "service-tables", "about"]Sections to include, in order. Choose from: cover, summary, service-summary, tag-compliance, service-tables, about. tag-compliance is skipped when no tag policy is active.
spec.word.columnslist of mappingsnot setColumns for the per-service tables. Defaults to the first max_columns entries of columns. Tag columns are not added.
spec.word.max_columnswhole number (min 1, max 12)6How many of columns to use when word.columns is not set. Word tables get hard to read beyond six or seven columns.
spec.word.max_rows_per_servicewhole number (min 1, max 10000)50Rows shown per service table. A note says how many were left out.
spec.word.max_noncompliant_rowswhole number (min 1, max 10000)100Rows shown in the non-compliant resources table.
spec.word.columns[].fieldtextrequiredResource field to show. Use dots for nested values: tags.Owner is the Owner tag, raw_data.InstanceType is a value from the AWS API response.
spec.word.columns[].headertextnot setColumn heading. Defaults to the field name in plain words (resource_name becomes Resource name).
spec.word.columns[].widthwhole number (min 4, max 120)not setExcel column width in characters. Defaults to a width that fits the content, capped by excel.max_column_width.

Tag-policy templates (kind: tag-policy)​

FieldTypeDefaultWhat it does
spec.required_tagslist of mappingsrequiredTags that in-scope resources must have. When a template extends another, entries are merged by key: same key replaces, new keys are added, and remove: true drops one.
spec.scopemappingsee belowWhich resources the policy applies to. Resources outside the scope are counted but not checked.
spec.required_tags[].keytextrequiredTag key. AWS tag keys are case-sensitive, so costcenter does not satisfy CostCenter.
spec.required_tags[].descriptiontextemptyWhy the tag exists. Shown in reports.
spec.required_tags[].allowed_valueslist of textnot setIf set, the tag value must be one of these.
spec.required_tags[].case_sensitivetrue or falsefalseCompare allowed_values case-sensitively.
spec.required_tags[].patternregular expressionnot setIf set, the whole tag value must match this regular expression (Python syntax).
spec.required_tags[].removetrue or falsefalseIn a template that extends another, drop this tag from the inherited list.
spec.scope.serviceslist of text[]Only check these services (as shown in the report, for example EC2, S3). Empty means all services.
spec.scope.resource_typeslist of text[]Only check these resource types (for example Bucket, Instance). Empty means all types.
spec.scope.exclude_resource_typeslist of text[]Never check these resource types, for example types that cannot carry tags.

Config templates (kind: config)​

FieldTypeDefaultWhat it does
spec.accountslist of mappingsnot setAccounts to scan. Leave out to scan the account of your current AWS credentials. Each account needs profile_name or role_arn.
spec.regionslist of textnot setRegions to scan (--account-regions). Leave out to scan every enabled region.
spec.serviceslist of textnot setServices to include (--account-services). Currently applied in one discovery path only, so other services can still appear.
spec.outputslist of values from excel, word["excel"]Files to produce (--create-excel, --create-word).
spec.output_directorytextbom_outputFolder for the reports (--output-directory).
spec.report_templatetemplate name or relative pathstandard-bomReport template to use, by name or relative path.
spec.tag_policytemplate name or relative pathnot setTag policy to check, by name or relative path.
spec.fail_on_tag_violationstrue or falsefalseExit with code 3 after writing the reports if any in-scope resource breaks the tag policy. Needs tag_policy.
spec.max_concurrent_accountswhole number (min 1, max 64)4Accounts scanned at the same time (--max-concurrent-accounts).
spec.account_processing_timeoutwhole number (min 60)1800Seconds allowed per account (--account-processing-timeout).
spec.parallel_processingtrue or falsetrueScan accounts in parallel. false is the same as --disable-parallel-processing.
spec.accounts[].account_idtextrequired12-digit AWS account ID, in quotes so YAML keeps leading zeros.
spec.accounts[].account_nametextemptyFriendly name used in reports.
spec.accounts[].profile_nametextnot setAWS CLI profile to use for this account.
spec.accounts[].role_arntextnot setIAM role to assume in this account, as a full ARN.
spec.accounts[].external_idtextnot setExternal ID required by the role's trust policy.
spec.accounts[].regionslist of textnot setRegions to scan in this account. Overrides spec.regions.
spec.accounts[].serviceslist of textnot setServices to scan in this account.

Resource fields you can use as columns​

A column's field reads a value from each resource. These fields are present on resources from a normal run:

FieldContains
serviceService name as shown in the report, for example S3, EC2, VPC
resource_typeFor example Bucket, Volume, Subnet
resource_nameName, when the resource has one
resource_idThe resource's ID
arnAmazon Resource Name, when known
regionRegion code
source_account_idAccount the resource was found in
source_account_nameThe account_name you gave that account
tagsAll tags, written as Key=Value, Key=Value
tags.<Key>The value of one tag, for example tags.Owner
taggedYes or No
discovered_viaWhich API found the resource
raw_data.<Name>A value from the AWS API response, for example raw_data.VolumeType

Missing values are left blank. To see every field your resources have, set excel.include_all_fields: true and look at the extra columns.

Validation messages​

inventag templates validate <file> and every run with --template print problems as:

Text
<file>:<line>: <field>: <what is wrong>

For example, a template with header_fill: blue, used in a run:

Terminal
inventag - ERROR - Template problem:
inventag - ERROR - bad.yaml:5: spec.colors.header_fill: must be a six-digit hex colour such as 1F3A5F (got 'blue')
$ echo $?
1

And a misspelt template name:

Terminal
inventag - ERROR - Template problem:
inventag - ERROR - no template named 'acme-bomm'. Run 'inventag templates list' to see what is available (searched: ~/acme-infra/.inventag/templates, ~/.config/inventag/templates, ~/inventag-aws/inventag/templating/builtin)
$ echo $?
1

When a template extends another, problems are reported against the file that contains them.

Exit codes​

CommandCodeMeaning
templates validate0Every file is valid
templates validate1At least one file has a problem
templates init1The output file exists (use --force) or the template is invalid
templates init2The output name or extension is not allowed
inventag --template ...1A template is invalid, or the run failed
inventag --template ...3Reports were written, but resources break the tag policy and fail_on_tag_violations is true