Skip to content

Commit ac27fa7

Browse files
Refine documentation of Azure.Provisioning (Azure#53354)
1 parent ebdd992 commit ac27fa7

File tree

1 file changed

+110
-3
lines changed

1 file changed

+110
-3
lines changed

sdk/provisioning/Azure.Provisioning/README.md

Lines changed: 110 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Azure Provisioning client library for .NET
22

3-
Azure.Provisioning makes it easy to declaratively specify Azure infrastructure natively in .NET.
3+
`Azure.Provisioning` makes it easy to declaratively specify Azure infrastructure natively in .NET.
44

55
## Getting started
66

@@ -20,13 +20,120 @@ dotnet add package Azure.Provisioning
2020

2121
## Key concepts
2222

23-
This library allows you to specify your infrastructure in a declarative style using dotnet. You can then use azd to deploy your infrastructure to Azure directly without needing to write or maintain bicep or arm templates.
23+
This library allows you to specify your infrastructure in a declarative style using dotnet. You can then use `azd` to deploy your infrastructure to Azure directly without needing to write or maintain `bicep` or arm templates.
24+
25+
### `BicepValue` types
26+
27+
`BicepValue` types are the foundation of `Azure.Provisioning`, providing a flexible type system that can represent literal .NET values, Bicep expressions, or unset properties. These types enable strongly-typed infrastructure definition while maintaining the flexibility needed for dynamic resource configuration.
28+
29+
#### Core `BicepValue` Types
30+
31+
**`BicepValue<T>`** - Represents a strongly-typed value that can be:
32+
- A literal .NET value of type `T`
33+
- A Bicep expression that evaluates to type `T`
34+
- An unset value (usually one should get this state from the property of a constructed resource/construct)
35+
36+
```csharp
37+
// Literal value
38+
BicepValue<string> literalName = "my-storage-account";
39+
40+
// Expression value
41+
BicepValue<string> expressionName = BicepFunction.CreateGuid();
42+
43+
// Unset value (can be assigned later)
44+
BicepValue<string> unsetName = storageAccount.Name;
45+
```
46+
47+
**`BicepList<T>`** - Represents a collection of `BicepValue<T>` items that can be:
48+
- A list of literal values
49+
- A Bicep expression that evaluates to an array
50+
- An unset list (usually one should get this state from the property of a constructed resource/construct)
51+
52+
```csharp
53+
// Literal list
54+
BicepList<string> tagNames = new() { "Environment", "Project", "Owner" };
55+
56+
// Expression list (referencing a parameter)
57+
BicepList<string> dynamicTags = parameterReference;
58+
59+
// Adding items
60+
tagNames.Add("CostCenter");
61+
```
62+
63+
**`BicepDictionary<T>`** - Represents a key-value collection where values are `BicepValue<T>`:
64+
- A dictionary of literal key-value pairs
65+
- A Bicep expression that evaluates to an object
66+
- An unset dictionary (usually one should get this state from the property of a constructed resource/construct)
67+
68+
```csharp
69+
// Literal dictionary
70+
BicepDictionary<string> tags = new()
71+
{
72+
["Environment"] = "Production",
73+
["Project"] = "WebApp",
74+
["Owner"] = "DevTeam"
75+
};
76+
77+
// Expression dictionary
78+
BicepDictionary<string> dynamicTags = parameterReference;
79+
80+
// Accessing values
81+
tags["CostCenter"] = "12345";
82+
```
83+
84+
#### Working with Azure Resources
85+
86+
**`ProvisionableResource`** - Base class for Azure resources that provides resource-specific functionality. Users typically work with specific resource types like `StorageAccount`, `VirtualMachine`, `AppService`, etc. An instance of type `ProvisionableResource` corresponds to a resource statement in `bicep` language.
87+
88+
**`ProvisionableConstruct`** - Base class for infrastructure components that group related properties and resources. Most users will work with concrete implementations like `StorageAccountSku`, `VirtualNetworkIPConfiguration`, etc. An instance of type `ProvisionableConstruct` usually corresponds to an object definition statement in `bicep` language.
89+
90+
Here's how you use the provided Azure resource classes:
91+
92+
```csharp
93+
// Create a storage account with BicepValue properties
94+
StorageAccount storage = new("myStorage", StorageAccount.ResourceVersions.V2023_01_01)
95+
{
96+
// Set literal values
97+
Name = "mystorageaccount",
98+
Kind = StorageKind.StorageV2,
99+
100+
// Use BicepValue for dynamic configuration
101+
Location = locationParameter, // Reference a parameter
102+
103+
// Configure nested properties
104+
Sku = new StorageSku
105+
{
106+
Name = StorageSkuName.StandardLrs
107+
},
108+
109+
// Use BicepList for collections
110+
Tags = new BicepDictionary<string>
111+
{
112+
["Environment"] = "Production",
113+
["Project"] = environmentParameter // Mix literal and dynamic values
114+
}
115+
};
116+
117+
// Access output properties (these are BicepValue<T> that reference the deployed resource)
118+
BicepValue<string> storageAccountId = storage.Id;
119+
BicepValue<Uri> primaryBlobEndpoint = storage.PrimaryEndpoints.BlobUri;
120+
121+
// Reference properties in other resources
122+
var appService = new AppService("myApp")
123+
{
124+
// Reference the storage account's connection string
125+
ConnectionStrings = new BicepDictionary<string>
126+
{
127+
["Storage"] = BicepFunction.Interpolate($"DefaultEndpointsProtocol=https;AccountName={storage.Name};AccountKey={storage.GetKeys().Value[0].Value}")
128+
}
129+
};
130+
```
24131

25132
## Examples
26133

27134
### Create Basic Infrastructure
28135

29-
This example demonstrates how to create basic Azure infrastructure using the Azure Provisioning framework, including a storage account with blob services and output values.
136+
This example demonstrates how to create basic Azure infrastructure using the `Azure.Provisioning` framework, including a storage account with blob services and output values.
30137

31138
```C# Snippet:ProvisioningBasic
32139
Infrastructure infra = new();

0 commit comments

Comments
 (0)