This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| virtualization:cloud:terraform [2023/09/26 15:29] – jotasandoku | virtualization:cloud:terraform [2023/11/02 14:38] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| **DOCUMENTATION**: | **DOCUMENTATION**: | ||
| * [[https:// | * [[https:// | ||
| - | * [[https:// | + | * [[https:// |
| + | * [[https:// | ||
| * This is the idea but not always strictly true: | * This is the idea but not always strictly true: | ||
| Line 27: | Line 28: | ||
| terraform plan -out example1.tfplan | terraform plan -out example1.tfplan | ||
| terraform apply example1.tfplan | terraform apply example1.tfplan | ||
| + | | ||
| + | . | ||
| + | |||
| + | terraform state list # enumerates all state elements | ||
| + | terraform state show < | ||
| ---- | ---- | ||
| | | ||
| + | \\ | ||
| + | Do not confuse with data sources. Output comes from the successful creation of a thing (like the output of a module). Data is accessing a thing that already exists but isn't necessarily managed in this state. E.g. getting a vpc id when your networking layer is in a different terraform state, | ||
| data " | data " | ||
| Line 55: | Line 63: | ||
| * terraform.tfvars : tfvars file extension is in the root folder of an environment to define values to variables. So we use a *.tfvar file to load in defaults as they are automatically loaded without any additional command line option. | * terraform.tfvars : tfvars file extension is in the root folder of an environment to define values to variables. So we use a *.tfvar file to load in defaults as they are automatically loaded without any additional command line option. | ||
| * variables.tf : the .tf uses modules to declare them | * variables.tf : the .tf uses modules to declare them | ||
| - | + | * variable.tfvar vs. variable.tf | |
| - | variable.tfvar vs. variable.tf | + | |
| * **VARIABLE TYPES:** | * **VARIABLE TYPES:** | ||
| Line 94: | Line 101: | ||
| **MODULE**: Is a __reusable piece of code__. Any set of Terraform configuration files in a folder is a module. The main one, where we work, is called '' | **MODULE**: Is a __reusable piece of code__. Any set of Terraform configuration files in a folder is a module. The main one, where we work, is called '' | ||
| - | * Example module | + | * Check this [[https:// |
| + | * when we call the module, | ||
| + | * Source points to the moudule' | ||
| + | * main.tf in that location is the module' | ||
| + | * The '' | ||
| + | * For the module file structure | ||
| Line 200: | Line 213: | ||
| - | **OUTPUTS**: | + | **OUTPUTS**: |
| + | \\ | ||
| + | Do not confuse with data sources. Output comes from the successful creation of a thing (like the output of a module). Data is accessing a thing that already exists but isn't necessarily managed in this state. E.g. getting a vpc id when your networking layer is in a different terraform state, | ||
| \\ | \\ | ||
| Example1: | Example1: | ||
| Line 252: | Line 267: | ||
| INTERPOLATION: | INTERPOLATION: | ||
| resource " | resource " | ||
| - | | + | |
| - | cidr_block = " | + | cidr_block = " |
| } | } | ||
| + | # | ||
| + | resource " | ||
| + | bucket = " | ||
| + | } | ||
| Line 267: | Line 286: | ||
| ---- | ---- | ||
| - | **CONDITIONALS AND THE COUNT PROPERTY** | + | **CONDITIONALS AND THE 'COUNT' |
| \\ | \\ | ||
| See [[https:// | See [[https:// | ||
| Line 279: | Line 298: | ||
| number_of_buckets = var.bucket_count > 0 ? var.bucket_count : local.minimum_number_of_buckets | number_of_buckets = var.bucket_count > 0 ? var.bucket_count : local.minimum_number_of_buckets | ||
| } | } | ||
| + | |||
| + | |||
| ---- | ---- | ||
| + | |||
| + | **TEMPLATING WITH HEREDOCS** | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | ---- | ||
| + | **ITERATIONS** | ||
| + | * By means of [[https:// | ||
| + | |||
| + | ---- | ||
| Install tf:\\ | Install tf:\\ | ||