azure functions created in one cloud location for example south India should be able to create resource group in location central US
I want a clear step by step approach if this is possible.
const { ResourceManagementClient } = require("@azure/arm-resources");
module.exports = async function (context, req) {
const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"];
const credentials = new DefaultAzureCredential();
const resourceClient = new ResourceManagementClient(credentials, subscriptionId);
const resourceGroupName = "demoDiffResourceGroup";
const resourceGroupParameters = {
location: "centralus"
};
context.log(`Creating resource group: ${resourceGroupName} in Central US`);
try {
const result = await resourceClient.resourceGroups.createOrUpdate(resourceGroupName, resourceGroupParameters);
context.res = {
body: `Resource group created successfully: ${result.name}`
};
} catch (err) {
context.res = {
status: 500,
body: `Error creating resource group: ${err.message}`
};
}
};
2
Answers
This can be done by
In my case, my function app is in location south India which should be able to create resource group to a different location After setting up permissions you can trigger the following code will directly create resource group in a different location from a function which is in other location, use the code snippet:
I have used below code to create Resource group and Function App in different regions:
Code Snippet:
createResourceGroup
function creates a resource group in the specified region.createFunctionApp
function creates an App Service Plan in the defined region and then creates a Function App in the same region.main
function.Console response:
Update:
Resource group got created in Central US region:
Function App got created in South India region: