Skip to content

Commit

Permalink
feat(vserver): Add the ability to create a KVM hypervisor type 3Gen s…
Browse files Browse the repository at this point in the history
…erver (#455)

* feat(vserver): Add VSERVER image numbers Data Source

* feat(vserver): Add VSERVER specs Data Source

* feat(vserver): Add the ability to create a KVM hypervisor type Gen3 server

* fix(vserver): Don't set the state when error responded

* review(vserver): Modify based on reviews
  • Loading branch information
youngmn authored Sep 27, 2024
1 parent 82109ad commit 5e4b421
Show file tree
Hide file tree
Showing 18 changed files with 1,245 additions and 81 deletions.
9 changes: 6 additions & 3 deletions docs/data-sources/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This module can be useful for getting detail of Server instance created before.

#### Basic usage

```hcl
```terraform
variable "instance_no" {}
data "ncloud_server" "server" {
Expand All @@ -21,7 +21,7 @@ data "ncloud_server" "server" {

#### Usage of using filter

```hcl
```terraform
variable "subnet_no" {}
variable "name" {}
Expand Down Expand Up @@ -84,4 +84,7 @@ The following arguments are supported:
* `private_ip` - IP address of the network interface.
* `init_script_no` - The ID of Init script.
* `placement_group_no` - The ID of Physical placement group.
* `is_encrypted_base_block_storage_volume` - Whether to encrypt basic block storage if server image is RHV.
* `is_encrypted_base_block_storage_volume` - Whether to encrypt basic block storage if server image is RHV.
* `hypervisor_type` - Hypervisor type. (`XEN` or `KVM`)
* `server_image_number` - Server image number.
* `server_spec_code` - Server spec code.
105 changes: 105 additions & 0 deletions docs/data-sources/server_image_numbers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
subcategory: "Server"
---


# Data Source: ncloud_server_image_numbers

To create a server instance (VM), you should select a server image. This data source gets a list of server images. You can look up the image numbers of Gen2(XEN) and Gen3(KVM) servers.

~> **NOTE:** This only supports VPC environment.

## Example Usage

The following example shows how to take a list of Server image.

```terraform
data "ncloud_server_image_numbers" "example" {
output_file = "image.json"
}
output "image_list" {
value = {
for image in data.ncloud_server_image_numbers.example.image_number_list:
image.server_image_number => [image.name, image.hypervisor_type]
}
}
```

Outputs:
```terraform
image_list = {
"16187005" = [
"ubuntu-20.04",
"XEN",
]
"16187007" = [
"win-2019-64-en",
"XEN",
]
"17552318" = [
"ubuntu-20.04-base",
"KVM",
]
"23789321" = [
"ubuntu-22.04-gpu",
"KVM",
]
"25495367" = [
"rocky-8.10-base",
"KVM",
]
"25623982" = [
"rocky-8.10-gpu",
"KVM",
]
"25624115" = [
"rocky-8.10-base",
"XEN",
]
}
```

```terraform
data "ncloud_server_image_numbers" "example" {
filter {
name = "name"
values = ["rocky-8.10-base"]
}
}
```

## Argument Reference

The following arguments are supported:

* `output_file` - (Optional) The name of file that can save data source after running `terraform plan`.
* `filter` - (Optional) Custom filter block as described below.
* `name` - (Required) The name of the field to filter by
* `values` - (Required) Set of values that are accepted for the given field.
* `regex` - (Optional) is `values` treated as a regular expression.

## Attributes Reference

This data source exports the following attributes in addition to the arguments above:

* `image_number_list` - List of SEVER image number.
* `server_image_number` - Server image number.
* `name` - Server image name.
* `description` - Server image description.
* `type` - Server image type. (`SELF` or `NCP`)
* `hypervisor_type` - Server image hypervisor type. (`XEN` or `KVM`)
* `cpu_architecture_type` - Server image cpu type.
* `os_category_type` - Server image os category type. (`LINUX` or `WINDOWS`)
* `os_type` - Server image os type. (`ROCKY` or `UBUNTU` or `CENTOS` or `WINDOWS`)
* `product_code` - The code of image product.
* `block_storage_mapping_list` - List of block storage allocated to the server image. Viewable after the server image is created.
* `order` - Block storage order.
* `block_storage_snapshot_instance_no` - Block storage snapshot instance number.
* `block_storage_snapshot_name` - Block storage snapshot name.
* `block_storage_size` - Block storage size (byte).
* `block_storage_name` - Block storage name.
* `block_storage_volume_type` - Block storage volume type. (`SSD` or `HDD` or `CB1` or `FB1`).
* `iops` - IOPS.
* `throughput` - Load balancing performance.
* `is_encrypted_volume` - Volume encryption status. (`true` or `false`)
84 changes: 84 additions & 0 deletions docs/data-sources/server_specs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
subcategory: "Server"
---


# Data Source: ncloud_server_specs

To create a server instance (VM), you should select a server spec. This data source gets a list of server specs. You can look up the spec code of servers.

~> **NOTE:** This only supports VPC environment.

## Example Usage

The following example shows how to take a list of Server spec.

```terraform
data "ncloud_server_specs" "example" {
output_file = "spec.json"
}
output "spec_list" {
value = {
for spec in data.ncloud_server_specs.example.server_spec_list:
spec.server_spec_code => [spec.description, spec.generation_code]
}
}
```

Outputs:
```terraform
spec_list = {
"c2-g3" = [
"vCPU 2EA, Memory 4GB",
"G3",
]
"m2-g3" = [
"vCPU 2EA, Memory 16GB",
"G3",
]
"c2-g2-s50" = [
"vCPU 2EA, Memory 4GB, [SSD]Disk 50GB",
"G2",
]
}
```

```terraform
data "ncloud_server_specs" "example" {
filter {
name = "server_spec_code"
values = ["c2-g3"]
}
}
```

## Argument Reference

The following arguments are supported:

* `output_file` - (Optional) The name of file that can save data source after running `terraform plan`.
* `filter` - (Optional) Custom filter block as described below.
* `name` - (Required) The name of the field to filter by
* `values` - (Required) Set of values that are accepted for the given field.
* `regex` - (Optional) is `values` treated as a regular expression.

## Attributes Reference

This data source exports the following attributes in addition to the arguments above:

* `server_spec_list` - List of SEVER spec.
* `server_spec_code` - Server spec code.
* `hypervisor_type` - Server hypervisor type. (`XEN` or `KVM`)
* `generation_code` - Server generation code. (`G2` or `G3`)
* `cpu_architecture_type` - Server cpu type.
* `cpu_count` - Server cpu count.
* `memory_size` - Server memory size(Byte).
* `block_storage_max_count` - Maximum number of BlockStorage that can be allocated.
* `block_storage_max_iops` - BlockStorage max IOPS.
* `block_storage_max_throughput` - BlockStorage max throughput(Mbps).
* `network_performance` - Network performance(bps).
* `network_interface_max_count` - Maximum number of network interfaces that can be allocated.
* `gpu_count` - GPU count.
* `description` - Server sepc description.
* `product_code` - The code of server product.
4 changes: 2 additions & 2 deletions docs/resources/block_storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Provides a Block Storage resource.

## Example Usage

```hcl
```terraform
resource "ncloud_block_storage" "storage" {
server_instance_no = "812345"
name = "tf-test-storage1"
Expand All @@ -23,7 +23,7 @@ The following arguments are supported:

* `size` - (Required) The size of the block storage to create. It is automatically set when you take a snapshot.
* `server_instance_no` - **(Required) When first created**. (Optional) After creation. Server instance ID to which you want to assign the block storage.
* `name` - (Optional) The name to create. If omitted, Terraform will assign a random, unique name.
* `name` - (Optional) The name to create. If omitted, Terraform will assign a random, unique name. Min: 3, Max: 30. Only English letters, numbers, and the special character "-" can be used. It must start with an English letter. It must end with an English letter or number.
* `description` - (Optional) description to create.
* `disk_detail_type` - (Optional) Type of block storage disk detail to create. Default `SSD`. Accepted values: `SSD` | `HDD`
* `stop_instance_before_detaching` - (Optional, Boolean) Set this to true to ensure that the target instance is stopped before trying to detach the block storage. It stops the instance, if it is not already stopped.
Expand Down
50 changes: 21 additions & 29 deletions docs/resources/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Provides a Server instance resource.

#### Basic (Classic)

```hcl
```terraform
resource "ncloud_server" "server" {
name = "tf-test-vm1"
server_image_product_code = "SPSW0LINUX000032"
Expand All @@ -31,7 +31,7 @@ resource "ncloud_server" "server" {

#### Basic (VPC)

```hcl
```terraform
resource "ncloud_login_key" "loginkey" {
key_name = "test-key"
}
Expand All @@ -52,14 +52,15 @@ resource "ncloud_subnet" "test" {
resource "ncloud_server" "server" {
subnet_no = ncloud_subnet.test.id
name = "my-tf-server"
server_image_product_code = "SW.VSVR.OS.LNX64.CNTOS.0703.B050"
server_image_number = "25495367"
server_spec_code = "s2-g3"
login_key_name = ncloud_login_key.loginkey.key_name
}
```

#### Create VPC instance reference by data source (retrieve image and product code)
#### Create VPC instance reference by data source (retrieve server_image_number and server_spec_code)

```hcl
```terraform
resource "ncloud_login_key" "loginkey" {
key_name = "test-key"
}
Expand All @@ -80,34 +81,22 @@ resource "ncloud_subnet" "test" {
resource "ncloud_server" "server" {
subnet_no = ncloud_subnet.test.id
name = "my-tf-server"
server_image_product_code = data.ncloud_server_image.server_image.id
server_product_code = data.ncloud_server_product.product.id
server_image_number = data.ncloud_server_image_numbers.server_image.image_number_list.0.server_image_number
server_spec_code = data.ncloud_server_specs.spec.server_spec_list.0.server_sepc_code
login_key_name = ncloud_login_key.loginkey.key_name
}
data "ncloud_server_image" "server_image" {
data "ncloud_server_image_numbers" "server_image" {
filter {
name = "os_information"
values = ["CentOS 7.3 (64-bit)"]
name = "name"
values = ["ubuntu-20.04-base"]
}
}
data "ncloud_server_product" "product" {
server_image_product_code = data.ncloud_server_image.server_image.id
filter {
name = "product_code"
values = ["SSD"]
}
filter {
name = "cpu_count"
values = ["2"]
}
data "ncloud_server_specs" "spec" {
filter {
name = "memory_size"
values = ["8GB"]
name = "server_spec_code"
values = ["s2-g3"]
}
}
```
Expand All @@ -116,17 +105,15 @@ data "ncloud_server_product" "product" {

The following arguments are supported:

* `server_image_product_code` - (Optional, Required if `member_server_image_no` is not provided) Server image product code to determine which server image to create. It can be obtained through `data.ncloud_server_image(s)`.
- [Docs server Image Products](https://github.com/NaverCloudPlatform/terraform-ncloud-docs/blob/main/docs/server_image_product.md)
* `server_image_product_code` - (Optional, Required if `member_server_image_no` or `server_image_number` is not provided) Server image product code to determine which server image to create. It can be obtained through `data.ncloud_server_image(s)`.
- [`ncloud_server_image` data source](../data-sources/server_image.md)
- [`ncloud_server_images` data source](../data-sources/server_images.md)

* `server_product_code` - (Optional) Server product code to determine the server specification to create. It can be obtained through the `data.ncloud_server_product(s)` action. Default : Selected as minimum specification. The minimum standards are 1. memory 2. CPU 3. basic block storage size 4. disk type (NET,LOCAL)
- [Docs server Image Products](https://github.com/NaverCloudPlatform/terraform-ncloud-docs/blob/main/docs/server_image_product.md)
- [`ncloud_server_product` data source](../data-sources/server_product.md)
- [`ncloud_server_products` data source](../data-sources/server_products.md)

* `member_server_image_no` - (Optional, Required if `server_image_product_code` is not provided) Required value when creating a server from a manually created server image. It can be obtained through the `data.ncloud_member_server_image(s)` action.
* `member_server_image_no` - (Optional, Required if `server_image_product_code` or `server_image_number` is not provided) Required value when creating a server from a manually created server image. It can be obtained through the `data.ncloud_member_server_image(s)` action.
- [`ncloud_member_server_image` data source](../data-sources/member_server_image.md)
- [`ncloud_member_server_images` data source](../data-sources/member_server_images.md)

Expand All @@ -149,6 +136,10 @@ The following arguments are supported:
~> **NOTE:** Below arguments only support VPC environment. Please set `support_vpc` of provider to `true`

* `subnet_no` - (Required) The ID of the associated Subnet.
* `server_image_number` - (Optional, Required if `server_image_product_code` or `member_server_image_no` is not provided) Required to create a KVM hypervisor type 3rd generation server. Server image number to determine which server image to create. It can be obtained through `data.ncloud_server_image_numbers`.
- [`ncloud_server_image_numbers` data source](../data-sources/server_image_numbers.md)
* `server_spec_code` - (Optional, Required if to select the spec) Available only if `server_image_number` is entered. Server spec code to determine the server specification to create. It can be obtained through the `data.ncloud_server_specs` action. Default : Selected as minimum specification. The minimum standards are 1. memory 2. CPU 3. basic block storage size 4. disk type (NET,LOCAL)
- [`ncloud_server_specs` data source](../data-sources/server_specs.md)
* `init_script_no` - (Optional) Set init script ID, The server can run a user-set initialization script at first boot.
* `placement_group_no` - (Optional) Physical placement group that belongs to the server instance.
* `network_interface` - (Optional) List of Network Interface. You can assign up to three network interfaces.
Expand Down Expand Up @@ -176,6 +167,7 @@ The following arguments are supported:
~> **NOTE:** Below attributes only provide VPC environment.

* `vpc_no` - The ID of the VPC where you want to place the Server Instance.
* `hypervisor_type` - Hypervisor type. (`XEN` or `KVM`)
* `network_interface` - List of Network Interface.
* `subnet_no` - Subnet ID of the network interface.
* `private_ip` - IP address of the network interface.
Expand Down
Loading

0 comments on commit 5e4b421

Please sign in to comment.