liveBook · Manning

Make

As explained in Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu

Make is a build automation tool that executes commands defined in a makefile according to target relationships and file dependencies.

A Terraform project can accumulate more formatting, documentation, testing, and quality-check commands than anyone wants to memorize. Make records reusable commands in a project-root file named `makefile`, so the team can run a named task such as `make test`. Its simple, widely available interface helps keep workflows consistent across projects. section 7.2.2 section 7.8

A makefile defines targets and the commands they run. Targets can also name other targets as dependencies, allowing one command to group related chores. Makefile variables can be overridden on the command line. The examples declare task targets with `.PHONY`; follow the required spacing and tab formatting carefully, because Make is particular about it. section 7.2.2

Listing 7.5 Using the makefile
.PHONY: chores
chores: format document                   #1
 
.PHONY: format
format:
  terraform fmt                           #2
 
.PHONY: document
document:
  terraform-docs -c .terraform-docs.yml . #3

The `chores` target names `format` and `document` as dependencies. Their commands run `terraform fmt` and `terraform-docs`, respectively, putting two routine Terraform tasks behind one target. section 7.2.2

Run a single task

A `hello` target containing `echo "Hello World"` can be invoked with `make hello`. Make displays the command and its output. The same target-and-command pattern can record a project's less memorable quality-control commands. section 7.2.2

How Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu covers it

How deep it goes
Explains makefile creation, targets, dependencies, variables, invocation, and formatting cautions, while leaving advanced Make features aside.
Examples
Shows a `hello` target and a `chores` target combining `terraform fmt` with `terraform-docs`.
What it assumes
Assumes command-line project work but introduces makefiles and targets without requiring advanced Make knowledge.
What you can do after
Operate/configure it to group and run repeatable Terraform project chores through named makefile targets.
How it connects
Connects targets to Terraform formatting, documentation generation, automated quality control, and project standards.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu. The section links point to the parts of the book it draws on.