liveBook · Manning

Infrastructure as code

As explained in AI-Powered Developer: Build software with ChatGPT and Copilot

Infrastructure as code is the practice of defining and managing infrastructure through versioned machine-readable configuration rather than manual operations.

Infrastructure as code (IaC) defines infrastructure in machine-readable files that can be stored and versioned, rather than relying on manual setup. It makes a deployment environment repeatable: describe the desired resources, then use tooling to provision them consistently. Terraform provides a domain-specific language for expressing cloud infrastructure without requiring every provider-specific provisioning detail. section 7.0 section 7.2

A practical IaC workflow starts after an application has been tested and containerized. Deployment files describe where it will run, while related automation builds images, publishes them, and releases the application. For AWS, this can combine Terraform-managed EC2 infrastructure with Docker installation and later Kubernetes deployment on EKS or ECS. section 7.0

Provisioning an EC2 host for a container

A Terraform file can select an AWS region, declare an EC2 instance, choose an AMI and instance type, and supply startup commands. The startup script updates the host, installs and starts Docker, adds the EC2 user to the Docker group, and runs an Nginx container on port 80. This turns host preparation and application startup into a reviewable configuration artifact. section 7.2 section 7.2

Listing 7.2 Example Terraform file, including instance size
# Create a Terraform file that provisions an AWS EC2 instance of type t2.micro, installs the Docker daemon, and returns the instance's hostname.
provider "aws" {
  region = "us-west-2"
}
  
resource "aws_instance" "example" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t2.micro"
}

Inspect a minimal Terraform declaration for an AWS provider and EC2 resource. It illustrates the core pattern: declare the provider, then declare the infrastructure resource and its desired attributes. section 7.2

Treat AI-assisted infrastructure definitions as a draft to verify, not an automatic deployment plan:

  • Specify the intended platform and outcome clearly, such as an EC2 instance, its size, Docker installation, and the hostname to return. section 7.2
  • Check generated files for essential operational steps. A generated configuration may omit Docker installation even when the application depends on it. section 7.2
  • Replace environment-specific placeholders with values you control, including an accessible key pair; consider an explicit VPC when default networking does not meet security requirements. section 7.2
  • Accept variation in generated output only after confirming that required provider, instance, Docker, key-pair, and security-group features are present. section 7.2

IaC also fits a broader delivery pipeline. GitHub Actions can respond to merges to the main branch, build and push a Docker image to Amazon ECR, configure AWS credentials from secrets, and deploy to EKS. Keeping workflow configuration in code centralizes repeated delivery steps, improving speed and reliability while reducing opportunities for manual error. section 7.6 section 7.6

Use generated infrastructure and workflow files as a starting point for refinement. Deployment needs, security constraints, cloud defaults, and tools evolve, so keep reviewing configurations and adapting the automation instead of treating any initial output as final. section 7.2 section 7.6

How AI-Powered Developer: Build software with ChatGPT and Copilot covers it

How deep it goes
Works through Terraform descriptors for an EC2 host and connects them to CI/CD automation, without detailing all cloud-provider provisioning complexities.
Examples
Uses an EC2 Terraform file with Docker startup commands and a GitHub Actions workflow that builds, pushes, and deploys an image.
What it assumes
Assumes a containerized application and access to an AWS key pair, then introduces Terraform deployment descriptors.
What you can do after
Operate/configure AWS deployment infrastructure through Terraform files and review AI-generated definitions for missing operational requirements.
How it connects
Connects Terraform, Docker, AWS EC2, Kubernetes, GitHub Actions, Amazon ECR, and Amazon EKS.

Also explained in

Compare how 14 books explain infrastructure as code →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI-Powered Developer: Build software with ChatGPT and Copilot. The section links point to the parts of the book it draws on.