Get Started with Strapi Using Azure ARM templates
Tags: strapi, azure, webdev, headlesscms
Published: 2023-01-19 17:30:47

Author: Sangram Rath

All components, i.e., Strapi & MySQL, run on a single VM; hence it is ideal for getting started, exploring Strapi, or a sandbox scenario.

## What are Azure ARM templates?

[Azure ARM](https://learn.microsoft.com/es-es/azure/azure-resource-manager/management/overview) templates are a way to implement infrastructure as code in Azure. Infrastructure as code's benefits includes deployment automation, consistent and repeatable infrastructure, and agility.  

## Deployment Specifications & Important Details

This guide uses an ARM (Azure Resource Manager) template to deploy the required Azure resources and a bash script to configure and install Strapi in it. You can do this with minimal user intervention.

The template creates the following required resources in its own new Resource Group:

- Azure Virtual Machine & a disk
- VNET & a Subnet
- vNIC, Network Security Group

Strapi installation steps run using a bash script after the VM provisioning. The script is part of the repository that contains the ARM template.

The ARM template (JSON file) and the bash script are available on the [GitHub repo](https://github.com/sangramrath/strapi-community-content/tree/master/tutorials/code/strapi-quickstart-azure-arm). 


### Default Values

**Azure Defaults**

| Parameter          | Value        | Description                                   |
| ------------------ | ------------ | --------------------------------------------- |
| adminUsername      | strapiadmin  | Username for connecting (SSH) to the Azure VM |
| adminPasswordOrKey | $tr@p!@12345 | Default password for the user                 |


**Strapi Defaults**

A Strapi app called *blog* is created with the following defaults.

| Parameter  | Value            |
| ---------- | ---------------- |
| NODE_ENV   | development      |
| DB_HOST    | localhost        |
| DB_PORT    | 3306             |
| DB_NAME    | strapi_dev       |
| DB_USER    | strapi           |
| DB_PASS    | mysecurepassword |
| JWT_SECRET | aSecretKey       |


>**NOTE**: This template has been deliberately created so that it requires the least possible inputs to get a working Strapi installation. Hence, many variables have been pre-defined as per minimum requirements. You can edit the ARM template if you wish to modify any variables, such as Azure VM size or password(s). 

Running this Azure deployment as it is in Production is not recommended.

## Pre-requisites
- An Azure account with an active Subscription

While it is not mandatory but a basic understanding of the following will help if you wish to customize this template or the script

- Basic knowledge of Microsoft Azure
- Basic knowledge of JSON
- Bash
- Git

## Deploying the ARM template

1. Click the **Deploy to Azure** button below to load the template in Azure Portal. You may be prompted to sign in to Azure.
![Deploy to Azure](https://aka.ms/deploytoazurebutton)

2. In the custom deployment page, click **Create new** and create a new Resource Group for this deployment.
![Create a Resource Group](https://paper-attachments.dropboxusercontent.com/s_B0C8E021B5C93B96F599398EA0FCBBE5EDC01C966223B54D57A1DBE424CA7E03_1667373114425_2022-11-02_10-49.png)

3. Next, select your preferred **Region** and then click **Review + create**.
![Select a preferred region](https://paper-attachments.dropboxusercontent.com/s_B0C8E021B5C93B96F599398EA0FCBBE5EDC01C966223B54D57A1DBE424CA7E03_1667373148571_2022-11-02_10-51.png)

4. Ensure *Validation passes* , click **Create** to start the Azure resource deployment.
![Review deployment](https://paper-attachments.dropboxusercontent.com/s_B0C8E021B5C93B96F599398EA0FCBBE5EDC01C966223B54D57A1DBE424CA7E03_1667373180073_2022-11-02_10-52.png)

5. The deployment process will begin and take around 5-10 minutes. 
    **NOTE:** If the deployment fails, delete the resource group completely and restart the deployment. Do not use the *Redeploy* feature.
6. Once the deployment is complete, click **Outputs** to retrieve the randomly generated Public DNS of the Azure VM. 
![Retrieve Strapi URL](https://paper-attachments.dropboxusercontent.com/s_B0C8E021B5C93B96F599398EA0FCBBE5EDC01C966223B54D57A1DBE424CA7E03_1668625671009_2022-11-17_00-32.png)

    You can also retrieve this & the Public IP address from the **Overview** section of the Azure VM.


7. You can now access the Strapi administration page at **[DNS]:1337** or **[PublicIP]:1337** and create the first administrator.

## Modifying the default values 
### Azure infrastructure

You can modify the default values of the Azure infrastructure to your need. The following values could be changed (avoid changing other values, such as for networking and DNS, unless you are sure of the expected outcome):

- *virtualMachineName* 
- *adminUsername* 
- *adminPasswordOrKey* (we are using a password based login approach)
- *vmSize* (you will need to know the VM size SKUs)

After clicking *Deploy to Azure*, click **Edit template**.

![Editing the ARM template - 1](https://paper-attachments.dropboxusercontent.com/s_B0C8E021B5C93B96F599398EA0FCBBE5EDC01C966223B54D57A1DBE424CA7E03_1667375279804_2022-11-02_12-48.png)


Modify values as needed.

![Editing the ARM template - 2](https://paper-attachments.dropboxusercontent.com/s_B0C8E021B5C93B96F599398EA0FCBBE5EDC01C966223B54D57A1DBE424CA7E03_1667376615613_2022-11-02_13-39.png)


Click **Save**.

Continue with deployment.

### Strapi installation

The installation uses some default values for database username, password, port, database name, etc. As mentioned earlier in the article, one can modify them after the installation if needed.

Refer to [the documentation](https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/configurations/required/databases.html#configuration-structure) for instructions. 

## Security
- The installation does not expose the MySQL database running locally from outside.
- The installation does not use SSL/TLS by default.

## Conclusion

This article demonstrates how to quickly bring up an Azure VM running Strapi using an ARM template or Infrastructure as Code approach.