IMPORTANT POINTS FOR EXAM (PART-10)

Updated: Aug 9, 2020




Congratulations on completing the series till now. Here are some important pointers for you that will help you clear the Terraform certified exam and brush up your concepts.






IMPORTANT POINTER AT A GLANCE


Pointer 1: Terraform Providers


A provider is responsible for understanding API interactions and exposing resources.


Most of the available providers correspond to one cloud or on-premises infrastructure platform and offer resource types that correspond to each of the features of that platform.


You can explicitly set a specific version of the provider within the provider block.


To upgrade to the latest acceptable version of each provider, run terraform init -upgrade


Following is the high-level architecture of the provider.



Pointer 2 - alias: Multiple Provider Instances


You can have multiple provider instances with the help of an alias



provider "aws" {
  region = "us-east-1"
}
provider "aws" {
  alias  = "west"
  region = "us-west-2"
}

The provider block without alias set is known as the default provider configuration. When an alias is set, it creates an additional provider configuration.


Pointer 3 - Terraform Init


The terraform init command is used to initialize a working directory containing Terraform configuration files.


During init, the configuration is searched for module blocks, and the source code for referenced modules is retrieved from the locations given in their source arguments.

Terraform must initialize the provider before it can be used.


Initialization downloads and installs the provider's plugin so that it can later be executed.


It will not create any sample files like example.tf



Pointer 4 - Terraform Plan


The terraform plan command is used to create an execution plan.


It will not modify things in infrastructure.


Terraform performs a refresh, unless explicitly disabled, and then determines what actions are necessary to achieve the desired state specified in the configuration files.


This command is a convenient way to check whether the execution plan for a set of changes matches your expectations without making any changes to real resources or to the state.



Pointer 5 - Terraform Apply


The terraform apply command is used to apply the changes required to reach the desired state of the configuration.



Terraform apply will also write data to the terraform.tfstate file.



Once apply is completed, resources are immediately available.


Pointer 6 - Terraform Refresh


The terraform refresh command is used to reconcile the state Terraform knows about (via its state file) with the real-world infrastructure.


This does not modify infrastructure but does modify the state file.



Pointer 7 - Terraform Destroy



The terraform destroy command is used to destroy the Terraform-managed infrastructure.


terraform destroy command is not the only command through which infrastructure can be destroyed.




Pointer 8 - Terraform Format


The terraform fmt command is used to rewrite Terraform configuration files to a canonical format and style.


For use-case, where the all configuration written by team members needs to have a proper style of code, terraform fmt can be used.



Pointer 9 - Terraform Validate


The terraform validate command validates the configuration files in a directory.


Validate runs checks that verify whether a configuration is syntactically valid and thus primarily useful for general verification of reusable modules, including the correctness of attribute names and value types.


It is safe to run this command automatically, for example, as a post-save check in a text editor or as a test step for a reusable module in a CI system. It can run before terraform plan.


Validation requires an initialized working directory with any referenced plugins and modules installed


Pointer 10 - Terraform Provisioners


Provisioners can be used to model specific actions on the local machine or on a remote machine in order to prepare servers or other infrastructure objects for service.


Provisioners should only be used as a last resort. For most common situations, there are better alternatives.


Provisioners are inside the resource block.


Have an overview of local and remote provisioner




Pointer 11 - Debugging In Terraform


Terraform has detailed logs that can be enabled by setting the TF_LOG environment variable to any value.


You can set TF_LOG to one of the log levels TRACE, DEBUG, INFO, WARN or ERROR to change the verbosity of the logs.


Example:


TF_LOG=TRACE


To persist logged output, you can set TF_LOG_PATH





Pointer 12 - Terraform Import


Terraform is able to import existing infrastructure.


This allows you to take resources that you've created by some other means and bring it under Terraform management.


The current implementation of Terraform import can only import resources into the state. It does not generate configuration.


Because of this, prior to running terraform import, it is necessary to write a resource configuration block manually for the resource, to which the imported object will be mapped.


terraform import aws_instance.myec2 instance-id




Pointer 13 - Local Values


A local value assigns a name to an expression, allowing it to be used multiple times within a module without repeating it.


The expression of a local value can refer to other locals, but as usual reference cycles are not allowed. That is, a local cannot refer to itself or to a variable that refers (directly or indirectly) back to it.


It's recommended to group together logically-related local values into a single block, particularly if they depend on each other.


Pointer 14 - Overview of Data Types




Pointer 15 - Terraform Workspace


Terraform allows us to have multiple workspaces; with each of the workspaces, we can have a different set of environment variables associated.


Workspaces allow multiple state files of a single configuration.




Pointer 16 - Terraform Modules


We can centralize the terraform resources and can call out from TF files whenever required.




Pointer 17 - ROOT and Child Modules


Every Terraform configuration has at least one module, known as its root module, which consists of the resources defined in the .tf files in the main working directory.


A module can call other modules, which lets you include the child module's resources into the configuration in a concise way.

A module that includes a module block like this is the calling module of the child module.




This is it for this article. to keep it short simple and crisp, the rest of the pointers are covered in the next part i.e. Part 11.















373 views0 comments

Recent Posts

See All