01
Erste Schritte
Provider
Provider definieren Cloud-Plattformen.
terraform
provider "aws" {
region = "us-east-1"
}Ressource
Resources definieren Infrastrukturobjekte.
terraform
resource "aws_instance" "web" {
ami = "ami-123456"
instance_type = "t2.micro"
tags = { Name = "WebServer" }
}Befehle
Kernworkflow: init, plan, apply, destroy.
terraform
# terraform init
# terraform plan
# terraform apply
# terraform destroy02
Features
Variablen
Variablen zur Parametrisierung.
terraform
variable "region" {
type = string
default = "us-east-1"
}
resource "aws_instance" "web" {
region = var.region
}Outputs
Outputs legen Werte nach apply offen.
terraform
output "instance_ip" {
value = aws_instance.web.public_ip
}Data Sources
Data Sources fragen bestehende Ressourcen ab.
terraform
data "aws_ami" "ubuntu" {
most_recent = true
filter { name = "name"; values = ["ubuntu-*"] }
}Was this helpful?