Skip to content

chore: loading plan.json with string indexs (for_each)#132

Merged
Emyrk merged 1 commit into
mainfrom
coder/plan_string_index
May 21, 2025
Merged

chore: loading plan.json with string indexs (for_each)#132
Emyrk merged 1 commit into
mainfrom
coder/plan_string_index

Conversation

@Emyrk
Copy link
Copy Markdown
Member

@Emyrk Emyrk commented May 21, 2025

When loading in values from a plan.json, loading maps and lists have to be merged with an existing hcl context.

Before this PR, only tuples were merged (integer indicies). This handles the map case.

Comment thread plan.go
Comment on lines +146 to +158
case string:
keyStr, ok := resource.Index.(string)
if !ok {
return fmt.Errorf("unable to convert index '%v' for %q to a string", resource.Name, resource.Index)
}

if !existing.CanIterateElements() {
continue
}

instances := existing.AsValueMap()
instances[keyStr] = val
merged = cty.ObjectVal(instances)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@@ -0,0 +1,236 @@
terraform {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is a larger test main.tf taken from https://registry.coder.com/modules/coder/jetbrains-gateway

I prefer it being a bit complicated like this 👍

@Emyrk Emyrk requested a review from jaaydenh May 21, 2025 21:05
@Emyrk Emyrk merged commit e6a60ff into main May 21, 2025
3 checks passed
@Emyrk Emyrk deleted the coder/plan_string_index branch May 21, 2025 21:21
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