Terraform - EC2

NuJey·2025년 3월 4일

Terraform EC2 생성하기

1. Main.tf 파일 구성

  1. Terraform 디렉터리 생성
  2. main.tf 파일 생성

Intellij Plugin 이용

main.tf

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.29.0"
    }
  }
  required_version = ">= 1.2.0"
}

provider "aws" {
  region = "ap-northeast-2" // Seoul
}

resource "aws_instance" "EC2-TEST" { // 
  ami                   = "ami-0ea766b7a13aecc49"
  instance_type         = "t4g.micro"
  tags = {
    Name = "ExampleAppServerInstance" // Instance name 
  }
}

2. Terraform Init

init을 통해 필요 플러그인 모듈 설치 및 파일 준비

terraform init
  • Terraform has been successfully initialized 문구가 뜨면 성공 !

3. Terraform plan

테라폼 코드 체크

4. Terraform apply

작성한 코드를 바탕으로 실제 AWS 환경에 적용

5. Terraform show

Terraform 상태 확인

6. Terraform state list

상태 목록 명령어

7. Terraform destory

Terraform 삭제

0개의 댓글