Skip to content

INF-7036: support nested remote_var structures and bracket notation - #172

Open
rmaynardap wants to merge 1 commit into
ephur:masterfrom
affinipay:rm/INF-7036/allow_building_remote_var_types
Open

INF-7036: support nested remote_var structures and bracket notation#172
rmaynardap wants to merge 1 commit into
ephur:masterfrom
affinipay:rm/INF-7036/allow_building_remote_var_types

Conversation

@rmaynardap

Copy link
Copy Markdown
Contributor

Add support for nested structures (dicts/lists) in remote_vars configuration, enabling more flexible Terraform remote state references.

Note to reviewers: This diff is fairly large, but a significant amount of it is the lockfile dependency changes (routine minor version updates to libraries), and tests, which provide comprehensive coverage and include edge cases.

Key changes:

  • New tfworker/util/remote_vars.py module for parsing/validation
  • Support nested keys: state.outputs.key.nested["item"]
  • Generate proper HCL for dict/list structures in definitions
  • Recursively resolve nested remote state values in hooks
  • Add HCL2 parsing with regex fallback for backwards compatibility
  • Check environment variable sizes and warn about shell limits

Additional improvements:

  • Better AWS authentication error handling in S3 backend (TokenRetrievalError, NoCredentialsError, PartialCredentialsError)
  • Comprehensive test coverage (126 tests, parameterized for maintainability)

This allows configurations like:

  remote_vars:
    kubernetes_clusters:
      prod: clusters.outputs.items["prod-cluster"]
    vpcs:
      platform: network.outputs

Copilot AI review requested due to automatic review settings June 25, 2026 19:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends remote_vars to support nested structures (dicts/lists) and bracket/dot notation paths, enabling more flexible Terraform remote state references throughout generated locals and hook environment variables.

Changes:

  • Introduces tfworker/util/remote_vars.py for parsing/validation helpers and remote state extraction.
  • Updates locals generation and hook env population to handle nested remote_vars via recursive HCL generation and HCL2 parsing with regex fallback.
  • Improves S3 backend initialization error reporting for common AWS authentication failures; adds comprehensive tests and routine dependency lockfile updates.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tfworker/util/remote_vars.py New helpers for parsing remote var references, generating TF refs, and extracting state names recursively.
tfworker/util/hooks.py Adds HCL2-based locals parsing and recursive resolution of remote state references; adds env var size warnings.
tfworker/definitions/prepare.py Generates nested HCL for remote_vars values and extracts remotes recursively.
tfworker/definitions/model.py Expands remote_vars schema type to allow dict/list structures.
tfworker/backends/s3.py Wraps common AWS auth failures into clearer BackendError messages.
tests/util/test_util_remote_vars.py Unit tests for the new remote_vars parsing/extraction/validation helpers.
tests/util/test_util_hooks.py Tests nested locals resolution, HCL2 fallback behavior, and env var size warnings.
tests/definitions/test_definitions_prepare_extra.py Tests locals generation and remote extraction with nested remote_vars structures.
tests/backends/test_backends_s3.py Tests new S3 auth error handling paths.
poetry.lock Routine minor dependency version bumps.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tfworker/util/hooks.py
Comment on lines +488 to +494
else:
# Return specific output value
if output_key not in outputs:
raise HookError(
f"Output '{output_key}' not found in state '{state}'"
)
return outputs[output_key].get("value")
Comment on lines +98 to +100
# Generate Terraform HCL for the value (handles str/dict/list)
tf_value = self._generate_tf_value(v, indent=1)
tflocals.write(f" {k} = {tf_value}\n")
lines = ["{"]
for key, val in value.items():
nested_value = self._generate_tf_value(val, indent + 1)
lines.append(f'{" " * (indent + 1)}"{key}" = {nested_value}')
@rmaynardap
rmaynardap force-pushed the rm/INF-7036/allow_building_remote_var_types branch from 4ae9f5c to 07b12a2 Compare June 25, 2026 20:26
Add support for nested structures (dicts/lists) in remote_vars configuration,
enabling more flexible Terraform remote state references.

Key changes:
- New tfworker/util/remote_vars.py module for parsing/validation
- Support nested keys: state.outputs.key.nested["item"]
- Generate proper HCL for dict/list structures in definitions
- Recursively resolve nested remote state values in hooks
- Add HCL2 parsing with regex fallback for backwards compatibility
- Check environment variable sizes and warn about shell limits

Additional improvements:
- Better AWS authentication error handling in S3 backend
  (TokenRetrievalError, NoCredentialsError, PartialCredentialsError)
- Comprehensive test coverage (126 tests, parameterized for maintainability)

This allows configurations like:
```yaml
  remote_vars:
    kubernetes_clusters:
      prod: clusters.outputs.items["prod-cluster"]
    vpcs:
      platform: network.outputs
```
@rmaynardap
rmaynardap force-pushed the rm/INF-7036/allow_building_remote_var_types branch from 07b12a2 to a39a625 Compare June 25, 2026 21:08
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.

3 participants