User Tools

Site Tools


virtualization:cloud:terraform

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
virtualization:cloud:terraform [2023/09/29 14:31] jotasandokuvirtualization:cloud:terraform [2023/11/02 14:38] (current) – external edit 127.0.0.1
Line 28: Line 28:
   terraform plan -out example1.tfplan       # like a dry test   terraform plan -out example1.tfplan       # like a dry test
   terraform apply example1.tfplan      # actual push   terraform apply example1.tfplan      # actual push
 +  
 +.
 +
 +  terraform state list    # enumerates all state elements
 +  terraform state show <element-in-the-state-list>    # for details
  
 ---- ----
  **DATA SOURCES (RO)** : Are more like to grab info. from existing, read-only stuff ( you can't always (actually, far from it) have the complete infrastructure in your tf templates, resources already exist and you don't have much control over them but you still need to use them inside your Terraform templates).   **DATA SOURCES (RO)** : Are more like to grab info. from existing, read-only stuff ( you can't always (actually, far from it) have the complete infrastructure in your tf templates, resources already exist and you don't have much control over them but you still need to use them inside your Terraform templates). 
 +\\
 +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 "oci_identity_availability_domains" "test_availability_domains" {   data "oci_identity_availability_domains" "test_availability_domains" {
Line 56: 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 : The former contains just the vaulues in a ''map'' format. More info [[https://drive.google.com/file/d/1sjIazwMtXbcSOnTruvrsUner9xCz63uQ/view?usp=sharing|Here]]
-variable.tfvar vs. variable.tf+
  
   * **VARIABLE TYPES:**   * **VARIABLE TYPES:**
Line 95: 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 ''root module'' **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 ''root module''
  
-  * Check this [[https://github.com/rojopolis/TerraformLiveLessons/blob/fc54a759b099d4dcf20880c57dc717751f8f1709/terraform/modules/trivial/examples/main.tf|Example]] of an extremely simple module+  * Check this [[https://github.com/rojopolis/TerraformLiveLessons/blob/fc54a759b099d4dcf20880c57dc717751f8f1709/terraform/modules/trivial/examples/main.tf|Example]] of an extremely simple module (on a [[https://drive.google.com/file/d/1q8PKfoHnTPgoACZjlhoiC97-Tp6T4IeH/view?usp=sharing|Screenshot]]. << **USEFUL**
     * when we call the module, the name is unrelated to the resources themselves.     * when we call the module, the name is unrelated to the resources themselves.
     * Source points to the moudule's location     * Source points to the moudule's location
     * main.tf in that location is the module's entry point!     * main.tf in that location is the module's entry point!
-  * For a more elaborated example, see [[https://drive.google.com/file/d/1qBXYVHgefXwFwfE9vqmut3SI2gFB-KbF/view?usp=drive_link|This]]+  * The ''output'' of the module is fed back the the root via output (see screenshot link above) 
 +  * For the module file structure and conventions, see these two links: [[https://developer.hashicorp.com/terraform/language/modules/develop/structure|Link1]] , [[https://drive.google.com/file/d/1qRJne6Ws9-S3ELtpuBC4qM578rjPzKsU/view?usp=sharing|Link2]] 
  
  
Line 205: 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:  If you wanted to output the arn of the following resource in a module: Example1:  If you wanted to output the arn of the following resource in a module:
Line 288: 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://developer.hashicorp.com/terraform/language/expressions/strings
 +
 +
 +----
 +**ITERATIONS**
 +  * By means of [[https://blog.gruntwork.io/terraform-tips-tricks-loops-if-statements-and-gotchas-f739bbae55f9|list_comprehensions]]
 +
 +----
  
 Install tf:\\ Install tf:\\
virtualization/cloud/terraform.1695997878.txt.gz · Last modified: (external edit)