Skip to content

Tag Terraform-created resources for AWS Partner Revenue Measurement - #133

Merged
drernie merged 2 commits into
mainfrom
prm-tag
Nov 12, 2026
Merged

drernie merged 2 commits into
mainfrom
prm-tag

Conversation

@drernie

@drernie drernie commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

The need

Closes #132. On a Terraform-managed stack the VPC, database and search domain are created by this repository's modules, not by the CloudFormation template, so AWS Partner Revenue Measurement (PRM) attribution for them has to come from the module. Every resource the module creates is to carry aws-apn-id-730278974607 = "pc:<product code>" by default, with pay-as-you-go's product code unless the caller sets another. The CloudFormation template tags the stack's own resources (https://github.com/quiltdata/deployment/pull/3271), so the stack itself is left untagged here, and the key has one writer per resource. No IAM or permission change is part of it.

What changed

  • New quilt module variable marketplace_product_code, default 1xn1f7bxkj2dc16ak28s0dbgk (pay-as-you-go). The module tags the template bucket and object and everything in the vpc, db and search submodules with aws-apn-id-730278974607 = "pc:<code>". It does not tag the CloudFormation stack, whose tags CloudFormation would also copy onto the template's resources, which the template tags itself.
  • The variable takes the bare code: a value with the pc: prefix, such as a pasted tag value, fails at plan.
  • An empty marketplace_product_code omits the tag. I chose to allow this so that a stack that must not carry the attribution can drop it without forking the module.
  • vpc, db and search gain a tags input (default {}), passed to every registry module and resource they use. The Transit Gateway attachment merges it with its existing Name tag rather than replacing it.
  • README: the template tags the stack's resources and this module the resources it creates; to keep one value across both, set marketplace_product_code to the template variant's code (pay-as-you-go by default on both sides); do not put the key in provider default_tags, which also reach the CloudFormation stack. VARIABLES.md and the CHANGELOG release notice match.

Verification

  • terraform fmt -check -recursive, terraform validate in every module, terraform test in modules/vpc and modules/quilt/tests/smoke, and markdownlint-cli2 all pass locally, as in CI. The smoke tests pin that the stack carries no partner tag and that a pc:-prefixed code is rejected. The vpc test pins the Transit Gateway attachment carrying both the tag and its Name.
  • The mocked tests cannot reach resources nested in submodules, so the tag on them is verified by plan. I ran read-only terraform plan -lock=false of the nightly root (an existing stack with a database, a search domain and a new VPC) against this branch, at the default code, at f5d6l3y7x2yy2fcm0uxr9gglh and at "". Each shows 0 to add and 0 to destroy, with nothing replaced and the stack carrying no partner tag. At a code, all 31 taggable resources the module creates carry pc:<that code>; at "" none does. For the database, search and VPC resources, tags/tags_all are the only attributes that change. With marketplace_product_code = "pc:1xn1f7bxkj2dc16ak28s0dbgk" the plan fails on the variable's validation.

Links

Risk and rollback

  • A stack whose template predates https://github.com/quiltdata/deployment/pull/3271 gets the tag only on the resources this module creates, not on the stack's own resources, until its template is upgraded.
  • A template variant carrying a code other than pay-as-you-go's, with marketplace_product_code left at its default, attributes the module's resources to pay-as-you-go and the stack's to its own listing. The README tells callers to set the variable to match.
  • Rollback: set marketplace_product_code = "" or pin the previous module version; either removes the tag in place.

The optionality note

This fixes the tag's account (Quilt's Partner Central account) in the module, and gives callers only the product code to choose. The module still has no general tags input; the new submodule tags inputs leave that door open.

🤖 Generated with Claude Code

Tag the CloudFormation stack and every resource the quilt module creates
with aws-apn-id-730278974607 = "pc:<code>", the code set by
marketplace_product_code (default: pay-as-you-go). Closes #132.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 11, 2026 22:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The documented deployment policy lacks the S3 tagging permissions required by the new defaults, causing apply to fail with AccessDenied for callers using that policy.

1 open issue
What changed in this PR

Adds default AWS Partner Revenue Measurement attribution to Terraform-managed Quilt stacks, covering infrastructure created outside CloudFormation.

Changes:

  • Adds a configurable Marketplace product code, defaulting to pay-as-you-go, with an empty-string opt-out.
  • Passes attribution tags through the Quilt, VPC, database, and search modules.
  • Adds tag assertions and documents configuration and upgrade behavior.
File Description
VARIABLES.md Documents the product code and submodule tag inputs.
README.md Explains attribution, overrides, and opt-out behavior.
modules/​vpc/​variables.tf Adds the VPC module’s tag input.
modules/​vpc/​tests/​validation.tftest.hcl Checks that attachment tags preserve its name.
modules/​vpc/​main.tf Passes tags to network resources and modules.
modules/​search/​variables.tf Adds the search module’s tag input.
modules/​search/​main.tf Tags the search domain and security groups.
modules/​quilt/​variables.tf Adds the default Marketplace product code.
modules/​quilt/​tests/​smoke/​smoke.tftest.hcl Checks default, custom, and omitted stack attribution.
modules/​quilt/​tests/​smoke/​main.tf Exposes product-code input and stack tags for tests.
modules/​quilt/​main.tf Constructs attribution tags and applies them across resources.
modules/​db/​variables.tf Adds the database module’s tag input.
modules/​db/​main.tf Passes tags to database and security-group modules.
CHANGELOG.md Announces default tagging and in-place upgrade behavior.

