Skip to content

Conversation

@rmaynardap
Copy link
Contributor

The remote vars were still not being output as expected, even though it was valid JSON it is supposed to only output the "data" part, it was still outputting the entire results from the terraform output show command which is contrary to the expected design.

rmaynardap and others added 16 commits November 14, 2025 07:24
INF-6284: Properly represent simple output types
Bumps [werkzeug](https://github.com/pallets/werkzeug) from 3.1.3 to 3.1.4.
- [Release notes](https://github.com/pallets/werkzeug/releases)
- [Changelog](https://github.com/pallets/werkzeug/blob/main/CHANGES.rst)
- [Commits](pallets/werkzeug@3.1.3...3.1.4)

---
updated-dependencies:
- dependency-name: werkzeug
  dependency-version: 3.1.4
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [urllib3](https://github.com/urllib3/urllib3) from 2.5.0 to 2.6.0.
- [Release notes](https://github.com/urllib3/urllib3/releases)
- [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst)
- [Commits](urllib3/urllib3@2.5.0...2.6.0)

---
updated-dependencies:
- dependency-name: urllib3
  dependency-version: 2.6.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
This constant is no longer needed as we're simplifying the TF_REMOTE
flow to use only direct backend.get_state() access, removing the
terraform refresh/show cache mechanism entirely.

Part of unified environment variable handling improvements.
Major changes:
- Added _parse_tfvars_file() using python-hcl2 for proper type parsing
- Refactored _populate_environment_with_terraform_variables() to use HCL2 parser
- Updated _populate_environment_with_terraform_remote_vars() to add state caching
- Rewrote get_state_item() to use only backend.get_state() with caching support
- Deleted 10 helper functions (~300 lines):
  * _get_state_item_from_output (terraform output path)
  * _get_state_item_from_remote (complex wrapper)
  * _get_state_cache_name, _make_state_cache, _read_state_cache
  * _find_remote_state, _get_item_from_remote_state
  * _run_terraform_refresh, _run_terraform_show, _write_state_cache
- Removed redundant TF_EXTRA preprocessing from _set_hook_env_var()
- Updated type hints and docstrings

Benefits:
- Consistent format for all variable types (booleans → TRUE/FALSE, complex types → compact JSON)
- Simplified TF_REMOTE flow using only direct backend access
- Performance: state cache prevents multiple S3 downloads for same state
- More reliable: works with pre_init hooks and --limit flag
- Easier to understand and extend
- Add tests for _parse_tfvars_file() function (HCL2 parsing, fallback, errors)
- Add tests for simplified get_state_item() with backend.get_state()
- Add tests for state caching mechanism
- Add test for boolean handling in TF_VAR variables
- Update test for _populate_environment_with_terraform_variables to use new parsing
- Delete obsolete tests for removed fallback functions

Test coverage: 92% for hooks.py, all 502 tests passing
The function was incorrectly looking for terraform_remote_state resources
within the state file's resources section. When backend.get_state() is
called, it returns the raw Terraform state file which has outputs at the
top level, not nested under values.root_module.resources.

Changes:
- Simplified get_state_item() to read from top-level outputs section
- Updated tests to use actual state file format from backend.get_state()
- This fixes the "Remote state resource not found" error

The correct flow is now:
1. backend.get_state(state_name) returns the state file
2. Extract from state_data["outputs"][item_name]
3. Return the output in Terraform format: {"value": ..., "type": ...}
…setting

INF-6707: Hook environment variable improvements (consistency, speed & reduced complexity)
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.

1 participant