Skip to content

Commit

Permalink
update:test file (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
youngmn authored Jun 21, 2023
1 parent db72307 commit 0afb3bf
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 4 deletions.
17 changes: 14 additions & 3 deletions examples/vpc/scenario02/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ resource "ncloud_subnet" "subnet_scn_02_private" {
// PRIVATE(Private)
}

resource "ncloud_subnet" "subnet_scn_02_public_natgw" {
vpc_no = ncloud_vpc.vpc_scn_02.id
subnet = cidrsubnet(ncloud_vpc.vpc_scn_02.ipv4_cidr_block, 8, 2)
// "10.0.2.0/24"
zone = "KR-2"
network_acl_no = ncloud_network_acl.network_acl_02_public.id
subnet_type = "PUBLIC"
usage_type = "NATGW"
}

# Network ACL
resource "ncloud_network_acl" "network_acl_02_public" {
vpc_no = ncloud_vpc.vpc_scn_02.id
Expand Down Expand Up @@ -78,9 +88,10 @@ resource "ncloud_public_ip" "public_ip_scn_02" {

# NAT Gateway
resource "ncloud_nat_gateway" "nat_gateway_scn_02" {
vpc_no = ncloud_vpc.vpc_scn_02.id
zone = "KR-2"
name = var.name_scn02
vpc_no = ncloud_vpc.vpc_scn_02.id
subnet_no = ncloud_subnet.subnet_scn_02_public_natgw.id
zone = "KR-2"
name = var.name_scn02
}

# Route Table
Expand Down
16 changes: 15 additions & 1 deletion ncloud/data_source_ncloud_nat_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package ncloud

import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

Expand All @@ -29,6 +30,9 @@ func TestAccDataSourceNcloudNatGateway_basic(t *testing.T) {
resource.TestCheckResourceAttrPair(dataName, "nat_gateway_no", resourceName, "nat_gateway_no"),
resource.TestCheckResourceAttrPair(dataName, "zone", resourceName, "zone"),
resource.TestCheckResourceAttrPair(dataName, "vpc_no", resourceName, "vpc_no"),
resource.TestCheckResourceAttrPair(dataName, "subnet_no", resourceName, "subnet_no"),
resource.TestCheckResourceAttrPair(dataName, "subnet_name", resourceName, "subnet_name"),
resource.TestCheckResourceAttrPair(dataName, "public_ip_no", resourceName, "public_ip_no"),
),
},
},
Expand All @@ -42,8 +46,18 @@ resource "ncloud_vpc" "vpc" {
ipv4_cidr_block = "10.3.0.0/16"
}
resource "ncloud_subnet" "subnet" {
vpc_no = ncloud_vpc.vpc.id
subnet = cidrsubnet(ncloud_vpc.vpc.ipv4_cidr_block, 8, 1)
zone = "KR-1"
network_acl_no = ncloud_vpc.vpc.default_network_acl_no
subnet_type = "PUBLIC"
usage_type = "NATGW"
}
resource "ncloud_nat_gateway" "nat_gateway" {
vpc_no = ncloud_vpc.vpc.vpc_no
subnet_no = ncloud_subnet.subnet.id
zone = "KR-1"
name = "%[1]s"
description = "description"
Expand Down
36 changes: 36 additions & 0 deletions ncloud/resource_ncloud_nat_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func TestAccResourceNcloudNatGateway_basic(t *testing.T) {
var natGateway vpc.NatGatewayInstance
name := fmt.Sprintf("test-nat-gateway-%s", acctest.RandString(5))
resourceName := "ncloud_nat_gateway.nat_gateway"
resourcePrivate := "ncloud_nat_gateway.nat_gateway_private"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -29,13 +30,22 @@ func TestAccResourceNcloudNatGateway_basic(t *testing.T) {
resource.TestMatchResourceAttr(resourceName, "vpc_no", regexp.MustCompile(`^\d+$`)),
resource.TestMatchResourceAttr(resourceName, "nat_gateway_no", regexp.MustCompile(`^\d+$`)),
resource.TestCheckResourceAttr(resourceName, "name", name),

testAccCheckNatGatewayExists(resourcePrivate, &natGateway),
resource.TestMatchResourceAttr(resourcePrivate, "vpc_no", regexp.MustCompile(`^\d+$`)),
resource.TestMatchResourceAttr(resourcePrivate, "nat_gateway_no", regexp.MustCompile(`^\d+$`)),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
ResourceName: resourcePrivate,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -155,12 +165,38 @@ resource "ncloud_vpc" "vpc" {
ipv4_cidr_block = "10.3.0.0/16"
}
resource "ncloud_subnet" "subnet_public" {
vpc_no = ncloud_vpc.vpc.id
subnet = cidrsubnet(ncloud_vpc.vpc.ipv4_cidr_block, 8, 1)
zone = "KR-1"
network_acl_no = ncloud_vpc.vpc.default_network_acl_no
subnet_type = "PUBLIC"
usage_type = "NATGW"
}
resource "ncloud_subnet" "subnet_private" {
vpc_no = ncloud_vpc.vpc.id
subnet = cidrsubnet(ncloud_vpc.vpc.ipv4_cidr_block, 8, 2)
zone = "KR-1"
network_acl_no = ncloud_vpc.vpc.default_network_acl_no
subnet_type = "PRIVATE"
usage_type = "NATGW"
}
resource "ncloud_nat_gateway" "nat_gateway" {
vpc_no = ncloud_vpc.vpc.vpc_no
subnet_no = ncloud_subnet.subnet_public.id
zone = "KR-1"
name = "%[1]s"
description = "%[2]s"
}
resource "ncloud_nat_gateway" "nat_gateway_private" {
vpc_no = ncloud_vpc.vpc.vpc_no
subnet_no = ncloud_subnet.subnet_private.id
zone = "KR-1"
description = "%[2]s"
}
`, name, description)
}

Expand Down
10 changes: 10 additions & 0 deletions ncloud/resource_ncloud_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,18 @@ resource "ncloud_route_table" "route_table" {
supported_subnet_type = "PRIVATE"
}
resource "ncloud_subnet" "subnet" {
vpc_no = ncloud_vpc.vpc.id
subnet = cidrsubnet(ncloud_vpc.vpc.ipv4_cidr_block, 8, 1)
zone = "KR-1"
network_acl_no = ncloud_vpc.vpc.default_network_acl_no
subnet_type = "PUBLIC"
usage_type = "NATGW"
}
resource "ncloud_nat_gateway" "nat_gateway" {
vpc_no = ncloud_vpc.vpc.id
subnet_no = ncloud_subnet.subnet.id
zone = "KR-1"
}
Expand Down

0 comments on commit 0afb3bf

Please sign in to comment.