#compute # 네트워크 추가, 블록 스토리지 추가된 인스턴스 생성 resource "nhncloud_compute_instance_v2" "web_server" { name = "web_server" key_pair = "seo1" flavor_id = data.nhncloud_compute_flavor_v2.web_server.id security_groups = ["default"] network { port = nhncloud_networking_port_v2.port_1.id } block_device { uuid = data.nhncloud_images_image_v2.ubuntu_22.id source_type = "image" destination_type = "volume" boot_index = 0 volume_size = 20 delete_on_termination = true } user_data = "#include https://kr2-api-object-storage.nhncloudservice.com/v1/AUTH_cf5a0f8add884a61a2f047ff8c16c4bb/real-iac-terraform/terra-index.txt" } resource "nhncloud_networking_port_v2" "port_1" { name = "tf_port_1" network_id = nhncloud_networking_vpc_v2.terraform_vpc.id fixed_ip { subnet_id = nhncloud_networking_vpcsubnet_v2.public_subnet.id } } #data data "nhncloud_compute_flavor_v2" "web_server"{ name = "m2.c1m2" } data "nhncloud_images_image_v2" "ubuntu_22" { name = "Ubuntu Server 22.04.5 LTS (2025.02.25)" } # network #VPC 생성 리소스 블록 resource "nhncloud_networking_vpc_v2" "terraform_vpc" { name = "terraform_vpc" cidrv4 = "10.0.0.0/16" } resource "nhncloud_networking_vpcsubnet_v2" "public_subnet" { name = "public_subnet" vpc_id = nhncloud_networking_vpc_v2.terraform_vpc.id cidr = "10.0.1.0/24" } resource "nhncloud_networking_vpcsubnet_v2" "private_subnet" { name = "private_subnet" vpc_id = nhncloud_networking_vpc_v2.terraform_vpc.id cidr = "10.0.2.0/24" } resource "nhncloud_networking_routingtable_v2" "private_rt" { name = "private_rt" vpc_id = nhncloud_networking_vpc_v2.terraform_vpc.id } # privider # Define required providers terraform { required_version = ">= 1.0.0" required_providers { nhncloud = { source = "nhn-cloud/nhncloud" version = "1.0.2" } } } provider "nhncloud" { user_name = var.nhncloud_info["user_name"] tenant_id = var.nhncloud_info["tenant_id"] password = var.passwd auth_url = var.nhncloud_info["auth_url"] region = var.region["kr2"] } # var variable nhncloud_info { type =map(string) default = { user_name = "topasvga@naver.com" tenant_id = "0ccc9863e23247e78a9fb6ad32d7cf43" password = "test" auth_url = "https://api-identity-infrastructure.nhncloudservice.com/v2.0" } } variable passwd { type = string default = "test" sensitive =true } variable region { type = map(string) default = { kr1 = "KR1" kr2 = "KR2" } }