init corsschool

This commit is contained in:
nora 2024-04-15 20:42:22 +02:00
parent dc76e01e92
commit b5a28e4e94
6 changed files with 552 additions and 42 deletions

View file

@ -0,0 +1,11 @@
[package]
name = "terraform-provider-corsschool"
version = "0.1.0"
edition = "2021"
[dependencies]
eyre = "0.6.12"
reqwest = "0.12.3"
terustform = { path = "../terustform" }
tokio = { version = "1.37.0", features = ["full"] }

View file

@ -0,0 +1,85 @@
use std::collections::HashMap;
use terustform::{
datasource::{self, DataSource},
provider::Provider,
AttrPath, DResult, StringValue, Value, ValueModel,
};
#[tokio::main]
async fn main() -> eyre::Result<()> {
terustform::start(&ExampleProvider {}).await
}
pub struct ExampleProvider {}
impl Provider for ExampleProvider {
fn name(&self) -> String {
"example".to_owned()
}
fn data_sources(&self) -> Vec<Box<dyn DataSource>> {
vec![ExampleDataSource {}.erase()]
}
}
struct ExampleDataSource {}
#[derive(terustform::Model)]
struct ExampleDataSourceModel {
name: StringValue,
meow: StringValue,
id: StringValue,
}
#[terustform::async_trait]
impl DataSource for ExampleDataSource {
fn name(&self, provider_name: &str) -> String {
format!("{provider_name}_kitty")
}
fn schema(&self) -> datasource::Schema {
datasource::Schema {
description: "an example".to_owned(),
attributes: HashMap::from([
(
"name".to_owned(),
datasource::Attribute::String {
description: "a cool name".to_owned(),
mode: datasource::Mode::Required,
sensitive: false,
},
),
(
"meow".to_owned(),
datasource::Attribute::String {
description: "the meow of the cat".to_owned(),
mode: datasource::Mode::Computed,
sensitive: false,
},
),
(
"id".to_owned(),
datasource::Attribute::String {
description: "the ID of the meowy cat".to_owned(),
mode: datasource::Mode::Computed,
sensitive: false,
},
),
]),
}
}
async fn read(&self, config: Value) -> DResult<Value> {
let mut model = ExampleDataSourceModel::from_value(config, &AttrPath::root())?;
let name_str = model.name.expect_known(AttrPath::attr("name"))?;
let meow = format!("mrrrrr i am {name_str}");
model.meow = StringValue::Known(meow);
model.id = StringValue::Known("0".to_owned());
Ok(model.to_value())
}
}

View file

@ -0,0 +1,24 @@
terraform {
required_providers {
corsschool = {
source = "github.com/Nilstrieb/corsschool"
}
}
}
provider "corsschool" {}
//resource "terustform_hello" "test1" {}
data "corsschool_kitty" "kitty" {
name = "aa mykitten"
}
data "corsschool_kitty" "hellyes" {
name = "aa a cute kitty"
}
output "cat1" {
value = data.corsschool_kitty.kitty.meow
}
output "cat2" {
value = data.corsschool_kitty.hellyes.meow
}