forked from Azure/azure-sdk-for-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
group_create.rs
38 lines (34 loc) · 1.31 KB
/
group_create.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
Create a resource group, similar to:
az group create --name $RESOURCE_GROUP_NAME --location $RESOURCE_GROUP_LOCATION
export RESOURCE_GROUP_NAME=azuresdkforrust
export RESOURCE_GROUP_LOCATION=southcentralus
cargo run --package azure_mgmt_resources --example group_create
*/
use azure_identity::AzureCliCredential;
use azure_mgmt_resources::models::ResourceGroup;
use std::env;
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let credential = Arc::new(AzureCliCredential::new());
let subscription_id = AzureCliCredential::get_subscription().await?;
let resource_group_name = &env::var("RESOURCE_GROUP_NAME").map_err(|_| "RESOURCE_GROUP_NAME required")?;
let resource_group_location = env::var("RESOURCE_GROUP_LOCATION").map_err(|_| "RESOURCE_GROUP_LOCATION required")?;
let client = azure_mgmt_resources::Client::builder(credential).build()?;
let group = ResourceGroup {
id: None,
name: None,
type_: None,
properties: None,
location: resource_group_location,
managed_by: None,
tags: None,
};
let group_created = client
.resource_groups_client()
.create_or_update(resource_group_name, group, subscription_id)
.await?;
println!("group created: {group_created:#?}");
Ok(())
}