chapter seven

7 CI/CD Pipelines as Code

 

This chapter covers:

  • Designing an end-to-end CI/CD pipeline for Docker containers on GCP
  • Dividing infrastructure into static and dynamic components
  • Iterating over complex types with for-each and dynamic blocks
  • Explicitly overriding default providers at the resource level
  • Creating custom resources with local-exec provisioners and the Shell provider

CI/CD stands for Continuous Integration (CI) and Continuous Deployment (CD). It’s a methodology that enables development teams to quickly ship code changes to production environments. Companies that adopt CI/CD are proven to be more agile, and able to respond to changes in the marketplace more swiftly, than companies that don’t adopt CI/CD. CI/CD is typically implemented by a CI/CD pipeline, which describes how code gets from version control systems through to end users and customers. In a CI/CD pipeline, each stage performs some discreet task, such as building, testing, and deploying, before automatically promoting to the next stage in the pipeline (see figure 7.1).

Figure 7.1 CI/CD stands for Continuous Integration (CI) and Continuous Deployment (CD). It’s normally implemented by a CI/CD pipeline, in which one stage automatically promotes into the next

7.1       A Tale of Two Deployments

7.2       CI/CD for Docker Containers on GCP

7.2.1   Designing the Pipeline

7.2.2   Detailed Engineering

7.3       Initial Workspace Setup

7.3.1   Organizing the Directory Structure

7.3.2   Implicit vs Explicit Providers

7.4       Dynamic Configurations and Provisioners

7.4.1   For-Each vs. Count

7.4.2   Executing Scripts with Provisioners

7.4.3    Dealing with Repeating Configuration Blocks

7.4.4   Dynamic Blocks: Rare Boys

7.5       Local-Exec Provisioners “The Golden Hammer”

7.5.1   Null Resource with a Local-Exec Provisioner

7.6       Community and Third-Party Providers

7.6.1   Installing the Shell Provider

7.7       Deploying Static Infrastructure

7.8       CI/CD of a Docker Container

7.9       Overview

7.10  Summary