v2_cloud_cost_management_UpdateCustomAllocationRule/
v2_cloud-cost-management_UpdateCustomAllocationRule.rs

1// Update custom allocation rule returns "OK" response
2use 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                    .values(Some(vec![])),
27                    ArbitraryCostUpsertRequestDataAttributesCostsToAllocateItems::new(
28                        "in".to_string(),
29                        "environment".to_string(),
30                    )
31                    .value("".to_string())
32                    .values(Some(vec!["production".to_string(), "staging".to_string()])),
33                ],
34                vec!["aws".to_string(), "gcp".to_string()],
35                "example-arbitrary-cost-rule".to_string(),
36                ArbitraryCostUpsertRequestDataAttributesStrategy::new("proportional".to_string())
37                    .allocated_by_tag_keys(vec!["team".to_string(), "environment".to_string()])
38                    .based_on_costs(vec![
39                        ArbitraryCostUpsertRequestDataAttributesStrategyBasedOnCostsItems::new(
40                            "is".to_string(),
41                            "service".to_string(),
42                        )
43                        .value("web-api".to_string())
44                        .values(Some(vec![])),
45                        ArbitraryCostUpsertRequestDataAttributesStrategyBasedOnCostsItems::new(
46                            "not in".to_string(),
47                            "team".to_string(),
48                        )
49                        .value("".to_string())
50                        .values(Some(vec!["legacy".to_string(), "deprecated".to_string()])),
51                    ])
52                    .granularity("daily".to_string()),
53                "shared".to_string(),
54            )
55            .enabled(true)
56            .order_id(1),
57        ),
58    );
59    let configuration = datadog::Configuration::new();
60    let api = CloudCostManagementAPI::with_config(configuration);
61    let resp = api.update_custom_allocation_rule(683, body).await;
62    if let Ok(value) = resp {
63        println!("{:#?}", value);
64    } else {
65        println!("{:#?}", resp.unwrap_err());
66    }
67}