v2_cloud_cost_management_CreateCustomAllocationRule/
v2_cloud-cost-management_CreateCustomAllocationRule.rs1use datadog_api_client::datadog;
3use datadog_api_client::datadogV2::api_cloud_cost_management::CloudCostManagementAPI;
4use datadog_api_client::datadogV2::model::ArbitraryCostUpsertRequest;
5use datadog_api_client::datadogV2::model::ArbitraryCostUpsertRequestData;
6use datadog_api_client::datadogV2::model::ArbitraryCostUpsertRequestDataAttributes;
7use datadog_api_client::datadogV2::model::ArbitraryCostUpsertRequestDataAttributesCostsToAllocateItems;
8use datadog_api_client::datadogV2::model::ArbitraryCostUpsertRequestDataAttributesStrategy;
9use datadog_api_client::datadogV2::model::ArbitraryCostUpsertRequestDataAttributesStrategyBasedOnCostsItems;
10use datadog_api_client::datadogV2::model::ArbitraryCostUpsertRequestDataType;
11
12#[tokio::main]
13async fn main() {
14 let body = ArbitraryCostUpsertRequest::new().data(
15 ArbitraryCostUpsertRequestData::new(
16 ArbitraryCostUpsertRequestDataType::UPSERT_ARBITRARY_RULE,
17 )
18 .attributes(
19 ArbitraryCostUpsertRequestDataAttributes::new(
20 vec![
21 ArbitraryCostUpsertRequestDataAttributesCostsToAllocateItems::new(
22 "is".to_string(),
23 "account_id".to_string(),
24 )
25 .value("123456789".to_string()),
26 ArbitraryCostUpsertRequestDataAttributesCostsToAllocateItems::new(
27 "in".to_string(),
28 "environment".to_string(),
29 )
30 .value("".to_string())
31 .values(Some(vec!["production".to_string(), "staging".to_string()])),
32 ],
33 vec!["aws".to_string(), "gcp".to_string()],
34 "example-arbitrary-cost-rule".to_string(),
35 ArbitraryCostUpsertRequestDataAttributesStrategy::new("proportional".to_string())
36 .allocated_by_tag_keys(vec!["team".to_string(), "environment".to_string()])
37 .based_on_costs(vec![
38 ArbitraryCostUpsertRequestDataAttributesStrategyBasedOnCostsItems::new(
39 "is".to_string(),
40 "service".to_string(),
41 )
42 .value("web-api".to_string()),
43 ArbitraryCostUpsertRequestDataAttributesStrategyBasedOnCostsItems::new(
44 "not in".to_string(),
45 "team".to_string(),
46 )
47 .value("".to_string())
48 .values(Some(vec!["legacy".to_string(), "deprecated".to_string()])),
49 ])
50 .granularity("daily".to_string()),
51 "shared".to_string(),
52 )
53 .enabled(true)
54 .order_id(1),
55 ),
56 );
57 let configuration = datadog::Configuration::new();
58 let api = CloudCostManagementAPI::with_config(configuration);
59 let resp = api.create_custom_allocation_rule(body).await;
60 if let Ok(value) = resp {
61 println!("{:#?}", value);
62 } else {
63 println!("{:#?}", resp.unwrap_err());
64 }
65}