Terraform Flashcards
What is
Resource?
Resource block describes one or more infrastructure objects, such as virtual networks, compute instances, or higher-level components such as DNS records.
What is
Provider?
Plugin form cloud provider that allow to manage infra specific for cloud.
What is
Module?
Modules are containers for multiple resources that are used together.
Each main.tf in folder is module on it own.
How to
How to call Module and why?
module "bigquery_datasets" { source = "<source_path>" }
You can call it to reuse configuration from another module
What is
What are sources of the module?
- From local file
- Github
- Http
- Cloud Storage Buckets
How to
How to change resoucre argument value when importing whole module? like
module "bigquery_datasets" { source = "../modules/bigquery_datasets" }
- Move OG name to variables
- Then dirrecly change this var in module file
~~~
module “bigquery_datasets” {
source = “../modules/bigquery_datasets”
dataset_name = “offers”
}
~~~
How to
How to make resource creation dependend on another resource?
Use
depends_on = [ resource_type.resource_name ]
Block
How to
How to make multiple resources via one block?
(there is 2 methods)
resource "aws_iam_user" "the-accounts" { for_each = toset(["Todd", "James", "Alice") name = each.key }
OR
~~~
resource “aws_iam_user” “the-accounts” {
count = 4
name = “Server ${count.index}”
}
~~~
How to - console
How to show dependency grap?
terraform graph
How to
How to declare variables?
In variables.tf file declared like
variable "project" { type = string }
How to
How to set variables?
1.In variables.tf file like
variable "project" { type = string default = "sc-9369-dataengineering-dev" }
2.terraform apply -var="project=sc-9369-dataengineering-dev"
3.In terraform.tfvars
file and running terraform apply -var-file="terraform.tfvars"