Infrastructure

Automate your AWS architecture diagrams

Architect drawing blueprints by hand at a wooden desk

If you use Terraform or any other IaC solution to provision your cloud infrastructure, you might have faced some of these questions:

  • How do I automate the infrastructure design diagram and infrastructure cost estimates?
  • How can I keep my infrastructure design diagram up to date with my IaC?
  • How can I get an architecture diagram that accurately represents my Infrastructure As Code?
  • How can I see a visual representation of all the changes my PR will make to the infrastructure?
  • How does my PR impact the infra cost?
  • Can I see the historical changes to my infrastructure not just as code but also as an architecture diagram?
  • How do I generate my cloud architecture diagram as part of CI-CD?

Recently I tried my hands with a couple of tools to solve these common IaC scenarios.

The tools: Pluralith and Infracost

Pluralith is a tool to visualize your Terraform state and automate infrastructure documentation. It also helps detect and visualize infrastructure drift and the cost of your infrastructure (via Infracost).

This approach of arriving at the architecture from the Terraform state, I feel, is better than some of the diagram as code solutions since you do not need to maintain anything additional apart from your Terraform code. There are a few other similar solutions out there like inframap, brainboard, etc. However, the CI-CD integration of Pluralith can be a differentiator.

Infracost shows cloud cost estimates for Terraform. It lets DevOps, SRE, and engineers see a cost breakdown and understand costs before making changes in the terminal or pull requests.

Arriving at the architecture from Terraform state is better than diagram-as-code - you maintain nothing extra beyond your IaC.

As a demo solution, I tried to incorporate both these tools into an IaC pipeline using GitHub Actions and tried to update PR comments with proposed architectural and cost changes. All the code for this demo and the implementation details are available on GitHub.

CI/CD pipeline integration

The Infracost run of the pipeline adds information in the PR comments that provides a view of the change in cost estimates that the PR will make.

GitHub Actions bot PR comment showing Infracost cost estimate: monthly cost will increase by $348 (+430%)

The Pluralith run of the pipeline adds information in the PR comments that provides a view of the infrastructure changes that the PR will make and provides a view of the infrastructure’s created, updated, destroyed, recreated, and drifted components.

GitHub Actions bot PR comment showing the Pluralith-generated infrastructure diagram for the run

You could also add the Pluralith infrastructure diagram in your README.md by just adding one line in your readme file.

Pluralith Dashboard

The Pluralith dashboard provides a consolidated view of the infrastructure with the option of drilling down to individual infrastructure components. It provides a view of the infrastructure’s created, updated, destroyed, recreated, and drifted components. Pluralith can be run locally as well.

Pluralith Dashboard showing an AWS infrastructure diagram with VPCs, subnets, and a DynamoDB table, with a sidebar showing Created/Updated/Destroyed/Replaced/Drift stats

Cost view

The Cost view of the dashboard provides a view of which component will make what cost estimate changes. The cost component uses Infracost to get the cost estimates.

Pluralith Dashboard Costs view showing total monthly cost of $62.19 and hourly cost of $0.085, with per-resource breakdown

History

The Dashboard also provides an option to view historical changes that the infrastructure has gone through, with the option of drilling down to the cost and design of all the components for these runs.

Pluralith Runs history view showing a list of CI pipeline runs with dates, branches, cost deltas, and change counts

How Terraform Cloud compares

Terraform Cloud does provide features for a cost estimate for a limited number of services and the capability to set policies around cost; however, you need to purchase the enterprise edition for this feature.

Terraform also has a feature to generate an architecture diagram using terraform graph; however, it is pretty rudimentary at this point.

It will be interesting to see how these tools and features evolve in this space of IaC.

While Pluralith is free for local use, the CI runs come at a cost. They made the cost changes in the past week itself. I did my tests last weekend and got some CI runs before the changes were made. 🙂

Topics
InfrastructureTerraformDevOpsAWS