Skip to content

fix(aws): refuse MemoryDB, OpenSearch and Redshift offerings priced above the approved upfront - #616

Merged
cristim merged 5 commits into
mainfrom
fix/53-price-guard-memorydb-opensearch-redshift
Oct 25, 2026
Merged

cristim merged 5 commits into
mainfrom
fix/53-price-guard-memorydb-opensearch-redshift

Conversation

@cristim

@cristim cristim commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Refs #53. Follows #611 (EC2) and #615 (RDS); mirrors their semantics for MemoryDB, OpenSearch and Redshift (one commit per service).

PurchaseCommitment reads the resolved offering back by ID and refuses when upfront (FixedPrice x count) exceeds the approved CommitmentCost by more than 5%, when the rec or offering currency is non-USD (case-insensitive, empty means USD), or when the read fails, returns other than exactly one offering, or has no price. Zero approved cost and no-upfront purchases are not checked. The guard runs after the idempotency dedupe, so a re-drive of an existing commitment still returns ExistingCommitment success (Redshift: after guardAgainstRepurchase).

Units, checked against the aws-sdk-go-v2 types:

  • MemoryDB ReservedNodesOffering.FixedPrice float64 (memorydb@v1.31.4 types.go:576), per node (existing code multiplies by NodeCount). No currency field, so only the rec currency is checked, and there is no nil case (a missing price reads as 0).
  • OpenSearch ReservedInstanceOffering.FixedPrice *float64 (opensearch@v1.52.3 types.go:2372) with CurrencyCode *string (:2364), per instance (purchase takes InstanceCount).
  • Redshift ReservedNodeOffering.FixedPrice *float64 (redshift@v1.58.3 types.go:1791) with CurrencyCode *string (:1784), per node (existing code multiplies by NodeCount).
  • Cost Explorer UpfrontCost is documented as "How much purchasing this instance costs you upfront" (costexplorer@v1.63.1 types.go:1971); it is read as the total for the recommended count, the same assumption as the EC2 and RDS guards.

Tests per service cover: above +5% refused with no purchase, exactly +5% buys, lowercase usd buys, EUR on rec (and offering where the field exists) refused, zero cost unchecked, no-upfront unaffected, re-drive after a price rise succeeds, describe error, two and zero offerings, nil price (OpenSearch, Redshift). 41 mutants in a scratch copy were all killed. go test -race -count=1 ./... passes in providers/aws with GOWORK=off and with the workspace; golangci-lint v2.10.1 reports 0 issues. PurchaseCommitment complexity was kept under the gocyclo limit by extracting reservationNameFor (OpenSearch) and reservedNodeTotal (Redshift).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • MemoryDB, OpenSearch, and Redshift purchases are blocked when upfront costs exceed the approved amount by more than 5%, currency is unsupported, or the price cannot be verified.
    • MemoryDB purchases with upfront costs are blocked when the offering is zero-priced or the purchase is in a China region.
    • Non-finite approved upfront amounts are rejected across EC2, RDS, MemoryDB, OpenSearch, and Redshift.
    • Purchases at the 5% limit remain allowed. Existing reservations, zero approved upfront amounts, and purchases without upfront costs remain unaffected.

Loading
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