fix(outputs): use one() for conditional resource outputs#240
Open
Miguel Lemos (miguelslemos) wants to merge 5 commits intobraintrustdata:mainfrom
Open
fix(outputs): use one() for conditional resource outputs#240Miguel Lemos (miguelslemos) wants to merge 5 commits intobraintrustdata:mainfrom
Miguel Lemos (miguelslemos) wants to merge 5 commits intobraintrustdata:mainfrom
Conversation
Replace direct [0] indexing on count-gated resources with the one() function in modules/services and modules/brainstore-ec2 outputs. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
fix(outputs): use one() for conditional resource outputs
Replace direct [0] indexing on count-gated resources with the one()
fix(outputs): use one() for conditional resource outputs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace direct
[0]indexing oncount-gated resources with theone()function in two module outputs:modules/services/outputs.tf—quarantine_warmup_arnmodules/brainstore-ec2/outputs.tf—writer_dns_nameProblem
Both outputs use the standard Terraform idiom of pairing a
countgate with a ternary that indexes[0]:This works fine under plain
terraform plan/applybecause the gate is a concretebooland the ternary short-circuits —[0]is never evaluated when the gate isfalse.It fails at plan time when the module is consumed by pulumi/pulumi-terraform-module. Pulumi inputs cross into OpenTofu as values that may be unknown until apply during
pulumi preview. When the gate is unknown, OpenTofu evaluates both branches of the ternary and indexes into acount = 0tuple, producing:This is a known rough edge with conditional
countresources whose outputs use[0](see hashicorp/terraform#23222 and the HashiCorp support note).Fix
one(resource[*].attr)is the idiomatic Terraform helper for "0-or-1 resource": it returnsnullwhen the splat is empty and the value when there's exactly one. It's safe to evaluate eagerly, so it doesn't blow up when the count tuple is empty.Behavior is unchanged for all existing terraform consumers (still
nullwhen the resource isn't created, the attribute when it is) and the module now plans cleanly under pulumi-terraform-module preview as well.