vendredi 11 juin 2021

Module per application or Module per Compute, Network or Storage? - Infrastructure as Code

This question is not limited to any tool, this is a general question.

Assume, we have below components in a simple project. Typical three-tier app.

  • 3 API Docker Images
  • 1 UI Component
  • 1 Database

I have designed my Terraform modules proportional to that. That means, 3 Terraform modules + 1 module to create cluster. API, UI, Database. For example,

  • cluster.tf - Creates cluster
  • api1.tf - Creates application and other needed resources for application
  • api2.tf
  • api3.tf
  • ui.tf - Creates CDN, Resources to serve static files
  • database.tf - Creates managed database instances

If we are adding one more API app, I will api4.tf. Easier to scale.

Is this a recommended pattern?

Another way of doing it is,

  • compute.tf - Creates cluster and all 3 applications
  • network.tf - Creates subnets etc
  • storage.tf - Creates storage volume, database instance
  • authentication.tf

The issue I see with second approach is that, it will not reflect my project components.

Any suggestions?

Aucun commentaire:

Enregistrer un commentaire