terrars_hashicorp_random/random/
provider.rs1use serde::Serialize;
2use std::cell::RefCell;
3use std::rc::Rc;
4use terrars::*;
5
6#[derive(Serialize)]
7struct ProviderRandomData {
8 #[serde(skip_serializing_if = "Option::is_none")]
9 alias: Option<String>,
10}
11
12struct ProviderRandom_ {
13 data: RefCell<ProviderRandomData>,
14}
15
16pub struct ProviderRandom(Rc<ProviderRandom_>);
17
18impl ProviderRandom {
19 pub fn provider_ref(&self) -> String {
20 let data = self.0.data.borrow();
21 if let Some(alias) = &data.alias {
22 format!("{}.{}", "random", alias)
23 } else {
24 "random".into()
25 }
26 }
27
28 pub fn set_alias(self, alias: impl ToString) -> Self {
29 self.0.data.borrow_mut().alias = Some(alias.to_string());
30 self
31 }
32}
33
34impl Provider for ProviderRandom_ {
35 fn extract_type_tf_id(&self) -> String {
36 "random".into()
37 }
38
39 fn extract_provider_type(&self) -> serde_json::Value {
40 serde_json::json!({
41 "source": "hashicorp/random",
42 "version": "3.4.3",
43 })
44 }
45
46 fn extract_provider(&self) -> serde_json::Value {
47 serde_json::to_value(&self.data).unwrap()
48 }
49}
50
51pub struct BuildProviderRandom {}
52
53impl BuildProviderRandom {
54 pub fn build(self, stack: &mut Stack) -> ProviderRandom {
55 let out =
56 ProviderRandom(Rc::new(ProviderRandom_ { data: RefCell::new(ProviderRandomData { alias: None }) }));
57 stack.add_provider(out.0.clone());
58 out
59 }
60}