Repository navigation
fix(aws): refuse MemoryDB, OpenSearch and Redshift offerings priced above the approved upfront - #616
Merged
Conversation
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.
Refs #53. Follows #611 (EC2) and #615 (RDS); mirrors their semantics for MemoryDB, OpenSearch and Redshift (one commit per service).
PurchaseCommitmentreads the resolved offering back by ID and refuses when upfront (FixedPricex count) exceeds the approvedCommitmentCostby 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 returnsExistingCommitmentsuccess (Redshift: afterguardAgainstRepurchase).Units, checked against the aws-sdk-go-v2 types:
ReservedNodesOffering.FixedPrice float64(memorydb@v1.31.4 types.go:576), per node (existing code multiplies byNodeCount). No currency field, so only the rec currency is checked, and there is no nil case (a missing price reads as 0).ReservedInstanceOffering.FixedPrice *float64(opensearch@v1.52.3 types.go:2372) withCurrencyCode *string(:2364), per instance (purchase takesInstanceCount).ReservedNodeOffering.FixedPrice *float64(redshift@v1.58.3 types.go:1791) withCurrencyCode *string(:1784), per node (existing code multiplies byNodeCount).UpfrontCostis 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.PurchaseCommitmentcomplexity was kept under the gocyclo limit by extractingreservationNameFor(OpenSearch) andreservedNodeTotal(Redshift).🤖 Generated with Claude Code
Summary by CodeRabbit