Terraform - nhn cloud: 인스턴스 생성하기

Terraform 사용 가이드

provider.tf

# Define required providers
terraform {
required_version = ">= 1.0.0"
  required_providers {
    nhncloud = {
      source  = "nhn-cloud/nhncloud"
      version = "1.0.2"
    }
  }
}

# Configure the nhncloud Provider
provider "nhncloud" {
  user_name   = "terraform-guide@nhncloud.com"
  tenant_id   = "aaa4c0a12fd84edeb68965d320d17129"
  password    = "difficultpassword"
  auth_url  = "https://api-identity-infrastructure.nhncloudservice.com/v2.0"
  region    = "KR1"
}

instance.tf

resource "nhncloud_compute_instance_v2" "terraform-instance-01" {
  name      = "terraform-instance-01"
  region    = "KR1"
  key_pair  = "Compute > Key Pair > 키페어 이름 하나 선택"
  image_id = data.nhncloud_images_image_v2.Ubuntu_Server_22_04_LTS.id
  flavor_id = data.nhncloud_compute_flavor_v2.t2c1m1.id
  security_groups = ["default"]
  availability_zone = "kr-pub-a"

  network {
    name = data.nhncloud_networking_vpc_v2.default_network.name
    uuid = data.nhncloud_networking_vpc_v2.default_network.id
  }

  block_device {
    uuid = data.nhncloud_images_image_v2.Ubuntu_Server_22_04_LTS.id
    source_type = "image"
    destination_type = "volume"
    boot_index = 0
    delete_on_termination = true
    volume_size = 30
  }
}

data "nhncloud_compute_flavor_v2" "t2c1m1"{
  name = "t2.c1m1"
}

data "nhncloud_images_image_v2" "Ubuntu_Server_22_04_LTS" {
  name = "Ubuntu Server 22.04.4 LTS (2024.08.20)"
  most_recent = true
}

data "nhncloud_networking_vpc_v2" "default_network" {
  region = "KR1"
  tenant_id = "Network > VPC > Default Network > 테넌트 ID"
  id = "Network > VPC > Default Network > VPC ID"
  name = "Default Network"
}

실습 명령어

terraform init
terraform plan
terraform apply
terraform destroy