Terraform is an Infrastructure as a Code, cloud agnostic tool created by HashiCorp.
A tool for building, changing, and versioning infrastructure safely and efficiently in any cloud using a declarative configuration language called HashiCorp Configuration Language(HCL).
Benefits of IaC
- Easily reproducible environments
- Idempotence and convergence
- Easing collaboration
- Self-Service Infrastructure
IaCs Options from famous Cloud Providers:
- AWS has CloudFormation
- Azure has Azure Resource Manager(ARM) templates
- GCP has Google Cloud Deployment Manager
When to use Terraform?
- Disposable environments
- Multi-cloud Deployments
- Multi-Tier Applications
- Resource Schedulers
Commands or steps or workflow in Terraform
- init
- validate
- plan
- apply
- destroy/taint
Resource graph is used to capture dependency information in your infrastructure and allow parallel changes
I would use this space mainly to understand about the Terraform and clear the Certification.
Terraform is from HashiCorp and more information about Terraform certification can be found here.
At the time of writing this entry in March 2024, "HashiCorp Certified: Terraform Associate (003)" is the name of the exam to get certified on Terraform Associate certification.
Below are the exam objectives
- Understand infrastructure as code (IaC) concepts
- Understand the purpose of Terraform (vs other IaC)
- Understand Terraform basics
- Use Terraform outside of core workflow
- Interact with Terraform modules
- Use the core Terraform workflow
- Implement and maintain state
- Read, generate, and modify configuration
- Understand Terraform Cloud capabilities
Some key terms and symbols:
IAC is used to deploy consistently configured infrastructure.
Cloud agnostic: Means it works on all Clouds like AWS, Azure, and Google Cloud etc
Idempotence: setting the same target environment with same configuration always when a specific command is executed.
Overtime, each environment drifts and becomes a Snowflake environment i.e. a unique configuration which difficult or cannot be produced automatically.
Symbols
- -/+ - in Terraform plan indicate that resource will be deleted and created
- ~ - forces replacement. Also it will look for the latest minor release and not major release. (E.g. if we specify ~4.16, it will look only till 4.99 and not more than or equal to 5)
- - - destroy
Infrastructure as Code(IaC)
Terraform Installation
3 steps
wget <link>
unzip
mv terraform /usr/local/bin/
Terraform Data Types for Values
Terraform Phases/steps
Terraform Commands
Terraform Configuration
Terraform Providers
Terraform Functions
zipmap,
- lower(str), upper(str), title(str)
- file(path), filebase64(path),
- min, max, abs(number), ceil(number), floor(number), round(number),
- timestamp(),
- lookup(map, key, default), coalesce(null, "Hi", 2) -- returns 1st non null value
- length(list), join(separator, list), element(list, index), concat(list1, list2, ..), flatten(list)
Terraform Variables
The name of a variable can be any valid identifier except the following: source, version, providers, count, for_each, lifecycle, depends_on, locals.
Some tidbits about Terraform
- The Terraform language does not support user-defined functions, and so only the functions built in to the language are available for use
- Terraform Cloud will automatically run a terraform plan operation whenever a new code change is committed to the version control repository that is linked to the workspace
- Locals word is used in the context of Modules
- Terraform files should be ignored by Git when committing code to a repository
- Files named exactly terraform.tfvars or terraform.tfvars.json.
- Any files with names ending in .auto.tfvars or .auto.tfvars.json.
- terraform.tfstate
Terraform Configuration:
Hashicorp Configuration Language(HCL) is the language used to write configurations in Terraform.
Configurations are written and stored in files with extension of "tf", standing for Terraform file.
We will see the syntax, assigning variables, organizing configuration files. With Terraform we can manage the following
Resources - infrastructure components like VM, Storage, Network, Database which are managed by Terraform
Providers - provide resources
Variables - inputs to configuration with description
Outputs - values that will displayed when we apply changes in configuration. Useful for integrating Terraform with scripting environments.
Data sources - fetch information outside of the current configuration
Terraform Cloud and Terraform Enterprise
HCL Syntax
setting the same target environment with same configuration always when a specific command is executed.
No comments:
Post a Comment