mirror of
https://github.com/Noratrieb/terustform.git
synced 2026-01-14 16:35:11 +01:00
init corsschool
This commit is contained in:
parent
dc76e01e92
commit
b5a28e4e94
6 changed files with 552 additions and 42 deletions
11
terraform-provider-corsschool/Cargo.toml
Normal file
11
terraform-provider-corsschool/Cargo.toml
Normal 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"] }
|
||||
85
terraform-provider-corsschool/src/main.rs
Normal file
85
terraform-provider-corsschool/src/main.rs
Normal 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())
|
||||
}
|
||||
}
|
||||
24
terraform-provider-corsschool/test/main.tf
Normal file
24
terraform-provider-corsschool/test/main.tf
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue