Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: vpc ncloud_server network interface assignment issue #479

Open
qkrshwns8481 opened this issue Nov 7, 2024 · 0 comments
Open

[Bug]: vpc ncloud_server network interface assignment issue #479

qkrshwns8481 opened this issue Nov 7, 2024 · 0 comments
Labels

Comments

@qkrshwns8481
Copy link

Terraform Core Version

Terraform v1.9.8

NCLOUD Provider Version

provider registry.terraform.io/navercloudplatform/ncloud v3.2.1

Affected Resource(s)

resource "ncloud_network_interface" "my_nic" {
name = "my-nic"
description = "terraform-nic"
subnet_no = ncloud_subnet.my_pubsubnet.id
private_ip = "10.0.1.6"
access_control_groups = [ncloud_access_control_group.my_acg.id]
}

resource "ncloud_server" "kvm-server" {
subnet_no = ncloud_subnet.my_pubsubnet.id
name = "kvm-web-server"
server_image_number = local.kvm_image[0].server_image_number
server_spec_code = local.kvm_spec[0].server_spec_code
login_key_name = ncloud_login_key.my_key.key_name
description = "terraform-kvm-server"
init_script_no = ncloud_init_script.my_init.id

network_interface {
network_interface_no = ncloud_network_interface.my_nic.id
order = 0
}

#depends_on = [ncloud_network_interface.my_nic]

#network_interface {

network_interface_no = ncloud_network_interface.my_nic2.id

order = 1

#}
}

Expected Behavior

I thought the server would be assigned 10.0.1.6 as the default network_interface.
10.0.1.6을 기본 NIC eth0으로 가지고 생성될 것이라고 생각했습니다.

Actual Behavior

The server hasn't even been created.
근데 서버가 만들어지지도 않았어요, 잘못된 파라미터로

Relevant Error/Panic Output Snippet

