Terraform
Installation on mac
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
brew upgrade hashicorp/tap/terraform
terraform -help
terraform -v
Add a terraform file
provider "aws" {
profile = "default"
region = "eu-west-1"
}
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"] # Canonical
}
resource "aws_instance" "app_server" {
ami = data.aws_ami.ubuntu.id
instance_type = "t2.micro"
tags = {
Name = "TrrInstance"
}
}
Run terraform init
in your project and to deploy these run terraform apply
. To delete these resource that were created terraform destroy
Terraform also takes a json config file main.tf.json
This is especially useful when generating Terraform configurations programmatically (e.g., using tools like CDKTF) or integrating Terraform with systems that prefer JSON.
{
"provider": {
"aws": {
"region": "us-east-1"
}
},
"resource": {
"aws_instance": {
"example": {
"ami": "ami-0c55b159cbfafe1f0",
"instance_type": "t2.micro",
"tags": {
"Name": "MyInstance"
}
}
}
}
}