Skip to content

feat(iam-policy): add generic IAM policy factory component - #18

Merged
opariffazman merged 3 commits into
mainfrom
feat/iam-policy-component
Jun 29, 2026
Merged

opariffazman merged 3 commits into
mainfrom
feat/iam-policy-component

Conversation

@opariffazman

Copy link
Copy Markdown
Contributor

Summary

Add a generic iam-policy component that wraps caller-composed IAM policy JSON into named, tagged aws_iam_policy resources — the environment authors the document, the component owns naming/tagging and exposes the ARN. Also grant the automation-roles CI role the IAM-policy lifecycle actions needed to apply it. Resolves #13.

Component(s)

iam-policy · automation-roles — plus docs / ci

Type

  • Added — new component or feature (MINOR)
  • Changed — behavior change to an existing component (automation-roles permissions)
  • Fixed — bug fix (PATCH)
  • Removed
  • Breaking input/output change — callers must edit their config (MAJOR; flag loudly in CHANGELOG)

Changes

  • iam-policy (new): policies map → one aws_iam_policy per entry, named <env>-<key>, body taken verbatim from the entry's policy_json, common_tags applied; outputs policy_arns keyed by the map key (feeds ec2 iam_role_policy_arns). No data sources — greenfield-plannable. Validates map keys (RFC1035 regex) and policy_json (jsondecode), both proven to fail at plan.
  • automation-roles: new ManagedPolicies statement granting iam:*Policy lifecycle actions scoped to arn:aws:iam::<account>:policy/<env>-*, so the dev pipeline can apply iam-policy. Attaching to instance roles is already covered by the existing AttachRolePolicy grant.
  • Design choice: thin JSON wrapper (env authors the document) over a structured policy-builder — keeps policy content in the environment so a new/changed grant never re-releases this component, and avoids re-implementing the IAM policy language as Terraform inputs.
  • Wiring: added to the CI matrix, the root README components table, and CHANGELOG [Unreleased] (Added + Changed).

Validation

  • terraform fmt / validate / tflint pass on the changed components (the gate)
  • CHANGELOG.md [Unreleased] updated
  • Component README / root README updated if inputs or outputs changed

Follow-ups (out of band, not in this PR)

  • Re-apply automation-roles to the dev account before the dev pipeline first applies iam-policy (it is human-applied, off-pipeline).
  • In infra-environments-dev: add the iam-policy unit (compose the postiz-ssm policy_json) and wire dependency.iam_policy.outputs.policy_arns["postiz-ssm"] into the ec2 unit's iam_role_policy_arns.

🤖 Generated with Claude Code

opariffazman and others added 3 commits June 30, 2026 07:33
Wraps caller-composed IAM policy JSON (the policies map) into named,
tagged aws_iam_policy resources and outputs policy_arns keyed by entry.
Models no IAM semantics — the environment authors each document and feeds
an ARN into a consumer role (e.g. ec2 iam_role_policy_arns). Greenfield-
plannable (no data sources); validates map keys (RFC1035) and policy_json
(jsondecode). Closes part of #13.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a ManagedPolicies statement granting iam:*Policy lifecycle actions on
arn:aws:iam::<account>:policy/<env>-* so the dev pipeline can apply the new
iam-policy component. Attaching policies to instance roles is already covered
by the existing AttachRolePolicy grant on role/<env>-*. Closes part of #13.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add iam-policy to the CI fmt/validate/tflint matrix, the root README
components table, and CHANGELOG [Unreleased] (Added iam-policy; Changed
automation-roles). Closes #13.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@opariffazman
opariffazman requested a review from Lexxick as a code owner June 29, 2026 23:40
@github-actions

Copy link
Copy Markdown

📝 Changelog preview (draft)

Generated from Conventional Commits. Curate into CHANGELOG.md → ## [Unreleased] — trim noise, keep consumer-facing changes.

[Unreleased]

Added

  • automation-roles: Allow CI role to manage scoped iam policies
  • iam-policy: Add generic IAM policy factory component

Fixed

  • release: Annotate the vX.Y.Z tag so tagging survives tag.gpgsign

@opariffazman
opariffazman merged commit 36552a4 into main Jun 29, 2026
11 checks passed
@opariffazman
opariffazman deleted the feat/iam-policy-component branch June 29, 2026 23:47
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 reusable scoped IAM policy module (consumer-composed policies for ec2 iam_role_policy_arns)

1 participant