Skip to content

[DevOps] PR Builds: Add PR deployment support to Deploy-Hub#2030

Open
flanakin wants to merge 4 commits intodevfrom
flanakin/pr-deploy-hub
Open

[DevOps] PR Builds: Add PR deployment support to Deploy-Hub#2030
flanakin wants to merge 4 commits intodevfrom
flanakin/pr-deploy-hub

Conversation

@flanakin
Copy link
Collaborator

🛠️ Description

Extends Deploy-Hub.ps1 with three new parameters to support CI automation and simplified export configuration:

  • -PR — Sets initials to pr for PR-based naming (e.g., pr-123-adx)
  • -Scope — Configures cost data exports after deployment (managed or manual)
  • -ManagedExports — Uses template-managed exports and grants the hub identity required RBAC roles on the monitored scope

Post-deployment logic handles two paths:

  • Managed exports: Grants Cost Management Contributor and RBAC Administrator on the scope, passes scopesToMonitor to the template
  • Manual exports: Creates a FocusCost export via New-FinOpsCostExport

Also documents the required RBAC roles for subscription/RG scopes in configure-scopes.md.

This is PR A of a multi-PR effort to add per-PR deployment CI for FinOps hubs.

📋 Checklist

🔬 How did you test this change?

  • 🤏 Lint tests
  • 🤞 PS -WhatIf / az validate
  • 👍 Manually deployed + verified
  • 💪 Unit tests
  • 🙌 Integration tests

🙋‍♀️ Do any of the following that apply?

  • 🚨 This is a breaking change.
  • 🤏 The change is less than 20 lines of code.

📑 Did you update docs/changelog.md?

  • ✅ Updated changelog (required for dev PRs)
  • ➡️ Will add log in a future PR (feature branch PRs only)
  • ❎ Log not needed (small/internal change)

📖 Did you update documentation?

  • ✅ Public docs in docs (required for dev)
  • ✅ Public docs in docs-mslearn (required for dev)
  • ✅ Internal dev docs in docs-wiki (required for dev)
  • ✅ Internal dev docs in src (required for dev)
  • ➡️ Will add docs in a future PR (feature branch PRs only)
  • ❎ Docs not needed (small/internal change)

Extends Deploy-Hub.ps1 with CI/automation support:
- -PR switch sets initials to "pr" for PR-based naming (e.g., pr-123)
- -Scope configures cost data exports after deployment
- -ManagedExports uses template-managed exports with RBAC setup

Post-deployment handles both managed exports (grants Cost Management
Contributor and RBAC Administrator on the monitored scope) and manual
exports (creates FocusCost export via New-FinOpsCostExport).

Also documents required RBAC roles for subscription/RG scopes in
configure-scopes.md.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 28, 2026 11:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends Deploy-Hub.ps1 with three new parameters (-PR, -Scope, -ManagedExports) to support CI/PR-based deployments and export configuration. It also documents required RBAC roles for subscription/resource group scopes in configure-scopes.md.

Changes:

  • Added -PR, -Scope, and -ManagedExports parameters to Deploy-Hub.ps1, including post-deployment logic to either grant managed identity RBAC roles or create a manual FocusCost export via New-FinOpsCostExport
  • Updated src/scripts/README.md with new parameter documentation and usage examples
  • Updated docs-mslearn/toolkit/hubs/configure-scopes.md to document the required roles (Cost Management Contributor and RBAC Administrator) for subscription/resource group scopes

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/scripts/Deploy-Hub.ps1 Core changes: new parameters, initials logic for PR mode, managed/manual export configuration post-deployment
src/scripts/README.md Updated parameter table and new usage examples for -PR, -Scope, and -ManagedExports
docs-mslearn/toolkit/hubs/configure-scopes.md Added documentation for RBAC roles needed for subscription/resource group scopes with managed exports

@flanakin flanakin changed the title Add -PR, -Scope, and -ManagedExports to Deploy-Hub [DevOps] PR Builds: Add PR deployment support to Deploy-Hub Feb 28, 2026
flanakin and others added 2 commits February 28, 2026 22:49
- Add "Optional." prefix to -PR parameter doc
- Fix enableManagedExports default: explicitly set to $false for manual exports
- Check New-AzRoleAssignment result before reporting success
- Fix comment: "Build" → "Import" for module load

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@flanakin
Copy link
Collaborator Author

flanakin commented Mar 1, 2026

🤖 [AI][Claude] PR Update Summary

Addressed: 4 thread(s)

  • ✅ Implemented: 4
  1. Added "Optional." prefix to -PR parameter doc
  2. Explicitly set enableManagedExports = $false for manual exports path (template defaults to true)
  3. Check New-AzRoleAssignment result before reporting success, warn on failure
  4. Fixed comment: "Build" → "Import" for module load

@flanakin flanakin enabled auto-merge (squash) March 1, 2026 07:04
@flanakin flanakin added Skill: DevOps GitHub setup and automation Tool: FinOps hubs Data pipeline solution labels Mar 1, 2026
@flanakin flanakin added this to the v14 milestone Mar 2, 2026
@RolandKrummenacher

This comment was marked as duplicate.

@RolandKrummenacher

This comment was marked as duplicate.

RolandKrummenacher

This comment was marked as duplicate.

- Subscriptions and resource groups – [Assign Azure roles using the Azure portal](/azure/role-based-access-control/role-assignments-portal).
- Subscriptions and resource groups – [Assign Azure roles using the Azure portal](/azure/role-based-access-control/role-assignments-portal). Assign the following roles to the hub managed identity on each scope:
- **Cost Management Contributor** – create and manage exports.
- **RBAC Administrator** – required by Cost Management to grant itself access to write export data to the hub storage account.
Copy link
Collaborator

Choose a reason for hiding this comment

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

RBAC Administrator — wrong scope?

The Microsoft.Authorization/roleAssignments/write permission is needed on the storage account, not on the monitored scope. This is so Cost Management can auto-assign itself StorageBlobDataContributor to write export data (per the exports prerequisites docs).

The Bicep template already handles this — ManagedExports/app.bicep:59-63 assigns RBAC Administrator on the storage account via storageRoles.

This means:

  1. The RBAC Administrator grant on $Scope in Deploy-Hub.ps1 is unnecessary — the template already assigns it where it's actually needed (storage account).
  2. The docs are misleading — granting RBAC Administrator on a subscription is overly permissive and doesn't serve the stated purpose.

Only Cost Management Contributor should be needed on the monitored scope.


```powershell
./Deploy-Hub -PR 123
```
Copy link
Collaborator

Choose a reason for hiding this comment

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

-PR switch vs. positional parameter confusion

-PR is declared as [switch] but this example reads as if -PR takes a value. It works because 123 binds to the positional -Name parameter, but it's misleading. Consider either:

  • Making the separation explicit: ./Deploy-Hub -PR -Name 123
  • Or changing -PR to a [string] that accepts the PR number directly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs: Review 👀 PR that is ready to be reviewed Skill: DevOps GitHub setup and automation Tool: FinOps hubs Data pipeline solution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants