AlestaSoft

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 Nedir? Infrastructure as Code (IaC) Nedir?
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.
Infrastructure as Code (IaC) Örneği
Manuel Yöntem (❌ Eski Yol):
- AWS Console'a giriş yap
- EC2 bölümüne git
- Launch Instance'a tıkla
- AMI seç, instance type seç, security group ayarla...
- 10-15 tıklama sonrası instance hazır
Terraform ile (✅ Modern Yol):
# main.tf dosyası
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
tags = {
Name = "AlestaWeb-Server"
}
}
# Komut
$ terraform applyHepsi 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)!
? Neden Terraform AWS İçin? (Why Terraform for AWS?)
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!
? Terraform ve AWS CLI Kurulumu (Installation)
1. Terraform Kurulumu (Install Terraform)
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/terraformLinux (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 terraformKurulum Kontrolü (Verify Installation):
terraform --version
# Output: Terraform v1.10.x2. AWS CLI Kurulumu (Install AWS CLI)
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.xAlesta 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).
? AWS Credentials Yapılandırması (AWS Credentials Configuration)
Terraform'un AWS'ye erişebilmesi için credentials (kimlik bilgileri) gereklidir:
Adım 1: AWS IAM Kullanıcısı Oluştur (Create IAM User)
- AWS Console → IAM → Users → Create User
- Kullanıcı adı:
terraform-user - Permissions:
AdministratorAccess(veya daha kısıtlı policy / or more restricted policy) - Access Key oluştur (Create Access Key) → CSV indir (download CSV)
CSV'de Access Key ID ve Secret Access Key olacak.
Adım 2: AWS CLI ile Yapılandır (Configure with AWS CLI)
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: jsonBu 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.
? İlk Terraform Projesi: EC2 Instance Oluşturma (First Terraform Project: Create EC2)
Alesta Web ile adım adım ilk Terraform projesini oluşturalım (let's create your first Terraform project step by step):
Adım 1: Proje Dizini Oluştur (Create Project Directory)
mkdir terraform-aws-demo
cd terraform-aws-demoAdım 2: main.tf Dosyası Oluştur (Create main.tf)
# 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 block: Terraform versiyonu ve provider'ları tanımlar
- provider "aws": AWS bağlantısını yapılandırır (configures AWS connection)
- resource "aws_instance": EC2 instance oluşturur
- output: Terraform apply sonrası bilgi gösterir (shows info after apply)
? Terraform Lifecycle: init, plan, apply, destroy
Terraform ile çalışma akışı (Terraform workflow):
1. terraform init - Projeyi Başlat (Initialize Project)
terraform initNe yapar (What it does):
- AWS provider'ı indirir (downloads AWS provider)
- .terraform dizini oluşturur
- Backend'i yapılandırır (configures backend)
Output:
Initializing provider plugins...
- Finding hashicorp/aws versions matching "~> 5.0"...
- Installing hashicorp/aws v5.x.x...
Terraform has been successfully initialized!2. terraform plan - Değişiklikleri Önizle (Preview Changes)
terraform planNe yapar:
- Mevcut altyapı ile kodu karşılaştırır (compares current infrastructure with code)
- Oluşturulacak/değiştirilecek/silinecek kaynakları gösterir
- Hiçbir şey oluşturmaz! (creates nothing - just preview)
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.3. terraform apply - Altyapıyı Oluştur (Create Infrastructure)
terraform applyVeya onay beklemeden direkt uygula (apply without confirmation):
terraform apply -auto-approveNe yapar:
- Plan'ı gösterir
- Onay ister:
yesyazın - AWS'de kaynakları oluşturur (creates resources in AWS)
- terraform.tfstate dosyası oluşturur (state file)
Output:
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"4. terraform destroy - Altyapıyı Sil (Destroy Infrastructure)
terraform destroyNe yapar:
- Terraform ile oluşturulan TÜM kaynakları siler (deletes ALL resources created by Terraform)
- Geri dönüşü yok! (irreversible!)
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)!
?️ İleri Düzey Örnek: VPC, S3, Load Balancer
Gerçek dünya senaryosu (real-world scenario): Web uygulaması için tam altyapı (complete infrastructure for web app):
Örnek: VPC + EC2 + S3 + ALB (Application Load Balancer)
# 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)!
✨ Terraform Best Practices ve Güvenlik (Best Practices and Security)
1. State Dosyasını Remote Storage'da Sakla (Store State in Remote Storage)
# 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.
2. Değişkenleri Kullan (Use Variables)
# ❌ 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
}3. .gitignore Kullan (Use .gitignore)
# .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)!
4. Modülleri Kullan (Use Modules)
# 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
- IAM kullanıcılarına minimum gerekli izinleri verin (give minimum required permissions)
- terraform.tfstate dosyası hassas bilgiler içerir - şifreleyin! (contains sensitive info - encrypt!)
- Production'da her zaman
terraform planönce çalıştırın (always run plan first in production) - Destroy komutunu dikkatli kullanın (use destroy carefully) - geri dönüşü yok!
? Kaynaklar ve Referanslar / Sources and References
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):
- HashiCorp - Terraform AWS Get Started - Resmi Terraform AWS tutorial
- HashiCorp - Create Infrastructure Tutorial - Altyapı oluşturma rehberi
- Atmosly - Terraform on AWS Complete Guide 2025 - Kapsamlı başlangıç rehberi
- Spacelift - Terraform on AWS - AWS kaynakları deployment
- DEV Community - Ultimate Terraform Tutorial 2025 - Başlangıçtan ileri seviyeye
- K21 Academy - Terraform Beginners Guide 2025 - Yeni başlayanlar için rehber
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 Altyapınızı Kodlayın! (Code Your AWS Infrastructure with Terraform!)
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:
- ✅ Terraform - Infrastructure as Code (IaC) aracı
- ✅ Multi-cloud: AWS, Azure, GCP hepsi desteklenir (all supported)
- ✅ Lifecycle: init → plan → apply → destroy
- ✅ HCL syntax kolay okunur (easy to read)
- ✅ State management ve team collaboration
- ✅ Terraform Registry'den binlerce modül (thousands of modules)
Faydalı Linkler / Useful Links:
- Alesta Web Ana Sayfa: alestaweb.com
- DevOps Tutorialları: DevOps Learning Path
- AWS Cloud Rehberleri: AWS Guides
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.

