You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Learn about the benefits of Bicep modules, and the basic syntax to create and use modules. Also, learn how modules relate to Azure deployments.
description: Learn about the benefits of Bicep modules, and the basic syntax to create and use modules. Also, learn how modules relate to Azure deployments.
- content: You deploy the *main.bicep* file with the default settings. You open the Azure portal and look at the deployment history for the resource group. What do you see?
20
-
choices:
21
-
- content: A single deployment named `main`.
22
-
isCorrect: false
23
-
explanation: Incorrect. Azure creates a deployment resource for each module, along with the template that you deploy.
24
-
- content: Two deployments. One is named `main` and the other is named `storage1`.
25
-
isCorrect: false
26
-
explanation: Incorrect. Although Azure creates two deployments in this example, the `name` property sets the module's deployment name, not the symbolic name.
27
-
- content: Two deployments. One is named `main` and the other is named `my-storage`.
28
-
isCorrect: true
29
-
explanation: Correct. Azure creates two deployments in this example. By default, the template file name is used for the parent deployment's name. The `name` property sets the module deployment's name.
30
-
- content: You plan to update the *main.bicep* file to add another resource. The new resource needs access to the key of the storage account created in the module. What should you do?
31
-
choices:
32
-
- content: Create an output in the module and set its value to the storage account's connection string.
33
-
isCorrect: false
34
-
explanation: Incorrect. Outputs should not be used for secure data, because they're logged and might be accessible to a lot of people in your organization.
35
-
- content: Use a key vault to create a secret.
36
-
isCorrect: true
37
-
explanation: Correct. You can define a key vault secret for the connection string value. Alternatively, you can use the `existing` keyword to read the properties of the storage account in another Bicep file.
38
-
- content: You don't need to do anything. Properties for all the resources defined in the module are automatically available to the parent template.
39
-
isCorrect: false
40
-
explanation: Incorrect. Properties for resources are accessible only within the Bicep file where they're declared.
41
-
- content: Your colleague has created a large Bicep file that you want to decompose into modules. You want to identify the resources that should be defined together in each module. Which tool can you consider using to help you achieve this task?
42
-
choices:
43
-
- content: Use the Bicep visualizer.
44
-
isCorrect: true
45
-
explanation: Correct. The Bicep visualizer illustrates the relationships between your resources. It can help you see any resources that are tightly coupled, which might indicate that they should be in a module together.
46
-
- content: Use the Bicep linter.
47
-
isCorrect: false
48
-
explanation: Incorrect. The Bicep linter scans your Bicep code for potential problems and warns you when you're not following best practices.
49
-
- content: Use the Azure documentation for ARM templates.
50
-
isCorrect: false
51
-
explanation: Incorrect. Although the ARM template documentation can be useful, it's not likely to help you when you're trying to decide how to decompose a Bicep file into modules.
- content: You deploy the *main.bicep* file with the default settings, then open the Azure portal and look at the deployment history for the resource group. What do you see?
20
+
choices:
21
+
- content: A single deployment named `main`.
22
+
isCorrect: false
23
+
explanation: Incorrect. Azure creates a deployment resource for each module, along with the template that you deploy.
24
+
- content: "Two deployments: one is named `main` and the other is named `storage1`."
25
+
isCorrect: false
26
+
explanation: Incorrect. Although Azure creates two deployments in this example, the `name` property sets the module's deployment name, not the symbolic name.
27
+
- content: "Two deployments: one is named `main` and the other is named `my-storage`."
28
+
isCorrect: true
29
+
explanation: Correct. Azure creates two deployments in this example. By default, the template file name is used for the parent deployment's name. The `name` property sets the module deployment's name.
30
+
- content: You plan to update the *main.bicep* file to add another resource. The new resource needs access to the key of the storage account created in the module. What should you do?
31
+
choices:
32
+
- content: Create an output in the module and set its value to the storage account's connection string.
33
+
isCorrect: false
34
+
explanation: "Incorrect. You shouldn't use outputs for secure data, because they're logged and might be accessible to many people in your organization."
35
+
- content: Use a key vault to create a secret.
36
+
isCorrect: true
37
+
explanation: Correct. You can define a key vault secret for the connection string value. Alternatively, you can use the `existing` keyword to read the properties of the storage account in another Bicep file.
38
+
- content: You don't need to do anything. Properties for all the resources defined in the module are automatically available to the parent template.
39
+
isCorrect: false
40
+
explanation: Incorrect. Properties for resources are accessible only within the Bicep file in which they're declared.
41
+
- content: Your colleague has created a large Bicep file that you want to decompose into modules. You want to identify the resources that should be defined together in each module. Which tool can you consider using to help you achieve this task?
42
+
choices:
43
+
- content: Use the Bicep visualizer.
44
+
isCorrect: true
45
+
explanation: Correct. The Bicep visualizer illustrates the relationships between your resources. It can help you see any resources that are tightly coupled, which might indicate that they should be in a module together.
46
+
- content: Use the Bicep linter.
47
+
isCorrect: false
48
+
explanation: Incorrect. The Bicep linter scans your Bicep code for potential problems and warns you when you're not following best practices.
49
+
- content: Use the Azure documentation for ARM templates.
50
+
isCorrect: false
51
+
explanation: Incorrect. Although the ARM template documentation can be useful, it's not likely to help you when you're trying to decide how to decompose a Bicep file into modules.
Copy file name to clipboardExpand all lines: learn-pr/azure/create-composable-bicep-files-using-modules/includes/1-introduction.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ To improve performance and reduce cost, you've been asked to add a content deliv
12
12
13
13
:::image type="content" source="../media/1-architecture-diagram.png" alt-text="Architecture diagram that shows two variants: one with traffic flowing from the internet to the app through a CDN, and another without a CDN." border="false" :::
14
14
15
-
## What will we be doing?
15
+
## What will we learn?
16
16
17
17
In this module, you'll create a set of Bicep modules to deploy your website and CDN. Then, you'll create a template that uses those modules together.
Copy file name to clipboardExpand all lines: learn-pr/azure/create-composable-bicep-files-using-modules/includes/2-create-use-bicep-modules.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ By using modules, you can reuse your Bicep code, and you can make your Bicep fil
4
4
5
5
## The benefits of modules
6
6
7
-
In your toy company, you've been provisioning cloud resources by using many individual Bicep files. Over time, these templates grow significantly. Eventually, you end up having monolithic code that's difficult to read and navigate, and even harder to maintain.
7
+
In your toy company, you've been provisioning cloud resources by using many individual Bicep files. Over time, these templates grow significantly. Eventually, you end up having monolithic code that's difficult to read and navigate and even harder to maintain.
8
8
9
9
This approach also forces you to duplicate parts of your code when you want to reuse it in other templates. When you change something, you need to search through and update multiple files.
10
10
@@ -22,7 +22,7 @@ You can even share modules within your team, within your organization, or with t
22
22
23
23
Modules help you keep related resource definitions together. For example, when you define an Azure Functions app, you typically deploy the app, a hosting plan for the app, and a storage account for the app's metadata. These three components are defined separately, but they represent a logical grouping of resources, so it might make sense to define them as a module.
24
24
25
-
That way, your main template doesn't need to be aware of the details of how a function app is deployed. That's the responsibility of the module.
25
+
That way, your main template doesn't need to be aware of the details of how a function app is deployed. That's the module's responsibility.
26
26
27
27
### Composability
28
28
@@ -80,7 +80,7 @@ Be sure to use a descriptive file name for each module. The file name effectivel
80
80
81
81
## Use the module in a Bicep template
82
82
83
-
You'll use a module in a Bicep template by using the `module` keyword, like this:
83
+
You can use a module in a Bicep template by using the `module` keyword, like this:
84
84
85
85
```bicep
86
86
module appModule 'modules/app.bicep' = {
@@ -125,8 +125,8 @@ You can list and view the details of deployment resources to monitor the status
125
125
126
126
### Generated JSON ARM templates
127
127
128
-
When you deploy a Bicep file, Bicep converts it to a JSON ARM template. This conversion is also called _transpilation_. The modules that the template uses are embedded into the JSON file. Regardless of how many modules you include in your template, only a single JSON file will be created.
128
+
When you deploy a Bicep file, Bicep converts it to a JSON ARM template. This conversion is also called _transpilation_. The modules that the template uses are embedded into the JSON file. Regardless of how many modules you include in your template, only a single JSON file is created.
129
129
130
-
In the example discussed in the previous section, Bicep generates a single JSON file even though there were originally two Bicep files.
130
+
In the example in the previous section, Bicep generates a single JSON file even though there were originally two Bicep files.
131
131
132
132
:::image type="content" source="../media/2-transpile.png" alt-text="Diagram that shows two Bicep files, which are transpiled into a single JSON file." border="false":::
Copy file name to clipboardExpand all lines: learn-pr/azure/create-composable-bicep-files-using-modules/includes/3-add-parameters-outputs-modules.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ Think about the parameters that your module accepts, and whether each parameter
12
12
13
13
When you create parameters for templates, it's a good practice to add default parameters where you can. In modules, it's not always as important to add default parameters, because your module will be used by a parent template that might use its own default parameters. If you have similar parameters in both files, both with default values, it can be hard for your template's users to figure out which default value will be applied and to enforce consistency. It's often better to leave the default value on the parent template and remove it from the module.
14
14
15
-
You should also think about how you manage parameters that control the SKUs for your resources and other important configuration settings. When you create a standalone Bicep template, it's common to embed business rules into your template. For example: _When I deploy a production environment, the storage account should use the GRS tier_. But modules sometimes present different concerns.
15
+
You should also think about how you manage parameters that control the SKUs for your resources and other important configuration settings. When you create a standalone Bicep template, it's common to embed business rules into your template. For example: _When I deploy a production environment, the storage account should use the GRS tier_. However, modules sometimes present different concerns.
16
16
17
17
If you're building a module that needs to be reusable and flexible, remember that the business rules for each parent template might be different, so it might not make as much sense to embed business rules into generic modules. Consider defining the business rules in your parent template, then explicitly pass module configuration through parameters.
18
18
@@ -32,7 +32,7 @@ You could achieve your requirement by adding a condition to the resource definit
When you include this module in a Bicep template, you can easily configure it to send the Azure Cosmos DB account logs to Log Analytics by setting a workspace ID. Or, if you don't need logs for the environment that you're deploying, omit the parameter. It has a default value. The module encapsulates the logic required to do the right thing for your requirements.
35
+
When you include this module in a Bicep template, you can easily configure it to send the Azure Cosmos DB account logs to Log Analytics by setting a workspace ID. If you don't need logs for the environment that you're deploying, you can omit the parameter. It has a default value. The module encapsulates the logic required to do the right thing for your requirements.
36
36
37
37
> [!TIP]
38
38
> Remember to test that your template is valid for both scenarios; when the `if` statement is evaluated as either `true` or `false`.
@@ -60,7 +60,7 @@ It's common to create a parent Bicep file that composes multiple modules togethe
In this example, symbolic names are used for the reference between the modules. This reference helps Bicep to automatically understand the relationships between the modules.
63
+
In this example, you use symbolic names for the reference between the modules. This reference helps Bicep automatically understand the relationships between the modules.
64
64
65
65
Because Bicep understands there's a dependency, it deploys the modules in sequence:
Copy file name to clipboardExpand all lines: learn-pr/azure/create-composable-bicep-files-using-modules/includes/4-exercise-create-use-module.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -152,7 +152,7 @@ New-AzResourceGroupDeployment -Name main -TemplateFile main.bicep
152
152
153
153
1. Select **<rgn>[sandbox resource group name]</rgn>**.
154
154
155
-
1. On the left menu, select **Deployments**.
155
+
1. On the left menu, select **Deployments** under **Settings**.
156
156
157
157
:::image type="content" source="../media/4-deployments.png" alt-text="Screenshot of the Azure portal that shows the resource group, with the Deployments menu item highlighted." :::
0 commit comments