Infrastructure as Code Pitfalls and How to Avoid Them - Part 2
April 06, 2021

Tim Davis
env0

As I mentioned before, Infrastructure as Code (IaC) comes with not only the pitfalls of infrastructure but also the pitfalls of code.

Start with: Infrastructure as Code Pitfalls and How to Avoid Them - Part 1

Code Pitfalls

One of the biggest code pitfalls is a very common issue with code in general. Redundant coding. This essentially means that you're creating entire duplicate sets of your code for each individual environment, and hard coding the customization values into each set of files.

he concept of DRY is usually pretty well known in the software development community. Don't repeat yourself (DRY, or sometimes do not repeat yourself) is a principle of software development aimed at reducing repetition of software patterns (Foote, Steven [2014]. Learning to Program. Addison-Wesley Professional. p. 336. ISBN 9780133795226), replacing it with abstractions or using data normalization to avoid redundancy.

So how do we make sure we're following this methodology while creating IaC files?

There are a few ways of doing this. Using variable values during the deployment process can help enable you to create a more "generic" set of IaC configurations that you can then use in a repeatable manner, customizing each deployment using the needed values.

Another way is using an IaC framework that natively enables this type of configuration creation. For example, Terragrunt is a "wrapper" for Terraform that enables the DRY methodology in the creation of IaC configuration files. It accomplishes this by restructuring the way Terraform files are organized and executed. You create 1 set of "DRY" configurations, then you use customization files to define each deployment. This allows you to write only one set of configuration files to be used for development and production deployments, but each has its own respective customization files in place so that it creates each one with the needed parameters.

Speaking of values, this is a significant topic when you're writing your infrastructure as code files. Specifically, what the default values are for each object you're going to be creating. If you do not specify a value for a specific object, there may be a default value associated with it. For example, if you write in your configuration to create a firewall, but don't specify values for a security policy, it may create the firewall with a default-permit-all policy. This is very bad.

How do we mitigate this pitfall?

From a code perspective, we make sure that we have the needed values and parameters for all of the objects we are creating in our code files.

We also talked about misconfiguration a bit earlier in the Infrastructure Pitfalls section. Using some kind of Policy as Code framework or security tool during the actual deployment phase can help you stop the deployment of misconfigured resources before it happens. It's better to have your deployment process fail and have to fix the code and try and redeploy again than have to fix an application that has been compromised due to being deployed with that misconfiguration.

Designing your IaC configuration files can also introduce a pitfall of performance issues. This performance hit comes during deployment, re-deployment, destroy, and other maintenance tasks when you have a large state file.

When you use Infrastructure as Code, the framework you choose needs to document the active "state" of what was actually deployed. This file is used to make future deploy or destroy operations more efficient so that it doesn't duplicate work it's already done.

For example, in Terraform, let's say you want to scale a cluster from 2 nodes to 3 nodes in the configuration file. When you subsequently run the Apply command again, it will check the state of the active deployment and see that it has already created 2 nodes, so it will only add 1 node to make 3 nodes in the cluster. Much more efficient than tearing down the 2 existing nodes and deploying the 3 new nodes you asked for from scratch. If you have a fast development cycle, and all of your infrastructure deployments are jammed into 1 giant state file, every little update or redeployment can take a significant amount of time to execute.

So how do we avoid this pitfall?

Modular programming is a software design technique that emphasizes separating the functionality of a program into independent, interchangeable modules, such that each contains everything necessary to execute only one aspect of the desired functionality. You can design your Infrastructure as Code files and the deployment process in such a way that you can split the full infrastructure into modular pieces. The network, the storage, and the compute, all in their own bite-sized modules. You can then chain these modules into a Workflow, or just re-deploy them individually when you need to. This makes it a much more "cloud-native" or "micro-service" friendly design.

Now, if you need to update just one piece of the infrastructure, you don't have to run the update or re-deploy operation against the entire infrastructures' state. Just that small piece that you're updating. This will make it so that you have more state files, but in the long run, that is a much easier situation to manage.

Wrap-Up

As you can see, there are a lot of decisions and pitfalls that go into using Infrastructure as Code. From choosing a framework, to who helps create and manage the files, and how you can manage the deployment process to try and help curb some of the pitfalls that come along with IaC configuration issues. And these aren't even close to all of the other types of pitfalls you may encounter along the way.

But, hopefully, this was helpful to get your head wrapped around some of the things you may need to be thinking about. And helps you to start off on the right foot, or even to help you go back and make some changes to your existing IaC configurations or procedures.

Tim Davis is a DevOps Advocate at env0
Share this

Industry News

September 05, 2024

Red Hat announced the general availability of Red Hat Enterprise Linux (RHEL) AI across the hybrid cloud.

September 05, 2024

Jitterbit announced its unified AI-infused, low-code Harmony platform.

September 05, 2024

Akuity announced the launch of KubeVision, a feature within the Akuity Platform.

September 05, 2024

Couchbase announced Capella Free Tier, a free developer environment designed to empower developers to evaluate and explore products and test new features without time constraints.

September 04, 2024

Amazon Web Services, Inc. (AWS), an Amazon.com, Inc. company, announced the general availability of AWS Parallel Computing Service, a new managed service that helps customers easily set up and manage high performance computing (HPC) clusters so they can run scientific and engineering workloads at virtually any scale on AWS.

September 04, 2024

Dell Technologies and Red Hat are bringing Red Hat Enterprise Linux AI (RHEL AI), a foundation model platform built on an AI-optimized operating system that enables users to more seamlessly develop, test and deploy artificial intelligence (AI) and generative AI (gen AI) models, to Dell PowerEdge servers.

September 04, 2024

Couchbase announced that Couchbase Mobile is generally available with vector search, which makes it possible for customers to offer similarity and hybrid search in their applications on mobile and at the edge.

September 04, 2024

Seekr announced the launch of SeekrFlow as a complete end-to-end AI platform for training, validating, deploying, and scaling trusted enterprise AI applications through an intuitive and simple to use web user interface (UI).

September 03, 2024

Check Point® Software Technologies Ltd. unveiled its innovative Portal designed for both managed security service providers (MSSPs) and distributors.

September 03, 2024

Couchbase officially launched Capella™ Columnar on AWS, which helps organizations streamline the development of adaptive applications by enabling real-time data analysis alongside operational workloads within a single database platform.

September 03, 2024

Mend.io unveiled the Mend AppSec Platform, a solution designed to help businesses transform application security programs into proactive programs that reduce application risk.

September 03, 2024

Elastic announced that it is adding the GNU Affero General Public License v3 (AGPL) as an option for users to license the free part of the Elasticsearch and Kibana source code that is available under Server Side Public License 1.0 (SSPL 1.0) and Elastic License 2.0 (ELv2).

August 29, 2024

Progress announced the latest release of Progress® Semaphore™, its metadata management and semantic AI platform.

August 29, 2024

Elastic, the Search AI Company, announced the Elasticsearch Open Inference API now integrates with Anthropic, providing developers with seamless access to Anthropic’s Claude, including Claude 3.5 Sonnet, Claude 3 Haiku and Claude 3 Opus, directly from their Anthropic account.