Skip to content

feat: property-level CFN drift MODIFIED for all drift-checkable types (#290) - #302

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/issue-290-drift-modified
Jun 2, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/issue-290-drift-modified

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Completes #290 — faithful property-level MODIFIED drift detection across all six drift-checkable CloudFormation resource types (S3 versioning shipped earlier; this adds the rest).

New comparators (cfnDriftComparators)

Type Properties compared
DynamoDB::Table BillingMode, ProvisionedThroughput.{Read,Write}CapacityUnits
Lambda::Function Runtime, Handler, Timeout, MemorySize
IAM::Role AssumeRolePolicyDocument (order-insensitive), Description, Path
SQS::Queue VisibilityTimeout, MessageRetentionPeriod, DelaySeconds, ReceiveMessageWaitTimeSeconds, MaximumMessageSize
SNS::Topic DisplayName

Design

  • Template-declared-only comparison: a property is checked only when the template explicitly declares it, so deploy-applied defaults (e.g. DynamoDB BillingMode→PROVISIONED) never produce false drift. The existing S3 versioning comparator was aligned to this rule (it previously emitted an ADD diff when the template omitted versioning).
  • All comparators reuse the existing compareS3BucketDrift pattern via a shared cfnDriftResourceProps helper (re-parse template → resolve intrinsics/params → read live state).
  • New policyDocumentsEqual (iam_policy_compare.go) compares trust policies independent of statement order (canonical per-statement JSON, sorted), so a reordered-but-equivalent policy does not register as drift.
  • To make SQS/SNS comparable (their deploy paths were name-only), deploySQSQueue/deploySNSTopic now forward declared properties, and SNS CreateTopic persists an initial DisplayName (AWS-faithful).

Latent bugs fixed en route

  • SQS, SNS, and Lambda existence drift-checkers used wrong state keys (spurious /region/ component; SNS used the ARN where the key is name-based) — so those checkers were silently broken.
  • deployLambdaFunction sent Timeout/MemorySize as strings, which CreateFunction (int fields) rejected with "invalid request body" — CFN Lambda with these properties never deployed. Now converted to int.

Tests

One MODIFIED case per type (mutate live state outside CFN → assert MODIFIED + PropertyDifferences), plus a reordered-trust-policy IN_SYNC case (no false positive) and a declared-only IN_SYNC case (undeclared property diverging in state → not drift). Test harness extended to register DynamoDB/Lambda/SQS.

make test (race) + make lint clean; main-pkg coverage steady at ~79.5%. AWS property names/shapes verified against the CloudFormation resource references.

Closes #290

…#290)

Extends cfnDriftComparators with comparators for DynamoDB (BillingMode,
ProvisionedThroughput), Lambda (Runtime/Handler/Timeout/MemorySize), IAM Role
(AssumeRolePolicyDocument via order-insensitive policyDocumentsEqual, plus
Description/Path), SQS (queue attributes), and SNS (DisplayName) — completing
S3 versioning shipped earlier. Comparison is template-declared-only so deploy
defaults never produce false drift; S3 comparator aligned to the same rule.

To make SQS/SNS comparable: deploySQSQueue/deploySNSTopic forward declared
properties; SNS CreateTopic persists initial DisplayName.

Fixes latent bugs found en route:
- SQS/SNS/Lambda existence drift-checkers used wrong state keys (spurious
  region component / ARN-vs-name).
- deployLambdaFunction sent Timeout/MemorySize as strings → CreateFunction
  rejected the body (CFN Lambda Timeout/MemorySize never worked).

New: iam_policy_compare.go (policyDocumentsEqual). Tests: one MODIFIED case per
type + reordered-policy IN_SYNC + declared-only IN_SYNC. make test (race)+lint clean.

Closes #290
@scttfrdmn
scttfrdmn merged commit cea947b into main Jun 2, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the feat/issue-290-drift-modified branch June 2, 2026 21:05
@codecov

codecov Bot commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.73684% with 67 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
betty_cfn.go 65.26% 33 Missing and 25 partials ⚠️
iam_policy_compare.go 57.14% 5 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

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.

CloudFormation drift detection

1 participant