You can use *templates* to create and persist configuration information to use
with Sensitive Data Protection. Templates are useful for decoupling configuration
information such as what you inspect for and how you de-identify it from the
implementation of your requests. Templates provide a robust
way to manage large-scale rollouts of Sensitive Data Protection capabilities.

Sensitive Data Protection supports two types of templates:

- [*Inspection templates*](https://docs.cloud.google.com/sensitive-data-protection/docs/creating-templates-inspect.md.txt): Templates for saving configuration information for inspection scan jobs, including what predefined or custom detectors to use.
- [*De-identification templates*](https://docs.cloud.google.com/sensitive-data-protection/docs/creating-templates-deid.md.txt): Templates for saving configuration information for de-identification jobs, including both infoType and structured dataset transformations.

## When to use templates

The following are some common use cases:

- **Standardize governance across multiple projects**: Standardize inspection rules (such as organizational infoType detector sets) at the organization or folder level to enforce consistent data security across multiple teams.
- **Decouple security configuration from application code**: Allow security and compliance administrators to modify infoTypes or transformation rules without requiring developers to update API calls or redeploy applications.
- **Enforce separation of duties and access control**: Use Identity and Access Management permissions to restrict who can edit sensitive transformation configurations (such as cryptographic keys used in de-identification) while granting broader teams permission to run jobs that reference the template.
- **Apply uniform protection across batch and streaming workloads**: Apply the same de-identification or inspection policies across both real-time content API calls and scheduled storage repository scans (such as BigQuery and Cloud Storage).
- **Streamline compliance updates**: Add newly mandated sensitive data types (such as a new national ID detector) to a single template so that all future inspection and profiling jobs automatically inherit the change.

## Advantages of templates

Templates enable you to use a single source for your job configuration
information. Consider a typical inspection scan request to
Sensitive Data Protection. Whether you're inspecting text, an image, or
structured data in a Google Cloud storage repository, your inspection request
will include two basic pieces of information:

- The data to scan: Either the data itself or information about the location of the data.
- What to scan for: The predefined or custom infoTypes to turn on, likelihood limits, and so on.

Say you scheduled several storage inspection jobs to run, all of which scanned a
Google Cloud storage repository for phone numbers and then created a
report of the findings. The following are conceptual summary descriptions of
these jobs. Note that `"inspectJob"` represents the data to scan, and
`"inspectConfig"` represents what to scan for.
>
> **Inspection job #1:**
>
> - `"inspectJob"`: *Q2 2017 marketing database.*
> - `"inspectConfig"`: *PHONE_NUMBER infoType.*
>
> <br />
>
>
> **Inspection job #2:**
>
> - `"inspectJob"`: *Customer alert contact
>   database.*
> - `"inspectConfig"`: *PHONE_NUMBER infoType.*
>
> <br />
>
>
> **Inspection job #3:**
>
> - `"inspectJob"`: *Top secret VIP partner strategy
>   database.*
> - `"inspectConfig"`: *PHONE_NUMBER infoType.*
>
> <br />
>
>
> **Inspection job #4:**
>
> - `"inspectJob"`: *Government contract database.*
> - `"inspectConfig"`: *PHONE_NUMBER infoType.*
>
> <br />
>
Each job's data source is different, but its instructions for what to scan for
are identical. Now suppose that we want to also scan for email addresses. In this
case, you would have to edit each job's configuration and add email addresses to
`"inspectConfig"`. If instead you had used a template to configure what to scan
for, you would only have to edit one configuration---that of the template. The
next time any of these jobs ran, it would know to scan for both phone numbers
and email addresses, because the `"inspectConfig"` had been set to a template.

## The InspectTemplate and DeidentifyTemplate objects

Templates are represented in Sensitive Data Protection by the
[`InspectTemplate`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/organizations.inspectTemplates)
and
[`DeidentifyTemplate`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/organizations.deidentifyTemplates)
objects. Both template objects contain a configuration---a set of infoType
detectors---to be used anywhere you otherwise would normally specify the [`InspectConfig`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/InspectConfig.md.txt) or
[`DeidentifyConfig`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/organizations.deidentifyTemplates#DeidentifyTemplate.DeidentifyConfig)
objects.

### Template configuration fields

Each template object contains the configuration object that the template
implements, plus several additional configuration fields:

- The template's name and display name, and a description.
- The [`InspectConfig`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/InspectConfig.md.txt) or [`DeidentifyConfig`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/organizations.deidentifyTemplates#DeidentifyTemplate.DeidentifyConfig) object: The configuration information for the inspection or de-identification job.
- Read-only timestamps for creation time (`"createTime"`) and a last updated time (`"updateTime"`).

### Template methods

Each template object also includes several built-in management methods.
These enable you to maintain the template without having to update every request
or integration. Each management method is linked in the following table,
and is organized by whether the template applies organization-wide
or project-wide, and whether the template is a de-identification template or an
inspection template:

<br />

|---|---|---|---|---|---|
|   | `organization.` || `project.` ||
|   | Create a new template | `create` | `create` | `create` | `create` |
| Update an existing template | [`patch`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/organizations.deidentifyTemplates/patch) | [`patch`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/organizations.inspectTemplates/patch) | [`patch`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/projects.deidentifyTemplates/patch.md.txt) | [`patch`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/projects.inspectTemplates/patch.md.txt) |
| Delete an existing template | [`delete`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/organizations.deidentifyTemplates/delete) | [`delete`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/organizations.inspectTemplates/delete) | [`delete`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/projects.deidentifyTemplates/delete.md.txt) | [`delete`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/projects.inspectTemplates/delete.md.txt) |
| Retrieve an existing template, including its configuration and status | [`get`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/organizations.deidentifyTemplates/get) | [`get`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/organizations.inspectTemplates/get) | [`get`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/projects.deidentifyTemplates/get.md.txt) | [`get`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/projects.inspectTemplates/get.md.txt) |
| List all existing job templates | [`list`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/organizations.deidentifyTemplates/list) | [`list`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/organizations.inspectTemplates/list) | [`list`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/projects.deidentifyTemplates/list.md.txt) | [`list`](https://docs.cloud.google.com/sensitive-data-protection/docs/reference/rest/v2/projects.inspectTemplates/list.md.txt) |

<br />

## Using templates

Templates are available for both inspection and de-identification configuration
information, and can be used in both content API calls (text and images) and
Sensitive Data Protection jobs (storage repositories).

Templates have powerful Identity and Access Management (IAM) controls so you can
restrict management of them to only approved users. For more information, see:

- [Sensitive Data Protection IAM roles](https://docs.cloud.google.com/sensitive-data-protection/docs/iam-roles)
- [Sensitive Data Protection IAM permissions](https://docs.cloud.google.com/sensitive-data-protection/docs/iam-permissions)

## Resources

To learn how to create and use templates with Sensitive Data Protection, see:

- [Creating Sensitive Data Protection inspection
  templates](https://docs.cloud.google.com/sensitive-data-protection/docs/creating-templates-inspect)
- [Creating Sensitive Data Protection de-identification
  templates](https://docs.cloud.google.com/sensitive-data-protection/docs/creating-templates-deid)