liveBook · Manning

Argument

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

A Terraform resource argument is a named value in a resource configuration that specifies an attribute of the represented infrastructure object.

To configure an AWS instance, put named values inside its resource block: `ami` selects an image, `subnet_id` identifies a subnet, and `instance_type` sets the instance type. Each is an argument: a `name = value` assignment that changes how the block behaves. The resource’s type determines which arguments it accepts. section 2.5.1 section 2.2.3

Listing 2.12 Terraform resource with arguments
resource "aws_instance" "hello_world" {
  ami           = data.aws_ami.ubuntu.id          #1
  subnet_id     = data.aws_subnets.default.ids[0] #1
  instance_type = var.instance_type               #1
}

The instance’s argument values come from three places: an AMI data source, a subnet data source, and an input variable. An argument value can be a Terraform expression, not just a literal. section 2.2.3

An argument name can appear only once in a block. Do not confuse an object-valued argument, which has an equals sign, with a nested subblock, which does not. Subblocks can normally repeat—for example, a data source can use several `filter` subblocks. section 2.2 section 2.2.3

Arguments also become accessible attributes, so another block can refer to a configured value. A resource may expose additional read-only attributes after a plan or apply; values inside subblocks are not exposed as attributes. Ordinary resource arguments configure infrastructure, while meta arguments tell Terraform how to process a block during planning. Some meta arguments require literal values or values known at plan time. section 2.2.4 section 2.7

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

How deep it goes
Defines assignment syntax and uniqueness, then distinguishes arguments from repeatable subblocks and exported attributes; defers complex expressions.
Examples
Uses an AWS instance configured with AMI, subnet, and instance-type references, plus data-source filters and firewall-rule subblocks.
What it assumes
Introduces block structure and argument assignments before using data-source and variable references; defers more complex expressions.
What you can do after
Apply it via Terraform HCL to assign resource values and distinguish arguments from subblocks and read-only attributes.
How it connects
Connects resource blocks to data sources, input variables, attributes, subblocks, and meta arguments.

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.