Skip to content

Commit e198ebf

Browse files
committed
edits
1 parent 51aeb3e commit e198ebf

File tree

1 file changed

+51
-32
lines changed

1 file changed

+51
-32
lines changed

articles/static-web-apps/publish-bicep.md

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,25 @@ ms.author: cshoe
1212

1313
# Deploy Azure Static Web Apps with Bicep
1414

15-
Use a Bicep file to create your Azure Static Web app to Azure. Bicep is a domain-specific language (DSL) that uses declarative syntax to define and create Azure resources repeatedly in a consistent manner.
15+
Use a Bicep file to create your Azure Static Web app to Azure. Bicep provides a declarative syntax to define and create Azure resources repeatedly in a consistent manner, which can be automated and repeated.
16+
17+
Your creation process should include all the resources in your application. 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.
1618

17-
To deploy your static web app, you need to:
18-
* Create resources with Bicep
19-
* Deploy your source code. Use one of the following tools to deploy your app:
20-
* [Azure Developer CLI](/azure/developer/azure-developer-cli)
21-
* [Static Web Apps CLI](https://github.com/Azure/static-web-apps-cli)
22-
* [GitHub Actions](https://docs.github.com/actions)
23-
2419
## Types of resource creation
2520

2621
Bicep is one of several types of resource creation. These types include:
2722

28-
* [Azure Resource Management](/azure/azure-resource-manager/) (ARM): 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 but generally updated to Bicep or Azure Verified Modules.
23+
* [Azure Resource Management](/azure/azure-resource-manager/) (ARM): 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 but updated to Bicep or Azure Verified Modules.
2924
* [Bicep](/azure/azure-resource-manager/Bicep/): Bicep is a domain-specific language (DSL) that uses declarative syntax to deploy Azure resources. In a Bicep file, you define the infrastructure you want to deploy to Azure, and then use that file throughout the development lifecycle to repeatedly deploy your infrastructure. Your resources are deployed in a consistent manner.
3025
* [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.
31-
* [Azure CLI](/cli/azure/)/[PowerShell](/powershell): These command line apps allow you to create resources. They have generally been superceded by Bicep and AVM but are still used for minor or quick fixes while the larger Bicep update may be more time-consuming.
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).
3227
* [Azure portal](https://portal.azure.com/): Azure portal is a web-based visual interface for resource creation and configuration.
3328

3429
Creation and configuration can be done across all the tools listed above.
3530

3631
## Bicep by example
3732

38-
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. You'll be able to recognize AVM because the referenced module includes `avm/res` such as `br/public:avm/res/web/static-site:0.3.0`.
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`.
3934

4035
```Bicep
4136
module swa 'br/public:avm/res/web/static-site:0.3.0' = {
@@ -50,24 +45,19 @@ module swa 'br/public:avm/res/web/static-site:0.3.0' = {
5045
}
5146
```
5247

53-
AVM allows you to adopt 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.
48+
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.
5449

5550
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.
5651

5752
## Prerequisites
5853

59-
- [Bicep](../azure-resource-manager/Bicep/install.md)
60-
- Optional, [Visual Studio Code extension for Bicep](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-Bicep). This extension is used to immediately run your Bicep file, which creates your resources.
54+
- [Bicep tools](../azure-resource-manager/Bicep/install.md)
55+
- [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.
6156

6257
## Create a static web app resource
6358

64-
Create a `main.Bicep` file with the Bicep code below to:
59+
Create a file named `main.bicep` file and paste in the following code:
6560

66-
* Create a unique string, `resourceToken`.
67-
* Create tags for the resources. Tags are filterable in the Azure portal.
68-
* Create a unique resource group.
69-
* Create a Static web app.
70-
7161
```Bicep
7262
targetScope = 'subscription'
7363
@@ -77,9 +67,6 @@ param location string ='eastus2'
7767
@description('Random string to make resource names unique')
7868
var resourceToken = uniqueString(subscription().subscriptionId, location)
7969
80-
@description('Tags to be added to all resources')
81-
var tags = { 'docs-Bicep-example-swa': resourceToken }
82-
8370
@description('Create a resource group')
8471
resource rg 'Microsoft.Resources/resourceGroups@2024-03-01' = {
8572
name: 'rg-swa-app-${resourceToken}'
@@ -95,7 +82,6 @@ module swa 'br/public:avm/res/web/static-site:0.3.0' = {
9582
name: 'swa-${resourceToken}'
9683
location: location
9784
sku: 'Free'
98-
tags: union(tags, { 'service-name': 'client' })
9985
}
10086
}
10187
@@ -106,17 +92,23 @@ output endpoint string = swa.outputs.defaultHostname
10692
output staticWebAppName string = swa.outputs.name
10793
```
10894

109-
Save the values of the output variables. You'll need these to configure the resources.
95+
This file creates the following resources for you:
96+
* An application name as the `resourceToken` value
97+
* Tags associated with your app to help you find and filter resources in the Azure portal
98+
* A resource group for this application
99+
* A static web app
110100

111-
## Create a static web app with a linked backend function app
101+
Save the values of the output variables to a text editor. You'll need these to configure the resources. The next step is to include a linked backend Azure Functions app in the next section.
112102

113-
To create a static web app with a linked backend function app, you need to use a standard plan for your static web app and complete the following steps.
103+
## Link a Functions app
114104

115-
* [Create the Azure Function app](/azure/azure-functions/functions-create-first-function-Bicep). You need the `resourceId` for the Function app, which looks like: `/subscriptions/<SUBSCRIPTION-ID>/resourcegroups/<RESOURCE-GROUP-NAME>/providers/Microsoft.Web/sites/<FUNCTION-APP-NAME>`.
116-
* Create the static web app using the [Bicep in the previous section](#create-a-static-web-app-resource).
117-
* Link the static web app to the function app.
105+
To link a Functions app for your backend, use the Static Web Apps standard plan for your web app and complete the following steps.
118106

119-
Create a `config.Bicep` file to link the static web app to the function app.
107+
To create the Azure Function app, follow the instructions provided in the Create the Azure Function app guide. 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>.
108+
109+
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, link the static web app to the function app to enable seamless integration between your front-end and back-end services.
110+
111+
Create a file named `config.bicep` file and paste in the following code:
120112

121113
```Bicep
122114
targetScope = 'resourceGroup'
@@ -154,17 +146,44 @@ resource linkedStaticWebAppBackend 'Microsoft.Web/staticSites/linkedBackends@202
154146
}
155147
```
156148

149+
This file handles the following tasks:
150+
151+
* Creates variables to use in resource configuration.
152+
* Create a reference to the existing static web app.
153+
* Create a reference string for the existing functions app.
154+
* Configure the static web app to link to the functions app.
155+
157156
## Deployment
158157

159-
After your resources are created, you can deploy your application to the hosting environment. The following descriptions show you how to work both locally and deploy though GitHub Actions:
158+
Deploy your source code with one of the following tools to deploy your app:
159+
* [Azure Developer CLI (Recommended)](/azure/developer/azure-developer-cli)
160+
* [Static Web Apps CLI](https://github.com/Azure/static-web-apps-cli)
161+
* [GitHub Action](https://docs.github.com/actions)
162+
* [Azure DevOps](/azure/devops/pipelines/overview-azure)
160163

161164
* **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.
162165

163166
* **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.
164167

165168
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).
166169

170+
## Speeding up deployments with Azure Developer CLI
171+
172+
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 is skipped. Learn more about this [performance improvement](
173+
https://devblogs.microsoft.com/azure-sdk/azure-developer-cli-azd-october-2023-release/#azd-provision-is-now-faster-when-there-are-no-infrastructure-changes
174+
).
175+
176+
## Azure samples
177+
178+
The following samples create and deploy Azure Static Web apps with Azure Developer CLI:
179+
180+
*
181+
167182
## Related content
168183

169184
* [Awesome AZD](https://azure.github.io/awesome-azd/?tags=swa)
170185
* [Public Bicep Registry](https://github.com/Azure/bicep-registry-modules)
186+
* [Azure Developer CLI](/azure/developer/azure-developer-cli)
187+
* [Static Web Apps CLI](https://github.com/Azure/static-web-apps-cli)
188+
* [GitHub Actions](https://docs.github.com/actions)
189+

0 commit comments

Comments
 (0)