Skip to content

Conversation

kin0992
Copy link
Contributor

@kin0992 kin0992 commented Sep 23, 2025

This pull request introduces enhancements to the monorepo generator, specifically improving the Terraform infrastructure setup by dynamically configuring the backend state based on the selected cloud provider (CSP). It adds new prompt variables for both AWS and Azure backends, updates documentation, and implements the backend configuration in the generated Terraform files.

Closes CES-1278

Copy link

changeset-bot bot commented Sep 23, 2025

🦋 Changeset detected

Latest commit: a9e6fdb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@pagopa/monorepo-generator Patch
@pagopa/dx-cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov-commenter
Copy link

codecov-commenter commented Sep 23, 2025

Codecov Report

❌ Patch coverage is 0% with 47 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.56%. Comparing base (8abeb56) to head (ae47d0b).
⚠️ Report is 68 commits behind head on main.

Files with missing lines Patch % Lines
packages/monorepo-generator/src/index.ts 0.00% 47 Missing ⚠️

❌ Your project status has failed because the head coverage (45.56%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #911       +/-   ##
===========================================
- Coverage   67.85%   45.56%   -22.30%     
===========================================
  Files          31       39        +8     
  Lines         840     1543      +703     
  Branches      146      184       +38     
===========================================
+ Hits          570      703      +133     
- Misses        258      826      +568     
- Partials       12       14        +2     
Files with missing lines Coverage Δ
packages/monorepo-generator/src/index.ts 0.45% <0.00%> (ø)

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kin0992 kin0992 marked this pull request as ready for review September 23, 2025 13:26
@Copilot Copilot AI review requested due to automatic review settings September 23, 2025 13:26
@kin0992 kin0992 requested a review from a team as a code owner September 23, 2025 13:26
Copy link
Contributor

@Copilot 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 pull request adds support for conditional Terraform backend configuration to the monorepo generator, allowing users to automatically configure state storage based on their selected cloud provider (AWS or Azure). It introduces user prompts for backend-specific details and dynamically injects the appropriate backend configuration into generated Terraform files.

  • Adds new Handlebars template partials for AWS and Azure backend state configuration
  • Extends user prompts to collect cloud provider-specific backend configuration details
  • Implements dynamic partial loading logic to select the correct backend template based on user input

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/monorepo-generator/templates/monorepo/infra/repository/providers.tf.hbs Replaces TODO comment with dynamic backend state partial inclusion
packages/monorepo-generator/templates/monorepo/infra/azure/partials/backend-state.tf.hbs New Azure backend configuration template with azurerm backend
packages/monorepo-generator/templates/monorepo/infra/aws/partials/backend-state.tf.hbs New AWS backend configuration template with S3 backend
packages/monorepo-generator/src/index.ts Adds new prompts, backend partial selection logic, and updates action dependencies
packages/monorepo-generator/README.md Documents new template variables and updates formatting
.changeset/swift-beers-deny.md Changeset documentation for the feature addition

Comment on lines 67 to 87
{
default: "eu-south-1",
message: "AWS region for tfstate:",
name: "awsRegion",
type: "input",
when: (answers) => answers.csp === "aws",
},
Copy link
Member

Choose a reason for hiding this comment

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

thought: in my opinion this question should not be asked, we have to decide a region for our consumers.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's difficult to put a default for region while keeping the tool agnostic from PagoPA habits.
Perhaps we could develop a CLI plugin for each business project we support to provide the right values to the user?
We already have a solution like this and it is actually implemented in part via a Terraform module, but the CLI scenario could expand it

Copy link
Contributor

Choose a reason for hiding this comment

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

what about having all defaults in some config.yaml ?

Copy link
Contributor

Choose a reason for hiding this comment

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

How are they fetched?

Comment on lines 49 to 121
message: "Azure resource group for tfstate:",
name: "repoStateResourceGroupName",
type: "input",
when: (answers) => answers.csp === "azure",
Copy link
Member

Choose a reason for hiding this comment

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

question: can't this be pre-filled following a convention?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

something like ${prefix}-${envShort}-${locationShort}-terraform-rg-01?

@kin0992 kin0992 force-pushed the fixes/add-backend-repository-terraform-files branch from 4e0f475 to 3a9cd26 Compare September 26, 2025 07:41
# Conflicts:
#	packages/monorepo-generator/README.md
#	packages/monorepo-generator/src/index.ts
@kin0992 kin0992 force-pushed the fixes/add-backend-repository-terraform-files branch from 3a9cd26 to f7a02a6 Compare October 1, 2025 10:08
@kin0992 kin0992 force-pushed the fixes/add-backend-repository-terraform-files branch from f7a02a6 to c6753ea Compare October 1, 2025 10:08
@kin0992 kin0992 force-pushed the fixes/add-backend-repository-terraform-files branch from 4e96ead to ae47d0b Compare October 1, 2025 10:16
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.

5 participants