From b4cba8e7cb53c15cb2bb4a4c9db57cd23c687ce7 Mon Sep 17 00:00:00 2001 From: Florian Lemaitre Date: Mon, 17 Jun 2024 00:22:54 +0200 Subject: [PATCH 1/3] Update versions --- Cargo.lock | 42 +++++++++++++++++++++--------------------- Cargo.toml | 2 +- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 064fcca..0e174f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -118,9 +118,9 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.72" +version = "0.3.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17c6a35df3749d2e8bb1b7b21a976d82b15548788d2735b9d82f329268f71a11" +checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" dependencies = [ "addr2line", "cc", @@ -169,9 +169,9 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "cc" -version = "1.0.98" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" [[package]] name = "cfg-if" @@ -401,9 +401,9 @@ checksum = "add0ab9360ddbd88cfeb3bd9574a1d85cfdfa14db10b3e21d3700dbc4328758f" [[package]] name = "httparse" -version = "1.8.0" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" +checksum = "d0e7a4dd27b9476dc40cb050d3632d3bba3a70ddbff012285f7f8559a1e7e545" [[package]] name = "httpdate" @@ -413,9 +413,9 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hyper" -version = "0.14.28" +version = "0.14.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" +checksum = "f361cde2f109281a220d4307746cdfd5ee3f410da58a70377762396775634b33" dependencies = [ "bytes", "futures-channel", @@ -514,9 +514,9 @@ checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" [[package]] name = "memchr" -version = "2.7.2" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "mime" @@ -577,9 +577,9 @@ dependencies = [ [[package]] name = "object" -version = "0.35.0" +version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8ec7ab813848ba4522158d5517a6093db1ded27575b070f4177b8d12b41db5e" +checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434" dependencies = [ "memchr", ] @@ -684,9 +684,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.84" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" dependencies = [ "unicode-ident", ] @@ -797,9 +797,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.4" +version = "1.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" dependencies = [ "aho-corasick", "memchr", @@ -809,9 +809,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" dependencies = [ "aho-corasick", "memchr", @@ -820,9 +820,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "ring" @@ -1050,7 +1050,7 @@ dependencies = [ [[package]] name = "tf-provider" -version = "0.2.0-beta-0" +version = "0.2.0" dependencies = [ "anyhow", "async-stream", diff --git a/Cargo.toml b/Cargo.toml index 803a668..077894b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ license = "Apache-2.0" readme = "README.md" name = "tf-provider" repository = "https://github.com/aneoconsulting/tf-provider" -version = "0.2.0-beta-0" +version = "0.2.0" [profile.release] strip = "debuginfo" From 3e97c55864d5d7f59a3b68ca401465fc8b77c849 Mon Sep 17 00:00:00 2001 From: Florian Lemaitre Date: Mon, 17 Jun 2024 00:23:05 +0200 Subject: [PATCH 2/3] Fix AttributePath --- examples/terraform-provider-null.rs | 3 ++- src/attribute_path.rs | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/examples/terraform-provider-null.rs b/examples/terraform-provider-null.rs index 3e58a9a..d5d5b64 100644 --- a/examples/terraform-provider-null.rs +++ b/examples/terraform-provider-null.rs @@ -109,8 +109,9 @@ impl Resource for NullResource { Vec, )> { let mut trigger_replace = Vec::new(); + if proposed_state.triggers != prior_state.triggers { - trigger_replace.push(AttributePath::new("root")); + trigger_replace.push(AttributePath::new("triggers")); } Some((proposed_state, prior_private_state, trigger_replace)) diff --git a/src/attribute_path.rs b/src/attribute_path.rs index 5e960b1..2a7268b 100644 --- a/src/attribute_path.rs +++ b/src/attribute_path.rs @@ -39,12 +39,18 @@ impl AttributePath { /// /// # Arguments /// - /// * `root` - Name of the root attribute - pub fn new>>(root: T) -> Self { + /// * `name` - Name of the root attribute + pub fn new>>(name: T) -> Self { Self { - steps: vec![AttributePathStep::Attribute(root.into())], + steps: vec![AttributePathStep::Attribute(name.into())], } } + + /// Create a new attribute path without any path component + pub fn root() -> Self { + Self::default() + } + /// Create a new attribute path for a function argument /// /// # Arguments @@ -55,6 +61,7 @@ impl AttributePath { steps: vec![AttributePathStep::Index(index)], } } + /// Create a new attribute path where the attribute `.name` has been appended /// /// # Arguments @@ -64,6 +71,7 @@ impl AttributePath { self.add_attribute(name); self } + /// Create a new attribute path where the access `["key"]` has been appended /// /// # Arguments @@ -73,6 +81,7 @@ impl AttributePath { self.add_key(key); self } + /// Create a new attribute path where the access `[idx]` has been appended /// /// # Arguments @@ -92,6 +101,7 @@ impl AttributePath { self.steps.push(AttributePathStep::Attribute(name.into())); self } + /// add key access to the path (ie: `["key"]`) /// /// # Arguments @@ -101,6 +111,7 @@ impl AttributePath { self.steps.push(AttributePathStep::Key(key.into())); self } + /// add index access to the path (ie: `[idx]`) /// /// # Arguments @@ -110,6 +121,7 @@ impl AttributePath { self.steps.push(AttributePathStep::Index(idx.into())); self } + /// Add step to the path /// /// # Arguments @@ -119,6 +131,7 @@ impl AttributePath { self.steps.push(step); self } + /// Add multiple steps into the path /// /// # Arguments From ca2c33e263417f05f1e4e9423732a02f8f689590 Mon Sep 17 00:00:00 2001 From: Florian Lemaitre Date: Mon, 17 Jun 2024 00:29:33 +0200 Subject: [PATCH 3/3] Clarify resource doc --- src/resource.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/resource.rs b/src/resource.rs index 8c23274..f39525d 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -174,8 +174,8 @@ pub trait Resource: Send + Sync { /// /// # Remarks /// - /// The return is ignored if there is an error in diagnostics. /// If the return is [`None`], an ad-hoc error is added to diagnostics. + /// Return must be [`Some`] if the resource was created, even if there was errors while creating the resource. async fn create<'a>( &self, diags: &mut Diagnostics, @@ -198,8 +198,8 @@ pub trait Resource: Send + Sync { /// /// # Remarks /// - /// The return is ignored if there is an error in diagnostics. - /// If the return is [`None`], an ad-hoc error is added to diagnostics. + /// If the return is [`None`], an ad-hoc error is added to diagnostics, and the resource state is kept unchanged. + /// Return must be [`Some`] if the resource was updated, even if there was errors while updated the resource. async fn update<'a>( &self, diags: &mut Diagnostics, @@ -240,8 +240,8 @@ pub trait Resource: Send + Sync { /// /// # Remarks /// - /// The return is ignored if there is an error in diagnostics. /// If the return is [`None`], an ad-hoc error is added to diagnostics. + /// Return must be [`Some`] if the resource was imported, even if there was errors while importing the resource. async fn import<'a>( &self, diags: &mut Diagnostics, @@ -262,8 +262,11 @@ pub trait Resource: Send + Sync { /// /// # Remarks /// - /// The return is ignored if there is an error in diagnostics. - /// If the return is [`None`], an ad-hoc error is added to diagnostics. + /// If the return is [`None`], an ad-hoc error is added to diagnostics, and the resource state is kept unchanged. + /// Return must be [`Some`] if the resource was upgraded, even if there was errors while upgraded the resource. + /// + /// Because the schema of the resource might have changed, + /// the prior state must be deserialized explicitely. async fn upgrade<'a>( &self, diags: &mut Diagnostics, @@ -411,8 +414,8 @@ pub trait DynamicResource: Send + Sync { /// /// # Remarks /// - /// The return is ignored if there is an error in diagnostics. /// If the return is [`None`], an ad-hoc error is added to diagnostics. + /// Return must be [`Some`] if the resource was created, even if there was errors while creating the resource. async fn create( &self, diags: &mut Diagnostics, @@ -435,8 +438,8 @@ pub trait DynamicResource: Send + Sync { /// /// # Remarks /// - /// The return is ignored if there is an error in diagnostics. - /// If the return is [`None`], an ad-hoc error is added to diagnostics. + /// If the return is [`None`], an ad-hoc error is added to diagnostics, and the resource state is kept unchanged. + /// Return must be [`Some`] if the resource was updated, even if there was errors while updated the resource. async fn update( &self, diags: &mut Diagnostics, @@ -477,8 +480,8 @@ pub trait DynamicResource: Send + Sync { /// /// # Remarks /// - /// The return is ignored if there is an error in diagnostics. /// If the return is [`None`], an ad-hoc error is added to diagnostics. + /// Return must be [`Some`] if the resource was imported, even if there was errors while importing the resource. async fn import(&self, diags: &mut Diagnostics, id: String) -> Option<(RawValue, Vec)> { _ = id; diags.root_error_short("Import is not supported"); @@ -495,8 +498,8 @@ pub trait DynamicResource: Send + Sync { /// /// # Remarks /// - /// The return is ignored if there is an error in diagnostics. - /// If the return is [`None`], an ad-hoc error is added to diagnostics. + /// If the return is [`None`], an ad-hoc error is added to diagnostics, and the resource state is kept unchanged. + /// Return must be [`Some`] if the resource was upgraded, even if there was errors while upgraded the resource. async fn upgrade( &self, diags: &mut Diagnostics,