Skip to content

Commit d539be9

Browse files
authored
Merge pull request #302076 from mumian/0630-resource-derived-types
Document Bicep resource-derived types
2 parents a9a42ed + 1747ed1 commit d539be9

File tree

3 files changed

+66
-5
lines changed

3 files changed

+66
-5
lines changed

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

Lines changed: 3 additions & 3 deletions
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

@@ -66,7 +66,7 @@ var index = 1
6666
output secondElement int = exampleArray[index] // 2
6767
```
6868

69-
Starting with [Bicep CLI version 0.34.x](https://github.com/Azure/bicep/releases/tag/v0.34.1), you can use the `array[^index]` syntax to access elements from the end of an array `^1` refers to the last element, `^2` to the second-to-last, and so on.
69+
Starting with [Bicep CLI version 0.34.x](https://github.com/Azure/bicep/releases/tag/v0.34.1), you can use the `array[^index]` syntax to access elements from the end of an array - `^1` refers to the last element, `^2` to the second-to-last, and so on.
7070

7171
```bicep
7272
var exampleArray = [1, 2, 3]
@@ -325,7 +325,7 @@ var storageName = 'storage${uniqueString(resourceGroup().id)}'
325325
In Bicep, multi-line strings are defined between three single quotation marks (`'''`) followed optionally by a newline (the opening sequence) and three single quotation marks (`'''` is the closing sequence). Characters that are entered between the opening and closing sequence are read verbatim. Escaping isn't necessary or possible.
326326

327327
> [!NOTE]
328-
> The Bicep parser reads every characters as it is. Depending on the line endings of your Bicep file, newlines are interpreted as either `\r\n` or `\n`.
328+
> The Bicep parser reads every character as it is. Depending on the line endings of your Bicep file, newlines are interpreted as either `\r\n` or `\n`.
329329
>
330330
> Interpolation isn't currently supported in multi-line strings. Because of this limitation, you might need to use the [`concat`](./bicep-functions-string.md#concat) function instead of using [interpolation](#strings).
331331
>

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: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: User-defined types in Bicep
33
description: This article describes how to define and use user-defined data types in Bicep.
44
ms.topic: conceptual
55
ms.custom: devx-track-bicep
6-
ms.date: 04/28/2025
6+
ms.date: 07/01/2025
77
---
88

99
# User-defined data types in Bicep
@@ -412,6 +412,67 @@ 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. [Bicep CLI version 0.34.1](https://github.com/Azure/bicep/releases/tag/v0.34.1) or higher is required to use these constructs.
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 ReadOnly in the ARM template 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 WriteOnly in the ARM template schema. It matches the type of value returned after the resource is provisioned.
432+
433+
You can apply `resourceInput<>` or `resourceOutput<>` to extract only a part of a resource schema. For example, to 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+
The preceding example 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 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+
// Typed parameter 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 typed parameter
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+
The following example shows how to use `resourceOutput<>` to create a typed output based on the `primaryEndPoints` of a storage account resource.
469+
470+
```bicep
471+
output storageEndpoints resourceOutput<'Microsoft.Storage/storageAccounts@2024-01-01'>.properties.primaryEndpoints = ...
472+
```
473+
474+
Unlike user-defined data types, resource-derived types are checked by Bicep when editing or compiling a file, but they aren't checked by the ARM service.
475+
415476
## Related content
416477

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

0 commit comments

Comments
 (0)