│ Error: Status: 400 Bad Request, Body: {
│   "responseError": {
│     "returnCode": "1100000",
│     "returnMessage": "Parameter is invalid. invalid overlayIp; networkInterface:NetworkInterfaceDto(vpcNo=81716, zoneNo=null, subnetNo=183920, networkInterfaceNo=4393826, networkInterfaceName=null, instanceType=null, ipAllotmentBlockNo=null, overlayIp=null, macAddress=null, cgnIp=null, isDefault=true, deleteOnTerminationYn=null, attachedDeviceName=null, order=0, accessControlGroups=[AccessControlGroupDto(accessControlGroupNo=216009)])"
│   }
│ }
│ 
│   with ncloud_server.kvm-server,
│   on compute.tf line 168, in resource "ncloud_server" "kvm-server":
│  168: resource "ncloud_server" "kvm-server" {
│ 
╵

Terraform Configuration Files

terraform {
required_providers {
ncloud = {
source = "NaverCloudPlatform/ncloud"
}
}
required_version = ">= 0.13"
}

data "ncloud_regions" "regions" {
//code = "KR"
output_file = "testfile1"
}

data "ncloud_zones" "zones" {
region = data.ncloud_regions.regions.regions[0].region_code // regions을 KR로 가져온다는 가정 하에
output_file = "testfile_zone" // 파일 경로
}

// Configure the ncloud provider
provider "ncloud" {
region = "KR"
support_vpc = true
}

//output "test" {
// description = "region data"
//value = [data.ncloud_regions.regions.regions[0],data.ncloud_regions.regions.regions[1]]
// value = ["Region 1: ${data.ncloud_regions.regions.regions[0].region_code}", "Region 2: ${data.ncloud_regions.regions.regions[1].region_code}"]
//value = {
// "First Region" = data.ncloud_regions.regions.regions[0]
// "Second Region" = data.ncloud_regions.regions.regions[1]
//}
//value = "Region 1: ${data.ncloud_regions.regions.regions[0].region_code}, Region 2: ${data.ncloud_regions.regions.regions[1].region_code}"
//}

resource "ncloud_vpc" "my_vpc" {
ipv4_cidr_block = "10.0.0.0/16"
name = "terraform-vpc"
}

// import resource
resource "ncloud_network_acl" "my_nacl" {
vpc_no = ncloud_vpc.my_vpc.id
// below fields is optional
name = "main"
description = "terraform"
}

resource "ncloud_subnet" "my_pubsubnet" {
vpc_no = ncloud_vpc.my_vpc.id
subnet = "10.0.1.0/24"
zone = "KR-2"
network_acl_no = ncloud_network_acl.my_nacl.id
subnet_type = "PUBLIC" // PUBLIC(Public) | PRIVATE(Private)
// below fields is optional
name = "${ncloud_vpc.my_vpc.name}-pub-sub"
usage_type = "GEN" // GEN(General) | LOADB(For load balancer)
}

resource "ncloud_subnet" "my_prisubnet" {
vpc_no = ncloud_vpc.my_vpc.id
subnet = "10.0.2.0/24"
zone = "KR-2"
network_acl_no = ncloud_network_acl.my_nacl.id
subnet_type = "PRIVATE" // PUBLIC(Public) | PRIVATE(Private)
// below fields is optional
name = "${ncloud_vpc.my_vpc.name}-pri-sub"
usage_type = "GEN" // GEN(General) | LOADB(For load balancer)
}

resource "ncloud_subnet" "my_nat_subnet" {
vpc_no = ncloud_vpc.my_vpc.id
subnet = "10.0.3.0/24"
zone = "KR-1"
network_acl_no = ncloud_network_acl.my_nacl.id
subnet_type = "PUBLIC" // PUBLIC(Public) | PRIVATE(Private)
// below fields is optional
name = "${ncloud_vpc.my_vpc.name}-pub-nat"
usage_type = "NATGW" // GEN(General) | LOADB(For load balancer)
}

resource "ncloud_route_table" "my_pub_route_table" {
vpc_no = ncloud_vpc.my_vpc.id
supported_subnet_type = "PUBLIC" // PUBLIC | PRIVATE
// below fields is optional
name = "${ncloud_vpc.my_vpc.name}-pub-route"
description = "public routing"
}

resource "ncloud_route_table" "my_pri_route_table" {
vpc_no = ncloud_vpc.my_vpc.id
supported_subnet_type = "PRIVATE" // PUBLIC | PRIVATE
// below fields is optional
name = "${ncloud_vpc.my_vpc.name}-pri-route"
description = "public routing"
}

resource "ncloud_nat_gateway" "my_nat_gateway" {
vpc_no = ncloud_vpc.my_vpc.id
subnet_no = ncloud_subnet.my_nat_subnet.id
zone = "KR-1"
// below fields are optional
private_ip = "10.0.3.20"
name = "terraform-nat-gw"
description = "terraform"
}

resource "ncloud_route" "my_route" {
route_table_no = ncloud_route_table.my_pri_route_table.id
destination_cidr_block = "0.0.0.0/0"
target_type = "NATGW" // NATGW (NAT Gateway) | VPCPEERING (VPC Peering) | VGW (Virtual Private Gateway).
target_name = ncloud_nat_gateway.my_nat_gateway.name
target_no = ncloud_nat_gateway.my_nat_gateway.id
}

resource "ncloud_route_table_association" "route_table_subnet" {
route_table_no = ncloud_route_table.my_pri_route_table.id
subnet_no = ncloud_subnet.my_prisubnet.id
}

output "vpc_attributes" {
value = ncloud_vpc.my_vpc
}

data "ncloud_server_image_numbers" "kvm_image" {
filter {
name = "hypervisor_type"
values = ["KVM"]
}

output_file = "kvm_image.json"
}

locals {
kvm_image = [
for img in data.ncloud_server_image_numbers.kvm_image.image_number_list :
img if img.type == "NCP" && img.os_type == "UBUNTU" && can(regex(".*22.04.base.", img.name)) == true
]
}

output "kvm_image_list" {
value = [
for img in local.kvm_image : {
name = img.name,
type = img.type,
hypervisor = img.hypervisor_type
description = img.description
}
]
}

data "ncloud_server_image_numbers" "xen_image" {
filter {
name = "hypervisor_type"
values = ["XEN"]
}

output_file = "xen_image.json"
}

locals {
xen_image = [
for img in data.ncloud_server_image_numbers.xen_image.image_number_list :
img if img.type == "NCP" && img.os_type == "UBUNTU" && can(regex(".*20.04$", img.name)) == true
]
}

output "xen_image_list" {
value = [
for img in local.xen_image : {
name = img.name,
type = img.type,
hypervisor = img.hypervisor_type
description = img.description
}
]
}

data "ncloud_server_specs" "kvm_spec" {
filter {
name = "hypervisor_type"
values = ["KVM"]
}

output_file = "kvm_spec.json"
}

locals {
kvm_spec = [
for spec in data.ncloud_server_specs.kvm_spec.server_spec_list :
spec if spec.cpu_count == 2 && spec.memory_size / 1024 / 1024 / 1024 == 4 && can(regex(".i.", spec.server_spec_code)) == false
]
}

output "kvm_spec_list" {
value = [
for spec in local.kvm_spec: {
spec_code = spec.server_spec_code,
hypervisor = spec.hypervisor_type,
generation = spec.generation_code,
cpu = spec.cpu_count,
memory = spec.memory_size / 1024 / 1024 / 1024,
description = spec.description
}
]
}

data "ncloud_server_specs" "xen_spec" {
filter {
name = "hypervisor_type"
values = ["XEN"]
}

output_file = "xen_spec.json"
}

locals {
xen_spec = [
for spec in data.ncloud_server_specs.xen_spec.server_spec_list :
spec if spec.cpu_count == 2 && spec.memory_size / 1024 / 1024 / 1024 == 4 && can(regex(".i.", spec.server_spec_code)) == false
&& can(regex(".s50.", spec.server_spec_code))
]
}

output "xen_spec_list" {
value = [
for spec in local.xen_spec: {
spec_code = spec.server_spec_code,
hypervisor = spec.hypervisor_type,
generation = spec.generation_code,
cpu = spec.cpu_count,
memory = spec.memory_size / 1024 / 1024 / 1024,
description = spec.description
}
]
}

resource "ncloud_init_script" "my_init" {
name = "terraform-script"
content = <<-EOF
#!/bin/bash
echo "test script" > test
pwd
EOF
}

resource "ncloud_login_key" "my_key" {
key_name = "terraform-key"
}

resource "ncloud_access_control_group" "my_acg" {
name = "terraform-acg"
description = "terraform"
vpc_no = ncloud_vpc.my_vpc.id
}

resource "ncloud_access_control_group_rule" "my_acg_rule" {
access_control_group_no = ncloud_access_control_group.my_acg.id

inbound {
protocol = "TCP"
ip_block = "121.138.156.5/32"
port_range = "22"
description = "accept 22 port"
}

outbound {
protocol = "TCP"
ip_block = "0.0.0.0/0"
port_range = "1-65535"
description = "accept 1-65535 port"
}
}

resource "ncloud_network_interface" "my_nic" {
name = "my-nic"
description = "terraform-nic"
subnet_no = ncloud_subnet.my_pubsubnet.id
private_ip = "10.0.1.6"
access_control_groups = [ncloud_access_control_group.my_acg.id]
#server_instance_no = ncloud_server.kvm-server.id
}

resource "ncloud_network_interface" "my_nic2" {
#name = "my-nic"
description = "terraform-nic"
subnet_no = ncloud_subnet.my_prisubnet.id
private_ip = "10.0.2.6"
access_control_groups = [ncloud_access_control_group.my_acg.id]
}

resource "ncloud_server" "kvm-server" {
subnet_no = ncloud_subnet.my_pubsubnet.id
name = "kvm-web-server"
server_image_number = local.kvm_image[0].server_image_number
server_spec_code = local.kvm_spec[0].server_spec_code
login_key_name = ncloud_login_key.my_key.key_name
description = "terraform-kvm-server"
init_script_no = ncloud_init_script.my_init.id

network_interface {
network_interface_no = ncloud_network_interface.my_nic.id
order = 0
}

#depends_on = [ncloud_network_interface.my_nic]

#network_interface {

network_interface_no = ncloud_network_interface.my_nic2.id

order = 1

#}
}

resource "ncloud_server" "xen-server" {
subnet_no = ncloud_subnet.my_pubsubnet.id
name = "xen-web-server"
server_image_number = local.xen_image[0].server_image_number
server_spec_code = local.xen_spec[0].server_spec_code
login_key_name = ncloud_login_key.my_key.key_name
description = "terraform-xen-server"
init_script_no = ncloud_init_script.my_init.id
}

Steps to Reproduce

terraform plan
terraform apply

Debug Output

│ Error: Status: 400 Bad Request, Body: {
│ "responseError": {
│ "returnCode": "1100000",
│ "returnMessage": "Parameter is invalid. invalid overlayIp; networkInterface:NetworkInterfaceDto(vpcNo=81716, zoneNo=null, subnetNo=183920, networkInterfaceNo=4393826, networkInterfaceName=null, instanceType=null, ipAllotmentBlockNo=null, overlayIp=null, macAddress=null, cgnIp=null, isDefault=true, deleteOnTerminationYn=null, attachedDeviceName=null, order=0, accessControlGroups=[AccessControlGroupDto(accessControlGroupNo=216009)])"
│ }
│ }

│ with ncloud_server.kvm-server,
│ on compute.tf line 168, in resource "ncloud_server" "kvm-server":
│ 168: resource "ncloud_server" "kvm-server" {

Panic Output

│ Error: Status: 400 Bad Request, Body: {
│ "responseError": {
│ "returnCode": "1100000",
│ "returnMessage": "Parameter is invalid. invalid overlayIp; networkInterface:NetworkInterfaceDto(vpcNo=81716, zoneNo=null, subnetNo=183920, networkInterfaceNo=4393826, networkInterfaceName=null, instanceType=null, ipAllotmentBlockNo=null, overlayIp=null, macAddress=null, cgnIp=null, isDefault=true, deleteOnTerminationYn=null, attachedDeviceName=null, order=0, accessControlGroups=[AccessControlGroupDto(accessControlGroupNo=216009)])"
│ }
│ }

│ with ncloud_server.kvm-server,
│ on compute.tf line 168, in resource "ncloud_server" "kvm-server":
│ 168: resource "ncloud_server" "kvm-server" {

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant