mirror of
https://github.com/Noratrieb/terustform.git
synced 2026-01-16 01:15:10 +01:00
Support nested object
This commit is contained in:
parent
55506d3748
commit
b50fa51e9c
8 changed files with 143 additions and 96 deletions
|
|
@ -1,5 +1,3 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use terustform::{
|
||||
resource::Resource, AttrPath, Attribute, DResult, EyreExt, Mode, Schema, Value, ValueModel,
|
||||
};
|
||||
|
|
@ -78,41 +76,28 @@ impl Resource for ClassResource {
|
|||
fn schema() -> terustform::Schema {
|
||||
Schema {
|
||||
description: "A class".into(),
|
||||
attributes: HashMap::from([
|
||||
(
|
||||
"id".to_owned(),
|
||||
// TODO: UUID validation :3
|
||||
Attribute::String {
|
||||
description: "The UUID".to_owned(),
|
||||
mode: Mode::Computed,
|
||||
sensitive: false,
|
||||
},
|
||||
),
|
||||
(
|
||||
"name".to_owned(),
|
||||
Attribute::String {
|
||||
description: "The description".to_owned(),
|
||||
mode: Mode::Required,
|
||||
sensitive: false,
|
||||
},
|
||||
),
|
||||
(
|
||||
"description".to_owned(),
|
||||
Attribute::String {
|
||||
description: "The description".to_owned(),
|
||||
mode: Mode::Required,
|
||||
sensitive: false,
|
||||
},
|
||||
),
|
||||
(
|
||||
"discord_id".to_owned(),
|
||||
Attribute::String {
|
||||
description: "The discord ID of the class".to_owned(),
|
||||
mode: Mode::Optional,
|
||||
sensitive: false,
|
||||
},
|
||||
),
|
||||
]),
|
||||
attributes: terustform::attrs! {
|
||||
"id" => Attribute::String {
|
||||
description: "The UUID".to_owned(),
|
||||
mode: Mode::Computed,
|
||||
sensitive: false,
|
||||
},
|
||||
"name" => Attribute::String {
|
||||
description: "The description".to_owned(),
|
||||
mode: Mode::Required,
|
||||
sensitive: false,
|
||||
},
|
||||
"description" => Attribute::String {
|
||||
description: "The description".to_owned(),
|
||||
mode: Mode::Required,
|
||||
sensitive: false,
|
||||
},
|
||||
"discord_id" => Attribute::String {
|
||||
description: "The discord ID of the class".to_owned(),
|
||||
mode: Mode::Optional,
|
||||
sensitive: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use eyre::Context;
|
||||
use terustform::{
|
||||
datasource::DataSource, Attribute, DResult, EyreExt, Mode, Schema, StringValue, Value,
|
||||
|
|
@ -41,14 +39,13 @@ impl DataSource for HugoDataSource {
|
|||
fn schema() -> Schema {
|
||||
Schema {
|
||||
description: "Get Hugo Boss".to_owned(),
|
||||
attributes: HashMap::from([(
|
||||
"hugo".to_owned(),
|
||||
Attribute::String {
|
||||
attributes: terustform::attrs! {
|
||||
"hugo" => Attribute::String {
|
||||
description: "Hugo Boss".to_owned(),
|
||||
mode: Mode::Computed,
|
||||
sensitive: false,
|
||||
},
|
||||
)]),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use terustform::{
|
||||
datasource::DataSource, AttrPath, Attribute, DResult, Mode, Schema, StringValue, Value,
|
||||
ValueModel,
|
||||
|
|
@ -13,7 +11,13 @@ pub struct ExampleDataSource {}
|
|||
struct ExampleDataSourceModel {
|
||||
name: StringValue,
|
||||
meow: StringValue,
|
||||
id: StringValue,
|
||||
paws: ExampleDataSourceModelPaws,
|
||||
}
|
||||
|
||||
#[derive(terustform::Model)]
|
||||
struct ExampleDataSourceModelPaws {
|
||||
left: StringValue,
|
||||
right: StringValue,
|
||||
}
|
||||
|
||||
impl DataSource for ExampleDataSource {
|
||||
|
|
@ -26,32 +30,35 @@ impl DataSource for ExampleDataSource {
|
|||
fn schema() -> Schema {
|
||||
Schema {
|
||||
description: "an example".to_owned(),
|
||||
attributes: HashMap::from([
|
||||
(
|
||||
"name".to_owned(),
|
||||
Attribute::String {
|
||||
description: "a cool name".to_owned(),
|
||||
mode: Mode::Required,
|
||||
sensitive: false,
|
||||
attributes: terustform::attrs! {
|
||||
"name" => Attribute::String {
|
||||
description: "a cool name".to_owned(),
|
||||
mode: Mode::Required,
|
||||
sensitive: false,
|
||||
},
|
||||
"meow" => Attribute::String {
|
||||
description: "the meow of the cat".to_owned(),
|
||||
mode: Mode::Computed,
|
||||
sensitive: false,
|
||||
},
|
||||
"paws" => Attribute::Object {
|
||||
description: "the ID of the meowy cat".to_owned(),
|
||||
mode: Mode::Required,
|
||||
sensitive: false,
|
||||
attrs: terustform::attrs! {
|
||||
"left" => Attribute::String {
|
||||
description: "meow".to_owned(),
|
||||
mode: Mode::Required,
|
||||
sensitive: false,
|
||||
},
|
||||
"right" => Attribute::String {
|
||||
description: "meow".to_owned(),
|
||||
mode: Mode::Required,
|
||||
sensitive: false,
|
||||
},
|
||||
},
|
||||
),
|
||||
(
|
||||
"meow".to_owned(),
|
||||
Attribute::String {
|
||||
description: "the meow of the cat".to_owned(),
|
||||
mode: Mode::Computed,
|
||||
sensitive: false,
|
||||
},
|
||||
),
|
||||
(
|
||||
"id".to_owned(),
|
||||
Attribute::String {
|
||||
description: "the ID of the meowy cat".to_owned(),
|
||||
mode: Mode::Computed,
|
||||
sensitive: false,
|
||||
},
|
||||
),
|
||||
]),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -67,7 +74,7 @@ impl DataSource for ExampleDataSource {
|
|||
let meow = format!("mrrrrr i am {name_str}");
|
||||
|
||||
model.meow = StringValue::Known(meow);
|
||||
model.id = StringValue::Known("0".to_owned());
|
||||
model.paws.right = StringValue::Known("O".to_owned());
|
||||
|
||||
Ok(model.to_value())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue