Terraform Basics Flashcards
The core Terraform workflow consists of three stages:
Write
Plan
Apply
The write stage of the Terraform Workflow
First Step in the workflow.
Define infra in config files
The Review stage of the Terraform workflow
2nd stage in workflow after Write
Review the changes Terraform will make to your infra
The Apply stage in the workflow
Final stage in the workflow
Terraform provisions your infra and updates the state file
State File
Keeps track of your infrastructure.
Used to determined the changes to make to your infra.
Modules
Reusable configuration components called modules that define configurable collections of infra.
To deploy infrastructure with Terraform (5 Steps):
Scope - Identify the infrastructure for your project.
Author - Write the configuration for your infrastructure.
Initialize - Install the plugins Terraform needs to manage the infrastructure.
Plan - Preview the changes Terraform will make to match your configuration.
Apply - Make the planned changes.
Configuration file: The Terraform Block
terraform {} block contains Terraform settings, including the required providers Terraform will use to provision your infrastructure.
Configuration File: The provider block
The provider block configures the specified provider
A provider is a plugin that Terraform uses to create and manage your resources. You can define multiple provider blocks in a Terraform configuration to manage resources from different providers.
provider “azurerm” {
features {}
}
Configuration File: Resources Block
Use resource blocks to define components of your infrastructure.
Resource blocks have two strings before the block: the resource type and the resource name.
Together, the resource type and resource name form a unique ID for the resource.
resource “azurerm_resource_group” “rg” {
name = “myTFResourceGroup”
location = “westus2”
}
Terraform State
Terraform must store state about your managed infrastructure and configuration.
This state is stored by default in a local file named “terraform.tfstate”, but it can also be stored remotely, which works better in a team environment.
What “Day 0” and “Day 1” activities?
“Day 0” code provisions and configures your initial infrastructure.
“Day 1” refers to OS and application configurations you apply after you’ve initially built your infrastructure.
What are providers?
A provider is a plugin that Terraform uses to translate the API interactions with the service. A provider is responsible for understanding API interactions and exposing resources.
How to configure a provider?
With a provider block
provider “google” {
project = “acme-app”
region = “us-central1”
}
meta-arguments defined by Terraform and available for all provider blocks?
version: Constraining the allowed provider versions
alias: using the same provider with different configurations for different resources