Review effort: Balanced

Comment thread modules/quilt/main.tf Resolved
@greptile-apps

greptile-apps Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no new blocking issues found.

Reviews (2) · Last reviewed commit: "Leave the stack untagged and validate th..." · Reviewed by Greptile

Comment thread modules/quilt/main.tf Resolved

drernie commented Nov 11, 2026

Copy link
Copy Markdown
Member Author

Looks good overall. This matches #132: paygo's product code by default, overridable, on the CloudFormation stack and on every resource the module creates. The tag wiring through vpc / db / search, the Transit Gateway attachment keeping its Name via merge, the "" opt-out, and the README / CHANGELOG / VARIABLES notes are all in the right place. CI is green (fmt, validate, module tests, markdownlint).

Two nits:

  1. Validate marketplace_product_code in modules/quilt/variables.tf. The module prefixes pc: itself (modules/quilt/main.tf, the local.tags block). A caller who pastes the full tag value (pc:1xn1f7bxkj2dc16ak28s0dbgk) would get pc:pc:..., which is not a valid PRM value. A validation that accepts "" or a code without the pc: prefix (for example ^[a-z0-9]+$) would catch that at plan time.

  2. Document the overlap with the CloudFormation template. quiltdata/deployment#3271 writes the same key onto the search domain, RDS instance, NAT gateways, and ECS task definitions, using the stack's Marketplace license — or paygo's code when there isn't one. Tagging aws_cloudformation_stack here means CloudFormation also copies this module's value onto those template resources. If a Terraform stack's Marketplace license is not paygo and the caller leaves the default, the two values for aws-apn-id-730278974607 will disagree and the stack update can fail. Worth a sentence in the README section: set marketplace_product_code to that listing's code so it matches the template.

The scope split with #3271 is intentional and fine: this module tags everything it creates, per #132; the template tags only the cost drivers.

The CloudFormation template tags the stack's own resources, so the module
tags only the resources it creates, and rejects a product code carrying
the "pc:" prefix at plan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 11, 2026 23:11
@drernie drernie changed the title Tag stacks for AWS Partner Revenue Measurement Tag Terraform-created resources for AWS Partner Revenue Measurement Nov 11, 2026
@drernie

drernie commented Nov 11, 2026

Copy link
Copy Markdown
Member Author

Both nits are addressed in 4e56c11.

  1. Validation: marketplace_product_code now accepts "" or a bare code (^[a-z0-9]*$), so a pasted tag value such as pc:1xn1f7bxkj2dc16ak28s0dbgk fails at plan. The smoke suite's new pc_prefixed_product_code_is_rejected run targets the module directly and expects that validation failure.
  2. Overlap with the template: removed rather than documented. Since quiltdata/deployment#3271 tags the template's own resources, the module no longer tags aws_cloudformation_stack. It tags only the resources it creates (VPC, database, search, the template bucket and object), so each resource has one writer of the key. new_vpc_plans now asserts that the stack carries no partner tag. The README says the template tags the stack's resources and this module tags the resources it creates. To keep one value across both, set marketplace_product_code to the variant's code, which is pay-as-you-go by default on both sides. Callers should not put the key in provider default_tags, which also reach the stack. The CHANGELOG, VARIABLES.md, the PR body and the title now match.

The tests that read the default and custom codes off the stack went with the stack's tag, since no output exposes the tags of resources the module creates. In their place, read-only plans of the nightly root at the default code, a custom code and "" show the expected tag on all 31 resources the module creates, no tag on the stack, and nothing replaced.

@drernie

drernie commented Nov 11, 2026

Copy link
Copy Markdown
Member Author

@greptileai re-review at head 4e56c11, please — the stack is no longer tagged (the template tags its own resources), and marketplace_product_code now rejects a pc:-prefixed value.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The Terraform attribution-tagging change has no active review issues.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

drernie commented Nov 12, 2026

Copy link
Copy Markdown
Member Author

Re-reviewed at 4e56c115. Both nits from the earlier comment are addressed, and the overlap is handled more cleanly than just documenting it:

  1. marketplace_product_code now validates ^[a-z0-9]*$, so a pasted pc:... value fails at plan. The new pc_prefixed_product_code_is_rejected smoke run pins that.
  2. The module no longer tags aws_cloudformation_stack. It tags only the resources it creates, so each resource has one writer of the key. The README tells callers to set marketplace_product_code to the template variant's code, and not to put the key in provider default_tags. new_vpc_plans asserts the stack carries no partner tag.

CI is all green (fmt, validate, module tests, markdownlint). Greptile is at 5/5 on this head, and Copilot's later pass recommends approval with the S3-policy thread resolved. The PR is mergeable, with mergeable_state: blocked — likely waiting on a required approval, not on CI or conflicts. Looks ready.

@drernie
drernie merged commit 090ff75 into main Nov 12, 2026
12 checks passed
@drernie
drernie deleted the prm-tag branch November 12, 2026 00:48
@drernie drernie mentioned this pull request Nov 12, 2026
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.

Add the Partner Revenue Measurement tag to Terraform-managed stacks

2 participants