terustform/terraform-provider-corsschool/src/main.rs
2024-04-29 20:20:19 +02:00

56 lines
1.6 KiB
Rust

mod client;
mod resources;
use std::collections::HashMap;
use eyre::Context;
use terustform::{
datasource::DataSource, provider::Provider, resource::Resource, DResult, EyreExt, Schema, Value,
};
#[tokio::main]
async fn main() -> eyre::Result<()> {
terustform::start(ExampleProvider {}).await
}
pub struct ExampleProvider {}
impl Provider for ExampleProvider {
type Data = client::CorsClient;
fn name(&self) -> String {
"corsschool".to_owned()
}
fn schema(&self) -> Schema {
Schema {
description: "uwu".to_owned(),
attributes: HashMap::new(),
}
}
async fn configure(&self, _config: Value) -> DResult<Self::Data> {
let username = std::env::var("CORSSCHOOL_USERNAME")
.wrap_err("CORSSCHOOL_USERNAME environment variable not set")
.eyre_to_tf()?;
let password = std::env::var("CORSSCHOOL_PASSWORD")
.wrap_err("CORSSCHOOL_PASSWORD environment variable not set")
.eyre_to_tf()?;
let client = client::CorsClient::new(username, password)
.await
.wrap_err("failed to create client")
.eyre_to_tf()?;
Ok(client)
}
fn data_sources(&self) -> terustform::provider::DataSources<Self> {
vec![
resources::kitty::ExampleDataSource::erase(),
resources::hugo::HugoDataSource::erase(),
resources::class_data_source::ClassDataSource::erase(),
]
}
fn resources(&self) -> terustform::provider::Resources<Self> {
vec![resources::class_resource::ClassResource::erase()]
}
}