The Contoso Real Estate (Power Platform Edition) project utilizes several Azure components to enable its functionality. These components include:
- Payments API Azure Functions - This component is used to host the payments api that is used by:
- Power Platform Custom Connector to create a Stripe Checkout session that is called by the portal using a Power Automate Flow. This is used for listing reservations.
- Power Platform Custom Connector to list Payments
- Dataverse Virtual Table Provider C# Plugin to expose the Payments as a Dataverse Virtual Table
- Webhook that is called by Stripe when payments events are raised
- Azure SQL Database - Stores the payments made via Stripe
- Azure Key Vault - Used to store all secrets that are necessary and is configured as the backing for Power Platform Environment Variable secrets.
AZURE-SQL-CONNECTION-STRING-payments-api
- SQL connection string for the Payments database. This does not contain any login username or password because the Azure Function uses a Managed Identity to connect to the database. E.g.Server=tcp:sql-***.database.windows.net,1433;Initial Catalog=contoso-real-estate;
. Learn about Managed Identities in Azure Functionscre-..-development-payments-api-client-secret
- Custom Connector Client Secret that is referenced by the Power Platform Environment Variable Secret and used in the custom connectors.StripeApiKey
- The Stripe API key to use for payment processingStripeWebhookSecret
- The Stripe webhook secret to use for verifying webhook events
- Entra ID Application registrations used to authenticate Power Platform against the Payments API
Note
For a full end-to-end set of instructions on how to install prerequisites, clone, build, deploy, and test the solutions, refer to full-development-setup-instructions.md.
To deploy the Azure resources required for the Contoso Real Estate (Power Platform Edition) project, you can use the azd up
command. This command is part of the Azure DevOps CLI extension and allows you to define and manage your infrastructure as code.
Here are the steps to deploy the Azure resources using azd up
:
-
Install the Azure CLI by following the instructions provided in the official Azure CLI documentation for your operating system.
-
Once the Azure CLI is installed, open a PowerShell terminal window inside VSCode at the root of the cloned repo.
-
Log in to your Azure account by running the following command and following the prompts:
az login
This will open a browser window where you can authenticate with your Azure account.
-
After successfully logging in, select the subscription you would like to deploy into:
az account list --output table az account set --subscription <Subscription Id you wish to use>
-
You must be a member of the User Access Administrator and Key Vault Administrator on your subscription to manage the access control on a key vault.
# Set the subscription and user principal name $subscriptionId = az account show --query id --output tsv $currentUPN = az ad signed-in-user show --query userPrincipalName # Find the roles of the current user for the currently selected subscription az role assignment list --query "[?principalName=='$currentUPN' && scope=='/subscriptions/$subscriptionId'].roleDefinitionName" --output table
If you do not see the two roles
Key Vault Administrator
andUser Access Administrator
, then use the following:# Assign the "Key Vault Administrator" and "User Access Administrator" role to the user az role assignment create --role "Key Vault Administrator" --assignee $currentUPN --scope /subscriptions/$subscriptionId az role assignment create --role "User Access Administrator" --assignee $currentUPN --scope /subscriptions/$subscriptionId az role assignment create --role "Key Vault Secrets User" --assignee $currentUPN --scope /subscriptions/$subscriptionId
-
The Power Platform Resource Provider must be registered in your Azure subscription so that Dataverse can access Azure Key Vaults in that subscription. At the VSCode terminal, use:
az provider show -n Microsoft.PowerPlatform
Registration will take a few minutes.
-
Install the Azure DevOps CLI extension by running the following command:
infra\azd\install-azd.ps1
Note
Check you have the latest version of Bicep (>= 0.29.47) installed using az bicep version
. Bicep is located in your azd bin folder %USERPROFILE%\.azd\bin
-
Install bicep using:
az bicep install
-
Login to azd using:
azd auth login
Select the same account that you authenticated with
az login
using. -
Run the
azd up
command to start the deployment process:az extension add --name graphservices azd up --environment development
The
environment
parameter would normally be the Power Platform environment that is being deployed to e.g.elaiza-dev1
UAT
PROD
-
When asked if you want to create the Environment, press 'Y'.
-
Select the Subscription to use when prompted.
-
Select the location to use - e.g. Central US
Important
When selecting a Azure location to deploy into, avoid using WEST US 2 due to there often being resource capacity limitations.
- When prompted for the 'principalLoginName' infrastructure parameter, enter your Power Platform username e.g.
[email protected]
. This will be stored in a file called.azure/<environmentname>/config.json
. It is important to ensure that this user name is the one you have authenticated against Azure with. It will be used to set the administrator of the SQL Server.
Note
If you want to deploy updates to the code later on after the infrastructure has been published you can use azd deploy
- Monitor the deployment progress and check for any errors or warnings. The
azd up
command will provide detailed logs and feedback during the deployment process.
Note
You may need to run azd up
a second time if there are errors the first time (due to azure replication)
Some settings cannot be performed by Bicep/ARM scripts (or are complex and beyond the scope of this sample). To complete the deployment the following tasks must be carried out:
- Grant the Azure Function Payment API managed identity access to SQL Server. The Azure Functions run under a System Assigned Managed Identity (SAMI). This identity must be added to the SQL Server as an external user. This cannot be performed by a SQL Login (inside the bicep script), because it needs access to Entra ID.
- Add admin consent to the Payment API client Entra ID Application registration, so that it can be used as an SPN connection in Power Platform
- Grant your user access to the Payment API so that it can be used as an OAuth user connection in Power Platform for testing.
-
You will need a stripe account for the payment API to function.
-
Navigate to Sign Up and Create a Stripe Account | Stripe
-
Enter you Email, Name, Country, and Password.
-
Select Create account.
-
Validate your email address by following the instructions.
-
Navigate to https://dashboard.stripe.com/test/dashboard
-
Run the following and follow the instructions carefully:
./infra/scripts/post-deployment-setup.ps1
It is important to note that deploying these resources to your Azure subscription will have a consumption cost. Once you have finished with the deployment you can remove the deployment by using:
./infra/scripts/delete-entraid-applications-before-azd-down.ps1
azd down
NOTE: When prompted 'Would you like to permanently delete these resources instead, allowing their names to be reused?' select YES
The Azure function managed identity is used to give access to the Key Vault and to the database.
To create a managed identity for the Azure Function:
- Open the Azure Function in the Azure Portal
- Select the
Identity
menu item - Set the
Status
toOn
- Select
Save
- Select
Yes
to enable the system assigned identity - Copy the
Object ID
of the managed identity
- Inside the Azure Function Identity page:
- Select 'Add role assignment'
- Select 'Add role assignment'
- Select the Scope `Key Vault'
- Select the Key Vault that contains the secrets
- Select the role
Key Vault Secrets User
- Select
Save
- Open the Azure SQL Database in Management Studio
- Run the following SQL command to create a user for the managed identity:
IF NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = N'AzureFunctionAppName')
BEGIN
CREATE USER [AzureFunctionAppName] FROM EXTERNAL PROVIDER;
END
ALTER ROLE db_datareader ADD MEMBER [AzureFunctionAppName];
ALTER ROLE db_datawriter ADD MEMBER [AzureFunctionAppName];
Note
Replace AzureFunctionAppName with the name of the Managed Identity created for the Azure Function App.