diff --git a/examples/vpc/scenario02/main.tf b/examples/vpc/scenario02/main.tf index b368fa320..56f35eab1 100644 --- a/examples/vpc/scenario02/main.tf +++ b/examples/vpc/scenario02/main.tf @@ -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 @@ -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 diff --git a/ncloud/data_source_ncloud_nat_gateway_test.go b/ncloud/data_source_ncloud_nat_gateway_test.go index cf4ae8682..819a6bf83 100644 --- a/ncloud/data_source_ncloud_nat_gateway_test.go +++ b/ncloud/data_source_ncloud_nat_gateway_test.go @@ -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" ) @@ -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"), ), }, }, @@ -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" diff --git a/ncloud/resource_ncloud_nat_gateway_test.go b/ncloud/resource_ncloud_nat_gateway_test.go index c1ebc58d7..90fe50b3a 100644 --- a/ncloud/resource_ncloud_nat_gateway_test.go +++ b/ncloud/resource_ncloud_nat_gateway_test.go @@ -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) }, @@ -29,6 +30,10 @@ 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+$`)), ), }, { @@ -36,6 +41,11 @@ func TestAccResourceNcloudNatGateway_basic(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + ResourceName: resourcePrivate, + ImportState: true, + ImportStateVerify: true, + }, }, }) } @@ -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) } diff --git a/ncloud/resource_ncloud_route_test.go b/ncloud/resource_ncloud_route_test.go index 6964e6b8f..c34feaccd 100644 --- a/ncloud/resource_ncloud_route_test.go +++ b/ncloud/resource_ncloud_route_test.go @@ -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" }