Hi ,
Thanks for reaching out to Microsoft Q&A.
To programmatically create a new Resource Group, Azure AI Doc Intelligence resource, and Storage Account in Java, you need to use the Azure SDK for Java (management libraries).
- Dependencies (Maven) : Use the latest version of these packages:
- Authenticate
Use DefaultAzureCredential
for local dev (ensure you have az login
or AZURE_CLIENT_ID
, etc. set up).
import com.azure.identity.DefaultAzureCredentialBuilder; import com.azure.resourcemanager.AzureResourceManager; import com.azure.resourcemanager.resources.fluentcore.profile.AzureProfile; import com.azure.core.management.profile.AzureEnvironment; AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE); AzureResourceManager azure = AzureResourceManager .authenticate(new DefaultAzureCredentialBuilder().build(), profile) .withDefaultSubscription();
- Creating Resource Group
String resourceGroupName = "myResourceGroup"; String region = "eastus"; azure.resourceGroups().define(resourceGroupName) .withRegion(region) .create();
- Create Storage Account
import com.azure.resourcemanager.storage.models.SkuName; import com.azure.resourcemanager.storage.models.Kind; String storageAccountName = "myuniquestorage" + System.currentTimeMillis(); // must be globally unique azure.storageAccounts().define(storageAccountName) .withRegion(region) .withExistingResourceGroup(resourceGroupName) .withSku(SkuName.STANDARD_LRS) .withKind(Kind.STORAGE_V2) .create();
- Create Azure AI Document Intelligence
The AI Document Intelligence API is part of Cognitive Services, so you create a Cognitive Services Account of kind "FormRecognizer"
.
import com.azure.resourcemanager.cognitiveservices.CognitiveServicesManager;
import com.azure.resourcemanager.cognitiveservices.models.Kind;
import com.azure.resourcemanager.cognitiveservices.models.Sku;
CognitiveServicesManager cognitiveServicesManager = CognitiveServicesManager
.authenticate(new DefaultAzureCredentialBuilder().build(), profile);
String cognitiveAccountName = "myformrecognizer" + System.currentTimeMillis();
cognitiveServicesManager.accounts().define(cognitiveAccountName)
.withRegion(region)
.withExistingResourceGroup(resourceGroupName)
.withKind(Kind.FORM_RECOGNIZER)
.withSku(new Sku().withName("S0"))
.withTags(Map.of("env", "dev"))
.create();
Note:
- Ensure that the Form Recognizer (Doc Intelligence) resource kind is correct:
Kind.FORM_RECOGNIZER
. - You need to register Microsoft.CognitiveServices and Microsoft.Storage resource providers in your subscription if not already registered.
- The names (especially for Storage and Cognitive accounts) must be globally unique.
The azure-resourcemanager
SDK is actively maintained, but make sure you use the correct combination of AzureResourceManager
and CognitiveServicesManager
, the two operate differently.
HTH!
Please 'Upvote'(Thumbs-up) and 'Accept' as answer if the reply was helpful. This will be benefitting other community members who face the same issue.