Skip to content

feat: support Terraform path references - #9

Open
SulimanAbdulrazzaq wants to merge 4 commits into
ops0-ai:mainfrom
SulimanAbdulrazzaq:fix/path-references
Open

SulimanAbdulrazzaq wants to merge 4 commits into
ops0-ai:mainfrom
SulimanAbdulrazzaq:fix/path-references

Conversation

@SulimanAbdulrazzaq

@SulimanAbdulrazzaq SulimanAbdulrazzaq commented Aug 9, 2026 •

Copy link
Copy Markdown

Summary

Refs #5.

  • thread Terraform path values (path.module, path.root, and path.cwd) and the workspace name into the evaluation context used by plan, apply, destroy, and output evaluation
  • expose terraform.workspace as the active workspace's name (for example default), not its state store id
  • add focused expression regression tests, plus a CLI test that applies output "workspace" { value = terraform.workspace } and checks the stored output

Not covered yet: path.* still resolves to an empty string during count/for_each expansion, provider configuration, variable defaults, and drift address expansion. The built-in functions listed in the audit in #5 (file(), templatefile(), and others) are left for separate issues, as that proposal suggests.

Validation

Run at 696743c in a Linux Codespace (rustc 1.98.1, protoc 3.21.12):

  • cargo fmt --all -- --check: clean
  • cargo test: 123 passed, 0 failed, 21 ignored (the e2e suite)
  • cargo test --test path_references_test: 4 passed; the new CLI test fails on the previous head, where the output is the workspace UUID instead of default
  • cargo clippy --all-targets -- -D warnings: fails only on clippy::for_kv_map in src/main.rs, which fails the same way on main (1f335eb); with that lint allowed, clippy passes with no warnings

Not run: the ignored e2e tests, which download providers.

@chaitanya-sistla

chaitanya-sistla commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

@SulimanAbdulrazzaq this is for #5 ?

The CLI passed the state store workspace id, a generated UUID, as the
terraform.workspace value, so expressions saw the UUID instead of the
workspace name that Terraform returns (for example "default").

Keep the workspace name on the engine next to the path values and use it
when evaluating plan, apply, destroy, and output expressions. State reads
and writes still use the workspace id.

Add a CLI regression test that applies a configuration whose output is
terraform.workspace and checks the stored value.
@SulimanAbdulrazzaq

Copy link
Copy Markdown
Author

@chaitanya-sistla yes, this is for #5, following the implementation proposal there.

  • It resolves path.module, path.root, and path.cwd for plan, apply, destroy, and output evaluation.
  • While re-checking it I found that terraform.workspace returned the state store's workspace id (a UUID) rather than the workspace name. 696743c fixes that so it returns the name, for example default, and adds a CLI regression test.
  • Not covered yet: path.* during count/for_each expansion, provider configuration, variable defaults, and drift address expansion, plus the built-in functions from the audit in Missing path.module and other Terraform path references #5, which the proposal leaves for separate issues.

Because of those gaps I changed Closes #5 to Refs #5. I can extend this PR to those sites if you'd prefer that.

Validation at 696743c: cargo test 123 passed (21 e2e ignored), cargo fmt --check clean. cargo clippy --all-targets -- -D warnings fails only on an existing clippy::for_kv_map lint that also fails on main.

@SulimanAbdulrazzaq

Copy link
Copy Markdown
Author

@chaitanya-sistla could you approve the CI workflow on this one when you have a moment? As I confirmed above, it's for #5: path.module, path.root and path.cwd now resolve in plan, apply, destroy and output evaluation, and terraform.workspace returns the workspace name instead of its id. CI is waiting for approval, and the branch has no conflicts.

@chaitanya-sistla

Copy link
Copy Markdown
Contributor

approved @SulimanAbdulrazzaq

@SulimanAbdulrazzaq

Copy link
Copy Markdown
Author

@chaitanya-sistla thanks for the approval! I pushed 4a6fd1d to get CI green:

  • Clippy was failing on existing code, not on this PR's changes: for (_name, (source, version_constraint)) in &providers_to_download in src/main.rs (for_kv_map in newer clippy). It now iterates providers_to_download.values(), a one-line change with the same behaviour. With it, Clippy, Check, Format, Test and Build all pass.
  • Security Audit still fails, because of advisories published after the last green run on main: h2 (RUSTSEC-2026-0258), quinn-proto (RUSTSEC-2026-0185) and rustls (RUSTSEC-2026-0285). They come from the lockfile, not from this change, and h2 0.3 has no fixed 0.3 release, so fixing it needs dependency upgrades. I'm happy to do that in a separate PR if you'd like.

@SulimanAbdulrazzaq

Copy link
Copy Markdown
Author

@chaitanya-sistla when you have a moment, could one of you approve the workflow runs and take a look at this one? No checks have run on the current head yet.

@chaitanya-sistla

Copy link
Copy Markdown
Contributor

@SulimanAbdulrazzaq done

@chaitanya-sistla

Copy link
Copy Markdown
Contributor

@chaitanya-sistla when you have a moment, could one of you approve the workflow runs and take a look at this one? No checks have run on the current head yet.

@SulimanAbdulrazzaq we might have to cut a release for 0.4.5

@chaitanya-sistla

Copy link
Copy Markdown
Contributor

@SulimanAbdulrazzaq security and clippy failed.

… lint

async-trait 0.1.89 generates a #[must_use] on its boxed futures, which newer
clippy rejects (dtolnay/async-trait#303); 0.1.92 drops it. Only the lockfile
changes; syn 3 is added because async-trait 0.1.91 moved to it.
@SulimanAbdulrazzaq

Copy link
Copy Markdown
Author

@chaitanya-sistla thanks for re-running it.

Clippy: it failed on src/state/backend.rs (33 double_must_use errors). They come from code generated by async-trait 0.1.89, which the clippy of Rust 1.99 now rejects (dtolnay/async-trait#303); async-trait 0.1.92 fixes it. I pushed e526b1e, which only bumps that entry in Cargo.lock (it also adds syn 3, which 0.1.92 depends on). On a CI run in my fork with the current stable toolchain (Rust 1.99.1), cargo clippy --all-targets -- -D warnings, cargo fmt --all -- --check and cargo test --release pass.

Security Audit: it still fails, and not because of this PR: Cargo.lock is the same as on main, which has 19 advisories now (h2, quinn-proto, rustls, rustls-webpki, webpki-roots, zip, ...). Running cargo update on a copy brings that down to 7; the rest need dependency upgrades (for example the zip advisories need zip >= 9.0.0). I left the lockfile alone so this PR stays about path references. If you want the in-range updates, I can open a separate PR with just cargo update.

@chaitanya-sistla

Copy link
Copy Markdown
Contributor

@SulimanAbdulrazzaq i triggered again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants