Learning
Terraform

Egyszerű resource létrehozása

Egy alap AWS EC2 példa: provider + resource, majd változókra és outputokra bontás.

Egyszerű resource létrehozása

Teljes példa konfiguráció

provider "aws" {
  region = "us-east-1"
}

resource "aws_instance" "example" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t2.micro"

  tags = {
    Name        = "terraform-example"
    Environment = "dev"
  }
}

Változókkal rugalmasan

variable "aws_region" {
  description = "AWS régió"
  type        = string
  default     = "us-east-1"
}

variable "instance_type" {
  description = "EC2 instance típusa"
  type        = string
  default     = "t2.micro"
}

variable "environment" {
  description = "Deployment környezet"
  type        = string
  default     = "dev"
}
provider "aws" {
  region = var.aws_region
}

resource "aws_instance" "example" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = var.instance_type

  tags = {
    Name        = "terraform-example"
    Environment = var.environment
  }
}
output "instance_id" {
  description = "Az EC2 instance azonosítója"
  value       = aws_instance.example.id
}

output "instance_public_ip" {
  description = "Az EC2 instance publikus IP-je"
  value       = aws_instance.example.public_ip
}

On this page