Terraform enables IAF - Infra As Code.
sources - spacelift terraform-registry
providers.tf and main.tf - files are core and only thing we need to get started. Below is one example.
Both objects can be placed in main.tf or provider object in providers.tf and resource object in main.tf.
provider "aws" {
region = "us-east-1" # Replace with your desired AWS region
}
resource "aws_instance" "example" {
ami = "ami-0c02fb55956c7d316" # Replace with a valid AMI ID for your region
instance_type = "t2.micro"
}
Various commands and purposes-
terraform init - downloads required files about provider specified in providers.tf
terraform validate - checks for syntactical errors.
terraform plan - shows execution plan, such as, what all resources would be launched or stopped .
terraform apply - executes the plan. i.e.- launches, updates or destroys various resources.
terraform destroy - shutdown resources
terraform get - downloads dependent modules
terraform console - allows to see variable and more.
terraform output - displays outputs declared in script after resources are created.