Skip to content

Commit

Permalink
Fix AttributePath
Browse files Browse the repository at this point in the history
  • Loading branch information
lemaitre-aneo committed Jun 16, 2024
1 parent b4cba8e commit 3e97c55
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion examples/terraform-provider-null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ impl Resource for NullResource {
Vec<tf_provider::AttributePath>,
)> {
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))
Expand Down
19 changes: 16 additions & 3 deletions src/attribute_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@ impl AttributePath {
///
/// # Arguments
///
/// * `root` - Name of the root attribute
pub fn new<T: Into<Cow<'static, str>>>(root: T) -> Self {
/// * `name` - Name of the root attribute
pub fn new<T: Into<Cow<'static, str>>>(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
Expand All @@ -55,6 +61,7 @@ impl AttributePath {
steps: vec![AttributePathStep::Index(index)],
}
}

/// Create a new attribute path where the attribute `.name` has been appended
///
/// # Arguments
Expand All @@ -64,6 +71,7 @@ impl AttributePath {
self.add_attribute(name);
self
}

/// Create a new attribute path where the access `["key"]` has been appended
///
/// # Arguments
Expand All @@ -73,6 +81,7 @@ impl AttributePath {
self.add_key(key);
self
}

/// Create a new attribute path where the access `[idx]` has been appended
///
/// # Arguments
Expand All @@ -92,6 +101,7 @@ impl AttributePath {
self.steps.push(AttributePathStep::Attribute(name.into()));
self
}

/// add key access to the path (ie: `["key"]`)
///
/// # Arguments
Expand All @@ -101,6 +111,7 @@ impl AttributePath {
self.steps.push(AttributePathStep::Key(key.into()));
self
}

/// add index access to the path (ie: `[idx]`)
///
/// # Arguments
Expand All @@ -110,6 +121,7 @@ impl AttributePath {
self.steps.push(AttributePathStep::Index(idx.into()));
self
}

/// Add step to the path
///
/// # Arguments
Expand All @@ -119,6 +131,7 @@ impl AttributePath {
self.steps.push(step);
self
}

/// Add multiple steps into the path
///
/// # Arguments
Expand Down

0 comments on commit 3e97c55

Please sign in to comment.