Foundations / Lesson 2 of 3

Providers and Resources

Follow one resource from your configuration file to a real object in the cloud.

7 min Beginner 7 steps
AWS accountaws_instance.webaws_vpc.mainmain.tfTerraform coreAWS provideraws_s3_bucket.logs

IN THIS LESSON

Step 1 of 7

STEP 1 / 7

Configuration says what you want

A Terraform configuration is a set of .tf files written in HCL. You declare the objects you want, and you do not write the steps to create them.

resource "aws_instance" "web" {
  ami           = "ami-0abcdef1234567890"
  instance_type = "t3.micro"
}

← → step · R replay · Space play/pause

YOU'LL LEARN

  • What Terraform core does, and what it leaves to providers
  • How terraform init installs providers
  • How resource blocks describe real objects
  • How references create dependencies
  1. Configuration says what you want. A Terraform configuration is a set of .tf files written in HCL. You declare the objects you want, and you do not write the steps to create them.
  2. Terraform core reads it. The terraform binary is the core. It parses your files, builds a graph of everything you declared, and decides what needs to happen. On its own it knows nothing about AWS, Azure or any other platform.
  3. Providers are plugins. Support for each platform lives in a provider plugin. Running terraform init reads the providers you require and downloads them, by default from the Terraform Registry.
  4. Providers call the cloud API. When Terraform needs to create or change something, the provider translates the request into API calls to the platform. Core decides what to do and the provider carries it out.
  5. Resources become real objects. Each resource block describes one infrastructure object. Its type, such as aws_instance, tells Terraform which provider and which kind of object it is. Its name, such as web, is how you refer to it in your code.
  6. References create dependencies. When one resource uses an attribute of another, Terraform knows the first must exist before the second. Resources with no link between them, like the bucket here, can be created in parallel.
  7. Recap. Terraform core plans the work and providers do it, which is why one tool can manage many platforms.