Skip to content

Commit c1b900f

Browse files
committed
Document Bicep resource-derived types
1 parent f31f4cb commit c1b900f

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

articles/azure-resource-manager/bicep/data-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Data types in Bicep
33
description: This article describes the data types that are available in Bicep.
44
ms.topic: reference
5-
ms.date: 05/20/2025
5+
ms.date: 06/30/2025
66
ms.custom: devx-track-bicep
77
---
88

articles/azure-resource-manager/bicep/toc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ items:
278278
- name: Import (import)
279279
href: bicep-import.md
280280
- name: User-defined data types (type)
281-
displayName: custom
281+
displayName: custom,resourceInput,resourceOutput,resource-derived types
282282
href: user-defined-data-types.md
283283
- name: User-defined functions (func)
284284
displayName: custom

articles/azure-resource-manager/bicep/user-defined-data-types.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,61 @@ output config object = serviceConfig
412412

413413
For more information, see [Custom tagged union data type](./data-types.md#custom-tagged-union-data-type).
414414

415+
## Resource-derived types
416+
417+
Bicep allows you to derive types directly from Azure resource schemas using the `resourceInput<>` and `resourceOutput<>` constructs. Resource-derived types allow you to check parameters and variables against a portion of a resource body instead of with a custom type.
418+
419+
Templates can reuse resource types wherever a type is expected:
420+
421+
```bicep
422+
resourceInput<'type@version'>
423+
```
424+
425+
`resourceInput<>`: Represents the writable properties of a resource type, stripping away any properties marked as WriteOnly in the ARM schema. It uses the type that you would need to pass in to the resource declaration.
426+
427+
```bicep
428+
resourceOutput<'type@version'>
429+
```
430+
431+
`resourceOutput<>`: Represents the readable properties of a resource type, stripping away any properties marked as ReadOnly in the ARM schema. It matches the type of value returned after the resource is provisioned.
432+
433+
You can apply `resourceInput<>` to extract only a part of a resource schema. For example, to strongly type a variable or parameter based on just the `kind` or `properties` of a storage account:
434+
435+
```bicep
436+
type accountKind = resourceInput<'Microsoft.Storage/storageAccounts@2024-01-01'>.kind
437+
```
438+
439+
This is equivalent to:
440+
441+
```bicep
442+
type accountKind = 'BlobStorage' | 'BlockBlobStorage' | 'FileStorage' | 'Storage' | 'StorageV2'
443+
```
444+
445+
The following example shows how to use `resourceInput<>` to create a strongly typed parameter based on the `properties` of a storage account resource. This allows you to define a parameter that matches the writable properties of a storage account, such as `accessTier`, `minimumTlsVersion`, and others:
446+
447+
```bicep
448+
// Strongly typed variable using the .properties path of a storage account
449+
param storageAccountProps resourceInput<'Microsoft.Storage/storageAccounts@2023-01-01'>.properties = {
450+
accessTier: 'Hot'
451+
minimumTlsVersion: 'TLS1_2'
452+
allowBlobPublicAccess: false
453+
supportsHttpsTrafficOnly: true
454+
}
455+
456+
// Resource declaration using the strongly typed properties variable
457+
resource storageAccount 'Microsoft.Storage/storageAccounts@2023-01-01' = {
458+
name: 'mystorageacct123'
459+
location: resourceGroup().location
460+
sku: {
461+
name: 'Standard_LRS'
462+
}
463+
kind: 'StorageV2'
464+
properties: storageAccountProps
465+
}
466+
```
467+
468+
Unlike user-defined data types, resource-derived types are checked by Bicep when editing or compiling a file, but they are not checked by the ARM service.
469+
415470
## Related content
416471

417472
For a list of the Bicep data types, see [Data types](./data-types.md).

0 commit comments

Comments
 (0)