Skip to content

Commit

Permalink
Use example framework of cargo
Browse files Browse the repository at this point in the history
  • Loading branch information
lemaitre-aneo committed May 25, 2024
1 parent ddd6287 commit 1e0be62
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 318 deletions.
299 changes: 136 additions & 163 deletions Cargo.lock

Large diffs are not rendered by default.

42 changes: 12 additions & 30 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,60 +1,42 @@
[workspace]
members = ["examples/*"]
resolver = "2"

[workspace.package]
[package]
authors = ["Florian Lemaitre <[email protected]>"]
description = "Plugin framework for Terraform and ToFu"
edition = "2021"
include = ["**/*.rs", "Cargo.toml", "LICENSE", "proto/*.proto"]
license = "Apache-2.0"
name = "tf-provider"
repository = "https://github.com/aneoconsulting/tf-provider"
version = "0.1.0"

[workspace.dependencies]
anyhow = "1"
async-trait = "0.1"
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
tokio = "1.0"

[profile.release]
strip = "debuginfo"

[package]
name = "tf-provider"

description = "Plugin framework for Terraform and ToFu"
include = ["**/*.rs", "Cargo.toml", "LICENSE", "proto/*.proto"]

authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
version.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1"
async-stream = "0.3"
async-trait = "0.1"
base64 = "0.22"
futures = "0.3"
pem = "3.0"
prost = "0.12"
rcgen = "0.12.1"
rcgen = "0.12"
rmp-serde = "1.1"
serde = { version = "1.0", features = ["derive"] }
serde_bytes = "0.11"
serde_json = "1.0"
time = "0.3"
tokio = "1.0"
tokio-stream = { version = "0.1", features = ["net", "sync"] }
tokio-util = "0.7"
tonic = { version = "0.11", features = ["tls", "transport"] }
tower-http = { version = "0.4", features = ["trace"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["fmt", "json", "std"] }

anyhow.workspace = true
async-trait.workspace = true
serde.workspace = true
tokio.workspace = true

[build-dependencies]
tonic-build = "0.11"

[dev-dependencies]
rand = "0.8"
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@

use std::borrow::Cow;

use anyhow::Result;
use async_trait::async_trait;
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
use serde::{Deserialize, Serialize};

use tf_provider::{
map, Attribute, AttributeConstraint, AttributePath, AttributeType, Block, Description,
Diagnostics, Resource, Schema, ValueEmpty, ValueMap, ValueString,
map, serve, Attribute, AttributeConstraint, AttributePath, AttributeType, Block, Description,
Diagnostics, Provider, Resource, Schema, ValueEmpty, ValueMap, ValueString,
};

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
Expand Down Expand Up @@ -163,3 +164,63 @@ impl Resource for NullResource {
Some(())
}
}

#[derive(Debug, Default, Clone)]
pub struct NullProvider;

#[async_trait]
impl Provider for NullProvider {
type Config<'a> = ValueEmpty;
type MetaState<'a> = ValueEmpty;

fn schema(&self, _diags: &mut tf_provider::Diagnostics) -> Option<tf_provider::Schema> {
Some(Schema {
version: 1,
block: Block {
description: Description::plain("null"),
..Default::default()
},
})
}

async fn validate<'a>(
&self,
_diags: &mut tf_provider::Diagnostics,
_config: Self::Config<'a>,
) -> Option<()> {
Some(())
}

async fn configure<'a>(
&self,
_diags: &mut tf_provider::Diagnostics,
_terraform_version: String,
_config: Self::Config<'a>,
) -> Option<()> {
Some(())
}

fn get_resources(
&self,
_diags: &mut tf_provider::Diagnostics,
) -> Option<std::collections::HashMap<String, Box<dyn tf_provider::resource::DynamicResource>>>
{
Some(map! {
"resource" => NullResource,
})
}

fn get_data_sources(
&self,
_diags: &mut tf_provider::Diagnostics,
) -> Option<
std::collections::HashMap<String, Box<dyn tf_provider::data_source::DynamicDataSource>>,
> {
Some(map! {})
}
}

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<()> {
serve("null", NullProvider).await
}
18 changes: 0 additions & 18 deletions examples/terraform-provider-null/Cargo.toml

This file was deleted.

File renamed without changes.
28 changes: 0 additions & 28 deletions examples/terraform-provider-null/src/main.rs

This file was deleted.

76 changes: 0 additions & 76 deletions examples/terraform-provider-null/src/null_provider.rs

This file was deleted.

This file was deleted.

0 comments on commit 1e0be62

Please sign in to comment.