Skip to content

restore resources group_create example #710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ Cargo.lock merge=binary

# Use unix line endings everywhere, even on Windows
* text=auto eol=lf
services/mgmt/**/*.rs linguist-generated=true
services/mgmt/**/src/**/*.rs linguist-generated=true
services/mgmt/**/Cargo.toml linguist-generated=true
39 changes: 39 additions & 0 deletions services/mgmt/resources/examples/group_create.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
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::token_credentials::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 {});
let subscription_id = &AzureCliCredential::get_subscription()?;
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::ClientBuilder::new(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()
.create_or_update(resource_group_name, group, subscription_id)
.into_future()
.await?;
println!("group created: {:#?}", group_created);
Ok(())
}