Skip to content

Add ResourceBase fields to labeled block CTY values - #13

Open
victorfrederiknielsen wants to merge 1 commit into
mainfrom
feature/labeled-block-access
Open

Add ResourceBase fields to labeled block CTY values#13
victorfrederiknielsen wants to merge 1 commit into
mainfrom
feature/labeled-block-access

Conversation

@victorfrederiknielsen

Copy link
Copy Markdown

Summary

Add meta, disabled, and depends_on fields to labeled block element CTY representations. This enables labeled block references (e.g., resource.aws_account.sandbox.user.admin) to be decoded into []types.ResourceBase fields, completing the round-trip for HCL configurations that reference labeled blocks.

Changes

Core CTY Conversion (convert/convert.go)

  • Pass parent resource ID to transformLabeledBlocks to build element reference paths
  • Rename elementToCty to elementToCtyWithMeta and populate ResourceBase fields:
    • meta.id with the full reference path (e.g., resource.aws_account.sandbox.user.admin)
    • disabled as false
    • depends_on as empty list
  • Use gocty.ToCtyValue for clean meta struct conversion instead of manual CTY construction
  • Add addLabelFieldToCtyMap helper to include label field values in CTY output

Tests

  • Add TestLabeledBlockCtyStructure to verify CTY includes meta/disabled/depends_on fields
  • Add TestLabeledBlockReferenceSlice to test slice references like members = [resource...user.admin]
  • Add TestLabeledBlockResourceBaseSlice to verify full round-trip with actual types
  • Consolidate test fixtures into valid.hcl for consistency
  • Add CloudTeam and CloudCredentials test structs

Test Fixtures

  • Update cloud_account.go Name field tag to hcl:"name,label" for proper decoding
  • Add cloud_team.go with Members/Lead fields for slice reference tests

Testing Strategy

  • All labeled block tests pass (TestLabeledBlock*)
  • CTY structure test verifies meta/disabled/depends_on presence
  • Slice reference tests verify whole-object references work
  • Both named and numeric index access patterns tested

Enable labeled block references to be decoded into []types.ResourceBase
by including meta, disabled, and depends_on fields in the CTY representation.

Changes:
- Add elementToCtyWithMeta function to include ResourceBase fields
- Use gocty.ToCtyValue for clean meta generation instead of manual CTY
- Add label field to CTY map via addLabelFieldToCtyMap helper
- Add comprehensive tests for labeled block slice references
- Consolidate test fixtures into valid.hcl for consistency
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