Skip to content

Commit

Permalink
Add resourceInput<> and resourceOutput<> utility types (#15825)
Browse files Browse the repository at this point in the history
Resolves #15183

This PR adds two new utility types (`resourceInput<>` and
`resourceOutput<>`) and deprecates the existing `resource<>` utility
types. These three utility types are all closely related but differ in
which property flags they surface:

- `resource<>` has the flags that were originally defined in the RP
types artifact. This is generally not what people want.
- `resourceInput<>` strips out all `WriteOnly` flags. This means that
template authors can access properties on a `resourceInput<>`-typed
parameter that would have previously raised a BCP077 diagnostic.
- `resourceOutput<>` strips out all `ReadOnly` flags.

Additionally, this PR allows the assignment of one `ReadOnly` property
to another `ReadOnly` property without raising any BCP073 diagnostics.
###### Microsoft Reviewers: [Open in
CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/15825)
  • Loading branch information
jeskew authored Dec 10, 2024
1 parent c0c938c commit f0470b8
Show file tree
Hide file tree
Showing 47 changed files with 2,085 additions and 1,499 deletions.
2 changes: 1 addition & 1 deletion docs/experimental-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Enables local deployment capability. See [Bicep Local Providers](https://github.
Enabling this feature makes the `name` property in the body of `module` declarations optional. When a `module` omits the `name` property with the feature enabled, the Bicep compiler will automatically generate an expression for the name of the resulting nested deployment in the JSON. If you specify the `name` property, the compiler will use the specified expression in the resulting JSON. For more information, see [Added optional module names as an experimental feature](https://github.com/Azure/bicep/pull/12600).

### `resourceDerivedTypes`
If enabled, templates can reuse resource types wherever a type is expected. For example, to declare a parameter `foo` that should be usable as the name of an Azure Storage account, the following syntax would be used: `param foo resource<'Microsoft.Storage/storageAccounts@2022-09-01'>.name`. **NB:** Because resource types may be inaccurate in some cases, no constraints other than the ARM type primitive will be enforced on resource derived types within the ARM deployment engine. Resource-derived types will be checked by Bicep at compile time, but violations will be emitted as warnings rather than errors.
If enabled, templates can reuse resource types wherever a type is expected. For example, to declare a parameter `foo` that should be usable as the name of an Azure Storage account, the following syntax would be used: `param foo resourceInput<'Microsoft.Storage/storageAccounts@2022-09-01'>.name`. **NB:** Because resource types may be inaccurate in some cases, no constraints other than the ARM type primitive will be enforced on resource derived types within the ARM deployment engine. Resource-derived types will be checked by Bicep at compile time, but violations will be emitted as warnings rather than errors.

### `resourceTypedParamsAndOutputs`
Enables the type for a parameter or output to be of type resource to make it easier to pass resource references between modules. This feature is only partially implemented. See [Simplifying resource referencing](https://github.com/azure/bicep/issues/2245).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ public void User_defined_discriminated_objects_can_amend_resource_derived_discri
new ServiceBuilder().WithFeatureOverrides(new(TestContext, ResourceDerivedTypesEnabled: true)),
"""
@discriminator('computeType')
type taggedUnion = resource<'Microsoft.MachineLearningServices/workspaces/computes@2020-04-01'>.properties
type taggedUnion = resourceInput<'Microsoft.MachineLearningServices/workspaces/computes@2020-04-01'>.properties
| { computeType: 'foo', bar: string }
""");

Expand All @@ -716,43 +716,57 @@ public void User_defined_discriminated_objects_can_amend_resource_derived_discri
"DataFactory": {
"type": "object",
"metadata": {
"__bicep_resource_derived_type!": "Microsoft.MachineLearningServices/workspaces/computes@2020-04-01#properties/properties/discriminator/mapping/DataFactory"
"__bicep_resource_derived_type!": {
"source": "Microsoft.MachineLearningServices/workspaces/computes@2020-04-01#properties/properties/discriminator/mapping/DataFactory"
}
}
},
"Databricks": {
"type": "object",
"metadata": {
"__bicep_resource_derived_type!": "Microsoft.MachineLearningServices/workspaces/computes@2020-04-01#properties/properties/discriminator/mapping/Databricks"
"__bicep_resource_derived_type!": {
"source": "Microsoft.MachineLearningServices/workspaces/computes@2020-04-01#properties/properties/discriminator/mapping/Databricks"
}
}
},
"VirtualMachine": {
"type": "object",
"metadata": {
"__bicep_resource_derived_type!": "Microsoft.MachineLearningServices/workspaces/computes@2020-04-01#properties/properties/discriminator/mapping/VirtualMachine"
"__bicep_resource_derived_type!": {
"source": "Microsoft.MachineLearningServices/workspaces/computes@2020-04-01#properties/properties/discriminator/mapping/VirtualMachine"
}
}
},
"AmlCompute": {
"type": "object",
"metadata": {
"__bicep_resource_derived_type!": "Microsoft.MachineLearningServices/workspaces/computes@2020-04-01#properties/properties/discriminator/mapping/AmlCompute"
"__bicep_resource_derived_type!": {
"source": "Microsoft.MachineLearningServices/workspaces/computes@2020-04-01#properties/properties/discriminator/mapping/AmlCompute"
}
}
},
"AKS": {
"type": "object",
"metadata": {
"__bicep_resource_derived_type!": "Microsoft.MachineLearningServices/workspaces/computes@2020-04-01#properties/properties/discriminator/mapping/AKS"
"__bicep_resource_derived_type!": {
"source": "Microsoft.MachineLearningServices/workspaces/computes@2020-04-01#properties/properties/discriminator/mapping/AKS"
}
}
},
"HDInsight": {
"type": "object",
"metadata": {
"__bicep_resource_derived_type!": "Microsoft.MachineLearningServices/workspaces/computes@2020-04-01#properties/properties/discriminator/mapping/HDInsight"
"__bicep_resource_derived_type!": {
"source": "Microsoft.MachineLearningServices/workspaces/computes@2020-04-01#properties/properties/discriminator/mapping/HDInsight"
}
}
},
"DataLakeAnalytics": {
"type": "object",
"metadata": {
"__bicep_resource_derived_type!": "Microsoft.MachineLearningServices/workspaces/computes@2020-04-01#properties/properties/discriminator/mapping/DataLakeAnalytics"
"__bicep_resource_derived_type!": {
"source": "Microsoft.MachineLearningServices/workspaces/computes@2020-04-01#properties/properties/discriminator/mapping/DataLakeAnalytics"
}
}
},
"foo": {
Expand Down
Loading

0 comments on commit f0470b8

Please sign in to comment.