Skip to main content

What is Terraform?

 

What is Terraform?

Terraform is an open-source Infrastructure as Code (IaC) tool developed by HashiCorp. It allows you to provision, manage, and version infrastructure using a declarative configuration language.


Key Concepts:

1. Providers

  • Plugins that let Terraform interact with APIs of cloud platforms (e.g., AWS, Azure, GCP) or services (e.g., GitHub, Kubernetes).

  • Example: provider "aws" { region = "us-west-2" }

2. Resources

  • The building blocks of infrastructure (e.g., EC2 instances, S3 buckets).

  • Declared using resource blocks.

  • Example:

    hcl
    resource "aws_instance" "example" { ami = "ami-0c55b159cbfafe1f0" instance_type = "t2.micro" }

3. Variables

  • Allow configuration flexibility.

  • Declared using variable blocks and passed via CLI, .tfvars, or environment variables.

4. Outputs

  • Provide information after a Terraform apply.

  • Example:

    h
    output "instance_ip" { value = aws_instance.example.public_ip }

5. State

  • Terraform keeps track of infrastructure in a state file (terraform.tfstate).

  • This file is critical for tracking changes between your configuration and real-world infrastructure.

6. Modules

  • Reusable groups of resources.

  • Promote code reuse and organization.


Basic Commands:

CommandPurpose
terraform initInitializes Terraform and downloads providers
terraform planShows what Terraform will do before applying
terraform applyApplies the configuration to build the infrastructure
terraform destroyDestroys the infrastructure defined in the code
terraform validateValidates the configuration syntax

Typical Workflow:

  1. Write .tf files (Terraform configuration)

  2. Run terraform init

  3. Run terraform plan

  4. Review changes

  5. Run terraform apply


Let me know if you’d like a simple project example or guidance on setting up Terraform with a specific cloud provider.

Comments

Popular posts from this blog

Learn GitHub

Learn GitHub git init git add file.txt git commit -m "my first commit" git remote add origin https://github.com/dansullivanma/devlops_data_sci.git git clone https://github.com/dansullivanma/devlops_data_sci.git

Garbage collection in Databricks

Clean up snapshots Delta Lake provides snapshot isolation for reads, which means that it is safe to run  OPTIMIZE  even while other users or jobs are querying the table. Eventually however, you should clean up old snapshots. You can do this by running the  VACUUM  command: VACUUM events You control the age of the latest retained snapshot by using the  RETAIN   <N>   HOURS  option: VACUUM events RETAIN 24 HOURS Test the garbage collection You can specify  DRY   RUN  to test the garbage collection and return a list of files to be deleted: VACUUM events DRY RUN Configure the retention threshold The  VACUUM  command removes any files that are no longer in the latest state of the transaction log for the table and are older than a retention threshold. The default threshold is 7 days, but you can specify an alternate retention interval. For example, to delete all stale files older t...

Z-Ordering

Z-Ordering in Databricks Z-Ordering is a technique to colocate related information in the same set of files. This co-locality is automatically used by Delta Lake on Databricks data-skipping algorithms to dramatically reduce the amount of data that needs to be read. To Z-Order data, you specify the columns to order on in the  ZORDER   BY  clause: OPTIMIZE events WHERE date >= current_timestamp () - INTERVAL 1 day ZORDER BY ( eventType ) You can specify multiple columns for  ZORDER   BY  as a comma-separated list. However, the effectiveness of the locality drops with each additional column. Z-Ordering on columns that do not have statistics collected on them would be ineffective and a waste of resources as data skipping requires column-local stats such as min, max, and count. You can configure statistics collection on certain columns by re-ordering columns in the schema and/or increasing the number of columns to collect s...