Ulaşım
- Adres:Batıkent Mh. 8910 Sk. 6. Etap 1H No: 18 Yeni Toki Eyyübiye / Şanlıurfa (Yeni Alım Satım Karşısı)
- Telefon:0 (545) 528 88 93
- eMail: info@alestaweb.com
Terraform ile AWS deployment (AWS infrastructure deployment with Terraform) öğrenmeye hazır mısınız? Infrastructure as Code (IaC) ile EC2, S3, VPC gibi AWS kaynaklarını kod ile yönetin! Alesta Web olarak sıfırdan başlayıp ilk Terraform AWS altyapınızı (your first Terraform AWS infrastructure) 10 dakikada kuracağız. Manuel tıklamalarla uğraşmayın, her şeyi kodlayın!
Terraform, HashiCorp tarafından geliştirilen açık kaynak Infrastructure as Code (IaC) aracıdır (open-source Infrastructure as Code tool). Basitçe söylemek gerekirse: Sunucu, network, storage gibi altyapı kaynaklarınızı kod ile tanımlarsınız (define infrastructure with code), Terraform bu kodu çalıştırarak gerçek kaynakları oluşturur.
Manuel Yöntem (❌ Eski Yol):
Terraform ile (✅ Modern Yol):
# main.tf dosyası
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
tags = {
Name = "AlestaWeb-Server"
}
}
# Komut
$ terraform apply
Hepsi bu kadar! 3 satır kod, 1 komut (3 lines of code, 1 command).
Alesta Web ekibi olarak Terraform'u şöyle tanımlıyoruz: Altyapınızın GitHub'ı. Kod ile versiyon kontrolü, takım çalışması ve otomasyonun zirvesi (version control, team collaboration, and automation at its peak)!
AWS CloudFormation gibi alternatifleri varken neden Terraform?
| Özellik / Feature | Terraform | AWS CloudFormation |
|---|---|---|
| Multi-Cloud | ✅ AWS, Azure, GCP, DigitalOcean hepsi! | ❌ Sadece AWS |
| Syntax (Dil) | HCL (okunması kolay / easy to read) | JSON/YAML (verbose) |
| State Yönetimi | Terraform state (S3'te saklanır) | AWS yönetir |
| Modüller | Terraform Registry (binlerce modül) | Sınırlı |
| Plan Preview | terraform plan (değişiklikleri görün) | Change sets (daha karmaşık) |
| Topluluk | Çok büyük (huge community) | AWS odaklı |
Eğer sadece AWS kullanıyorsanız ve AWS ekosisteminden çıkmayacaksanız CloudFormation iyidir. Ama multi-cloud düşünüyorsanız veya daha temiz syntax istiyorsanız (want cleaner syntax) - Terraform kesinlikle önde!
Windows:
# Chocolatey ile (with Chocolatey) choco install terraform # Veya manuel: terraform.io'dan binary indir # PATH'e ekle (add to PATH)
macOS:
# Homebrew ile brew tap hashicorp/tap brew install hashicorp/tap/terraform
Linux (Ubuntu/Debian):
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list sudo apt update && sudo apt install terraform
Kurulum Kontrolü (Verify Installation):
terraform --version # Output: Terraform v1.10.x
Windows/macOS/Linux:
# AWS CLI v2 kurulumu (install AWS CLI v2) # https://aws.amazon.com/cli/ adresinden indirin # Kurulum kontrolü aws --version # Output: aws-cli/2.x.x
Alesta Web olarak 2025'te Terraform 1.10+ ve AWS CLI 2.x kullanmanızı öneriyoruz (we recommend using Terraform 1.10+ and AWS CLI 2.x in 2025).
Terraform'un AWS'ye erişebilmesi için credentials (kimlik bilgileri) gereklidir:
terraform-userAdministratorAccess (veya daha kısıtlı policy / or more restricted policy)CSV'de Access Key ID ve Secret Access Key olacak.
aws configure # Girdiler (inputs): AWS Access Key ID: [ACCESS_KEY_ID buraya] AWS Secret Access Key: [SECRET_ACCESS_KEY buraya] Default region name: us-east-1 (veya eu-west-1 vb.) Default output format: json
Bu bilgiler ~/.aws/credentials dosyasına kaydedilir (saved to ~/.aws/credentials).
AWS credentials'ları ASLA kodunuza yazmayın (NEVER write credentials in code)! Git'e commit etmeyin! Environment variables veya AWS CLI config kullanın.
Alesta Web ile adım adım ilk Terraform projesini oluşturalım (let's create your first Terraform project step by step):
mkdir terraform-aws-demo cd terraform-aws-demo
# main.tf
# AWS Provider Tanımı (AWS Provider Definition)
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
required_version = ">= 1.2.0"
}
provider "aws" {
region = "us-east-1" # Bölge (Region)
}
# EC2 Instance Kaynağı (EC2 Instance Resource)
resource "aws_instance" "alesta_web_server" {
ami = "ami-0c55b159cbfafe1f0" # Amazon Linux 2 AMI
instance_type = "t2.micro" # Free tier eligible
tags = {
Name = "AlestaWeb-Demo-Server"
Environment = "Development"
ManagedBy = "Terraform"
}
}
# Output: Instance'ın public IP'sini göster (Show public IP)
output "instance_public_ip" {
description = "EC2 instance'ın public IP adresi"
value = aws_instance.alesta_web_server.public_ip
}
Terraform ile çalışma akışı (Terraform workflow):
terraform init
Ne yapar (What it does):
Output:
Initializing provider plugins... - Finding hashicorp/aws versions matching "~> 5.0"... - Installing hashicorp/aws v5.x.x... Terraform has been successfully initialized!
terraform plan
Ne yapar:
Output örneği:
Terraform will perform the following actions:
# aws_instance.alesta_web_server will be created
+ resource "aws_instance" "alesta_web_server" {
+ ami = "ami-0c55b159cbfafe1f0"
+ instance_type = "t2.micro"
...
}
Plan: 1 to add, 0 to change, 0 to destroy.
terraform apply
Veya onay beklemeden direkt uygula (apply without confirmation):
terraform apply -auto-approve
Ne yapar:
yes yazınOutput:
aws_instance.alesta_web_server: Creating... aws_instance.alesta_web_server: Creation complete after 45s Apply complete! Resources: 1 added, 0 changed, 0 destroyed. Outputs: instance_public_ip = "54.123.45.67"
terraform destroy
Ne yapar:
Kullanım senaryosu: Test ortamlarını temizleme, maliyet tasarrufu (clean test environments, cost savings)
Alesta Web best practice: Her zaman önce terraform plan çalıştırın, ne olacağını görün, sonra apply yapın (always run plan first, see what will happen, then apply)!
Gerçek dünya senaryosu (real-world scenario): Web uygulaması için tam altyapı (complete infrastructure for web app):
# variables.tf - Değişkenler (Variables)
variable "project_name" {
default = "alestaweb-app"
}
variable "region" {
default = "us-east-1"
}
# vpc.tf - Virtual Private Cloud
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "${var.project_name}-vpc"
}
}
resource "aws_subnet" "public" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.1.0/24"
availability_zone = "${var.region}a"
tags = {
Name = "${var.project_name}-public-subnet"
}
}
# s3.tf - Storage Bucket
resource "aws_s3_bucket" "app_storage" {
bucket = "${var.project_name}-storage-bucket"
tags = {
Name = "AlestaWeb App Storage"
Environment = "Production"
}
}
# ec2.tf - Web Server
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
subnet_id = aws_subnet.public.id
tags = {
Name = "${var.project_name}-web-server"
}
}
# outputs.tf - Çıktılar (Outputs)
output "vpc_id" {
value = aws_vpc.main.id
}
output "s3_bucket_name" {
value = aws_s3_bucket.app_storage.bucket
}
output "web_server_ip" {
value = aws_instance.web.public_ip
}
Alesta Web ekibi bu tür modüler yapıyı önerir (we recommend this modular structure): Her kaynak türü için ayrı dosya, bakımı kolay (separate file for each resource type, easy to maintain)!
# backend.tf
terraform {
backend "s3" {
bucket = "my-terraform-state-bucket"
key = "terraform.tfstate"
region = "us-east-1"
encrypt = true
}
}
Neden: Takım çalışmasında çakışma önler (prevents conflicts in team work), state güvenliğini artırır.
# ❌ Kötü (Bad) - Hard-coded değerler
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
}
# ✅ İyi (Good) - Değişkenler
variable "instance_type" {
default = "t2.micro"
}
resource "aws_instance" "web" {
ami = var.ami_id
instance_type = var.instance_type
}
# .gitignore .terraform/ *.tfstate *.tfstate.backup *.tfvars # Secret değişkenler (secret variables) .terraform.lock.hcl
ÖNEMLİ: State dosyalarını Git'e commit ETMEYİN (DO NOT commit state files to Git)!
# Terraform Registry'den hazır modül kullan (use ready modules from Terraform Registry)
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "5.0.0"
name = "my-vpc"
cidr = "10.0.0.0/16"
}
Kaynak: Terraform Registry
terraform plan önce çalıştırın (always run plan first in production)Bu makalede kullanılan bilgiler aşağıdaki güvenilir kaynaklardan alınmıştır (information used in this article is from the following reliable sources):
Alesta Web olarak tüm bilgileri Terraform 1.10+ ve AWS güncel servisleriyle doğruladık ve test ettik (we verified and tested all information with Terraform 1.10+ and current AWS services).
Terraform ile AWS deployment artık çok kolay! Infrastructure as Code (IaC) ile manuel tıklamalara veda edin, her şeyi versiyonlayın, takım ile çalışın, otomasyonun tadını çıkarın (enjoy automation)! Alesta Web olarak DevOps ve cloud altyapı projelerinizde size yardımcı olabiliriz. alestaweb.com üzerinden iletişime geçin!
Hızlı Özet / Quick Summary:
Faydalı Linkler / Useful Links:
1. İlk Terraform projenizi oluşturun (create your first project)
2. EC2 instance deploy edin (deploy EC2 instance)
3. S3 bucket ekleyin (add S3 bucket)
4. Production'da kullanmadan önce test edin (test before production)!
Alesta Web ekibi Terraform yolculuğunuzda başarılar diler!
© 2025 AlestaWeb - Tüm hakları saklıdır. Bu rehber Terraform 1.10+ ve AWS güncel servisleri için hazırlanmıştır.