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
Copy file name to clipboardExpand all lines: articles/static-web-apps/publish-bicep.md
+68-86Lines changed: 68 additions & 86 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,75 +5,62 @@ services: static-web-apps
5
5
author: craigshoemaker
6
6
ms.service: azure-static-web-apps
7
7
ms.topic: how-to
8
-
ms.date: 08/13/2024
8
+
ms.date: 08/28/2024
9
9
ms.author: cshoe
10
10
#customer intent: As a developer, I want create a Static Web App on Azure with a Bicep file so that the process can to automated.
11
11
---
12
12
13
13
# Deploy Azure Static Web Apps with Bicep
14
14
15
-
Use a Bicep file to create your Azure Static Web Apps resource. Bicep provides a declarative syntax to define and create Azure resources, which can be automated and repeated for consistency.
15
+
You can use a Bicep file to create an instance of Azure Static Web Apps. Bicep provides a declarative syntax to define and create Azure resources, which can be automated and repeated for consistency.
16
16
17
-
This article details how to create the resource group that holds all the resources for your application, the Azure Static Web Apps resource, which contains your statically generated client application such as React, Vue, or Svelte, and the linked Azure Functions backend.
17
+
The steps in this article show you how to use Bicep to create a resource group and a Static Web Apps instance. After your static web app is created you still need to deploy your code using the typical methods of GitHub Actions, or using Azure Pipelines.
18
18
19
19
## Tools for resource creation
20
20
21
-
Bicep is one of several tools of resource creation. These tools include:
21
+
Bicep is one of several tools you can use to create resources in Azure. These tools include:
22
22
23
-
*[Azure Resource Management](/azure/azure-resource-manager/) (ARM): To implement infrastructure as code for your Azure solutions, use Azure Resource Manager templates (ARM templates). The template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. This older style is still in use.
24
-
*[Bicep](/azure/azure-resource-manager/Bicep/): Bicep is a domain-specific language (DSL) that uses declarative syntax to deploy Azure resources. Bicep provides concise syntax, reliable type safety, and support for code reuse.
25
-
*[Azure verified modules (AVM)](https://azure.github.io/Azure-Verified-Modules): These modules represent the only standard from Microsoft for Bicep modules in the [Bicep Public Registry](https://github.com/Azure/bicep-registry-modules/tree/main/avm). Use AVM when possible because it consolidates and set the standards for what a good infrastructure as code module looks like.
26
-
*[Azure CLI](/cli/azure/)/[PowerShell](/powershell): These command line apps allow you to create resources. They have generally been superseded by Bicep and AVM but are still used for minor or quick fixes while the larger Bicep update may be more time-consuming. Learn to [create resources with the Azure CLI and a Bicep file](/azure/azure-resource-manager/bicep/deploy-cli#deploy-local-bicep-file).
27
-
*[Azure portal](https://portal.azure.com/): Azure portal is a web-based visual interface for resource creation and configuration.
23
+
| Tool | Description |
24
+
|---|---|
25
+
|[Azure Resource Manager (ARM)](/azure/azure-resource-manager/)| To implement infrastructure as code for your Azure solutions, use Azure Resource Manager templates (ARM templates). The template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. This older style is still in use. |
26
+
|[Bicep](/azure/azure-resource-manager/Bicep/)| Bicep is a domain-specific language (DSL) that uses declarative syntax to deploy Azure resources. Bicep provides concise syntax, reliable type safety, and support for code reuse. |
27
+
|[Azure verified modules (AVM)](https://azure.github.io/Azure-Verified-Modules)| These modules represent the only standard from Microsoft for Bicep modules in the [Bicep Public Registry](https://github.com/Azure/bicep-registry-modules/tree/main/avm). Use AVM when possible because it consolidates and set the standards for what a good infrastructure as code module looks like. |
28
+
|[Azure CLI](/cli/azure/)/[PowerShell](/powershell)| These command line apps allow you to create resources. Bicep and AVM are often used in favor of these tools, but are still used for minor or quick fixes while the larger Bicep update might be more time-consuming. Learn to [create resources with the Azure CLI and a Bicep file](/azure/azure-resource-manager/bicep/deploy-cli#deploy-local-bicep-file). |
29
+
|[Azure portal](https://portal.azure.com/)| Azure portal is a web-based visual interface for resource creation and configuration. |
28
30
29
-
Creation and configuration can be done across all the tools listed above.
31
+
You can create and configure resources using any of the listed tools.
30
32
31
-
## Bicep by example
33
+
## Verified modules
32
34
33
-
The bicep examples in this article use [Azure Verified Modules (AVM)](https://azure.github.io/Azure-Verified-Modules/) when possible and [bicep](/azure/azure-resource-manager/bicep/) when AVM isn't available. AVM modules are recognizable because they reference modules that include `avm/res`, such as `br/public:avm/res/web/static-site:0.3.0`.
35
+
The Bicep examples in this article use [Azure Verified Modules (AVM)](https://azure.github.io/Azure-Verified-Modules/) when possible and [Bicep](/azure/azure-resource-manager/bicep/) when AVM isn't available. AVM modules are recognizable because they reference modules that include `avm/res`, such as `br/public:avm/res/web/static-site:0.3.0`.
AVM allows you to use managed Bicep code, which has been built and is maintained by professional engineers fluent in Bicep. These modules aren't only supported and maintained, they're opinionated about what proper Bicep files look like.
49
-
50
-
Due to the work involved in owning and maintaining the AVM files, it takes time to specify the module, determine best practices, and find the appropriate owner/maintainer. For this reason, the module you need may not be available at this time.
51
-
52
-
If the AVM isn't available, you can use _vanilla_[Bicep for your resources](/azure/templates/).
37
+
Using a verified module allows you to use opinionated managed Bicep code maintained by professional engineers fluent in Bicep. Since verified modules require support and dedicated attention, sometimes a module you need might not be available. If an AVM isn't available, you can code your [Bicep files](/azure/templates/) by hand.
53
38
54
39
## Prerequisites
55
40
56
-
-[Bicep tools](../azure-resource-manager/Bicep/install.md): Learn how to install Bicep tools.
41
+
-[Bicep tools](../azure-resource-manager/Bicep/install.md): Learn how to install Bicep tools.
57
42
-[Visual Studio Code extension for Bicep](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-bicep): An optional extension that creates resources for you by running your Bicep file.
58
43
59
44
## Create a static web app resource
60
45
61
-
Create a file named `main.bicep` file and paste in the following code:
46
+
The following code creates a new resource group and a Static Web Apps resource and then outputs the default host name and static web app name.
47
+
48
+
Create a file named `main.bicep` file and paste in the following code.
49
+
50
+
Before you run this code, make sure to replace the `<REGION_NAME>` placeholder with your region name.
62
51
63
52
```Bicep
64
53
targetScope = 'subscription'
65
54
66
-
@description('The name of the Azure region that will be used for the deployment.')
67
-
param location string ='eastus2'
55
+
param location string ='<REGION_NAME>'
68
56
69
-
@description('Random string to make resource names unique')
57
+
@description('String to make resource names unique')
70
58
var resourceToken = uniqueString(subscription().subscriptionId, location)
@description('Save the static web app name in an output')
80
+
@description('Output the static web app name')
94
81
output staticWebAppName string = swa.outputs.name
95
82
```
96
83
97
-
This file creates the following resources for you:
98
-
* An application name as the `resourceToken` value
99
-
* Tags associated with your app to help you find and filter resources in the Azure portal
100
-
* A resource group for this application
101
-
* A static web app
84
+
This code:
102
85
103
-
Save the values of the output variables to a text editor. You'll need these to find and configure the resources in the Azure portal. The next step is to include a linked backend Azure Functions app, shown in the next section.
86
+
- Scopes the action to the current Azure subscription.
87
+
- Generates a unique string to ensure the static web app name is globally unique.
88
+
- Creates a new resource group.
89
+
- Creates a new Static Web Apps instance using the free tier.
90
+
- Outputs the web app's URL.
91
+
- Outputs the static web app name.
104
92
105
-
## Link a Functions app
93
+
After you execute this file, save the values of the output variables to a text editor.
106
94
107
-
To link a Functions app for your backend, use the Static Web Apps standard plan for your web app and complete the following steps.
95
+
See the next section if you want to link an existing Azure Functions app to your static web app.
108
96
109
-
To create the Azure Function app, follow the instructions provided in the [Quickstart: Create and deploy Azure Functions resources using Bicep](/azure/azure-functions/functions-create-first-function-bicep) guide. When you're done creating your resource, you'll need the resourceId for the Function app, which looks like: `/subscriptions/<SUBSCRIPTION-ID>/resourcegroups/<RESOURCE-GROUP-NAME>/providers/Microsoft.Web/sites/<FUNCTION-APP-NAME>`, in order to link that function app to your static web app.
97
+
## Link a Functions app
110
98
111
-
Next, create the static web app using the Bicep template provided in the previous section. This sets up the necessary resources for your static web app. Finally, use the following Bicep file to link the static web app to the function app to enable seamless integration between your front-end and back-end services.
99
+
The code in the previous section demonstrates how to create a static web app using the free tier. If you want to link a managed backend to your static web app, you need to change to the [Standard hosting plan](/azure/static-web-apps/plans).
112
100
113
-
Create a file named `config.bicep` file and paste in the following code:
101
+
To link your Functions app to your static web app, you need the `resourceId` of your Functions App. You can get this value from the Azure portal, or you can use the following command to return your Functions app `resourceId`.
114
102
115
-
```Bicep
116
-
targetScope = 'resourceGroup'
117
-
118
-
@description('The name of the Azure region that will be used for the deployment.')
119
-
param location string = 'eastus2'
103
+
```bash
104
+
az functionapp show -n <FUNCTION-APP-NAME> -g <RESOURCE-GROUP-NAME> --query id --output tsv
105
+
```
120
106
121
-
@description('The Subscription ID')
122
-
param subscriptionId string = '<SUBSCRIPTION-ID>'
107
+
Create a file named `config.bicep` file and paste in the following code.
123
108
124
-
@description('The name of the Azure resource group.')
***Local development environment**: Use [Azure Developer CLI](/azure/developer/azure-developer-cli) to deploy from your local machine. When running locally, you define your deployment in an `azure.yml` file. This file includes hooks that plug into the resource creation process at any point to help you during deployment, especially when different parts of your app need to know about each other at build time.
149
+
-**Local development environment**: Use [Azure Developer CLI](/azure/developer/azure-developer-cli) to deploy from your local machine. When running locally, you define your deployment in an `azure.yml` file. This file includes hooks that plug into the resource creation process at any point. These extensibility points help you during deployment, especially when different parts of your app need to know about each other at build time.
167
150
168
-
***Production environment**: The ability to deploy from a GitHub Actions workflow file is a built-in feature when you create your static web app. Once the file is in your repository, you can edit the file as needed. Deployment from [other source code providers](external-providers.md) is also supported.
151
+
-**Production environment**: The ability to deploy from a GitHub Actions workflow file is a built-in feature when you create your static web app. Once the file is in your repository, you can edit the file as needed. Deployment from [other source code providers](external-providers.md) is also supported.
169
152
170
153
To learn more from a full end-to-end application that includes resource creation and application deployment, see [Serverless AI Chat with RAG using LangChain.js](https://github.com/Azure-Samples/serverless-chat-langchainjs).
171
154
172
-
## Speeding up deployments with Azure Developer CLI
155
+
## Faster deployments with the Azure Developer CLI
173
156
174
-
Azure Developer CLI (`azd`) uses Bicep files along with deployment configurations to create and provision your application. Since version 1.4, azd checks the Bicep against cloud resources to understand if the underlying infrastructure as code (IaC) state requires updates. If the state hasn't changed, creation and configuration are skipped. Learn more about this [performance improvement](
157
+
Azure Developer CLI (`azd`) uses Bicep files along with deployment configurations to create your application. Since version 1.4, `azd` checks the Bicep against cloud resources to determine if the underlying infrastructure as code (IaC) state requires updates. If the state remains unchanged, creation and configuration are skipped. To learn more about this performance improvement, see [azd provision is now faster when there are no infrastructure changes](
0 commit comments