Pulumi - Automation Api - over Http hosted using the Azure Container Apps
Its been a long time, since I posted here (but good to be back here). Recently I started exploring Pulumi for Azure and came across this Automation API and would like to share how we can setup this in a container to host it as an endpoint.
Pulumi Automation API is a SDK layer exposes Pulumi Infrastructure as a code to be used without the Pulumi CLI. More details around the Pulumi automation can be found here. In this post, We will see how we can host the Pulumi Automation API as a service on a Azure container apps.
The below steps, takes us through the setup required to host an endpoint to create a storage account in the Azure using the Pulumi Automation API.
Create a new Docker based API project
Include Pulumi Automation and Pulumi Native package to the project
Create an endpoint to create an Azure storage account
Use Pulumi Automation API to provision the storage account
Initialise the Pulumi Local Workspace as below to provision the storage account based on the parameters passed to the endpoint.
1 . Initialise the Pulumi local function using the Azure Native API to provision the resource group and a storage account.
2 . Setup the Pulumi Localworkspace
Note: CInlineProgramArgs is a custom class used to set the container application path required for Pulumi program to execute at the time of provisioning the resources.
3 . Install the Azure Native plugin The latest version of azure-native plugin at the time of writing this post is v1.102.0 and the details can be found here.
4 . Set the config
Setup the Pulumi stack to use a Azure Application registration, to provision the resources in the specified subscription and region.
5 . Refresh and Update the Stack
Refresh the stack state and Pulumi up to provision the resources.
Use Pulumi Automation API to provision the storage account
So, we have the endpoint ready to provision the storage account. Now let’s setup the Pulumi state using the Docker so that we can deploy it as a containerised app. The below docker code uses the Azure storage account to manage the state.
Use Pulumi Automation API to provision the storage account
So we got all the setup ready and lets test locally by invoking the endpoint with the required parameters.
http://0.0.0.0:4001/createstorage?resourceGroupName=rgsktech0101&stackName=snsktech0101&storageAccountName=stracsktech0102
Deploy the image to the Azure Container apps
1 . Deploy the image to the container registry
2 . Call the Endpoint https://containerurl.io/createstorage?resourceGroupName=rgsktech0101&stackName=snsktech0101&storageAccountName=stracsktech0101
Reference:
a. Pulumi Automation API examples
b. Sample code for the above