tf_provider/
lib.rs

1// This file is part of the tf-provider project
2//
3// Copyright (C) ANEO, 2024-2024. All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License")
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9//     http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17//! Terraform provider library
18//!
19//! It enables to write your own TF provider that is supported by both Terraform and OpenTofu.
20//!
21//! Implementing a provider consists in implementing the [`Resource`], [`DataSource`], and/or [`Function`] traits,
22//! and implementing the [`Provider`] trait that references the resources, data sources and functions.
23
24mod attribute_path;
25mod data_source;
26mod diagnostics;
27mod function;
28mod plugin;
29mod provider;
30mod raw;
31mod resource;
32mod server;
33mod tf6provider;
34mod utils;
35
36pub mod schema;
37pub mod value;
38
39mod tfplugin6 {
40    tonic::include_proto!("tfplugin6");
41}
42
43pub use attribute_path::{AttributePath, AttributePathStep};
44pub use data_source::{DataSource, DynamicDataSource};
45pub use diagnostics::{Diagnostic, Diagnostics};
46pub use function::{DynamicFunction, Function};
47pub use provider::{DynamicProvider, Provider};
48pub use resource::{DynamicResource, Resource};
49pub use server::{serve, serve_dynamic};
50
51#[macro_export]
52/// Build a hash map
53///
54/// # Examples
55///
56/// ```
57/// # use tf_provider::map;
58/// # use std::collections::HashMap;
59/// let m: HashMap<String, String> = map!{
60///     "key1" => "value1",
61///     "key2" => "value2",
62/// };
63/// ```
64///
65/// # Remarks
66///
67/// Keys and Values are converted with [`Into::into`] to build the map.
68/// Because of that, type annotations are usually required.
69macro_rules! map {
70    {$($key:expr => $value:expr),*} => {
71        {
72            let mut map = std::collections::HashMap::default();
73            $(
74                map.insert($key.into(), $value.into());
75            )*
76            map
77        }
78    };
79
80    {$($key:expr => $value:expr),+ ,} => { map!{$($key => $value),+} };
81}