Skip to content

Commit

Permalink
feat: NAS and NATGW update (#268)
Browse files Browse the repository at this point in the history
* feat:NAS API update

* fix:ACG rule delete protocoltype num

* feat:NAT GW update
  • Loading branch information
youngmn authored Apr 21, 2023
1 parent ae8b890 commit 8444e74
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 45 deletions.
4 changes: 2 additions & 2 deletions docs/data-sources/subnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The following arguments are supported:
* `zone` - (Optional) Available zone where the subnet will be placed physically.
* `network_acl_no` - (Optional) The ID of Network ACL.
* `subnet_type` - (Optional) Internet connectivity. If you use `PUBLIC`, all VMs created within Subnet will be assigned a certified IP by default and will be able to communicate directly over the Internet. Considering the characteristics of Subnet, you can choose Subnet for the purpose of use. Accepted values: `PUBLIC` (Public) | `PRIVATE` (Private).
* `usage_type` - (Optional) Usage type, Accepted values: `GEN` (General) | `LOADB` (For load balancer).
* `usage_type` - (Optional) Usage type, Accepted values: `GEN` (General) | `LOADB` (For load balancer) | `NATGW` (for NAT Gateway. Only pub env)..
* `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.
Expand All @@ -47,4 +47,4 @@ The following arguments are supported:
In addition to all arguments above, the following attributes are exported:

* `subnet_no` - The ID of Subnet. (It is the same result as `id`)
* `name` - The name of Subnet.
* `name` - The name of Subnet.
4 changes: 2 additions & 2 deletions docs/data-sources/subnets.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The following arguments are supported:
* `zone` - (Optional) Available zone where the subnet will be placed physically.
* `network_acl_no` - (Optional) The ID of Network ACL.
* `subnet_type` - (Optional) Internet connectivity. If you use `PUBLIC`, all VMs created within Subnet will be assigned a certified IP by default and will be able to communicate directly over the Internet. Considering the characteristics of Subnet, you can choose Subnet for the purpose of use. Accepted values: `PUBLIC` (Public) | `PRIVATE` (Private).
* `usage_type` - (Optional) Usage type, Accepted values: `GEN` (General) | `LOADB` (For load balancer).
* `usage_type` - (Optional) Usage type, Accepted values: `GEN` (General) | `LOADB` (For load balancer) | `NATGW` (for NAT Gateway. Only pub env).
* `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.
Expand All @@ -56,4 +56,4 @@ The following attributes are exported:
* `zone` - Available zone where the Subnet is placed.
* `network_acl_no` - The ID of Network ACL.
* `subnet_type` - Internet connectivity.
* `usage_type` - Usage type.
* `usage_type` - Usage type.
16 changes: 8 additions & 8 deletions docs/resources/nas_volume.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ resource "ncloud_nas_volume" "test" {
The following arguments are supported:

* `volume_name_postfix` - (Required) Name of a NAS volume to create. Enter a volume name that is 3-20 characters in length after entering the name for user identification.
* `volume_size` - (Required) Enter the nas volume size to be created. You can enter in GiB.
* `volume_size` - (Required) NAS volume size. The default capacity of a volume ranges from 500 GB to 10,000 GB. Additions can be made in units of 100 GB.
* `volume_allotment_protocol_type` - (Required) Volume allotment protocol type code. `NFS` | `CIFS`
`NFS`: You can mount the volume in a Linux server such as CentOS and Ubuntu.
`CIFS`: You can mount the volume in a Windows server.
* `server_instance_no_list` - (Optional) List of server instance numbers for which access to NFS is to be controlled.
* `cifs_user_name` - (Optional) CIFS user name. The ID must contain a combination of English alphabet and numbers, which can be 6-20 characters in length.
* `cifs_user_password` - (Optional) CIFS user password. The password must contain a combination of at least 2 English letters, numbers and special characters, which can be 8-14 characters in length.
* `description` - (Optional) NAS volume description
* `zone` - (Optional) Zone code. Zone in which you want to create a NAS volume. Default: The first zone of the region.
Get available values using the data source `ncloud_zones`.
* `server_instance_no_list` - (Optional) List of server instance numbers where you want to mount the NAS volume.
* `cifs_user_name` - (Optional) CIFS user name. The ID must contain a combination of English alphabet and numbers, which can be 6-19 characters in length.
* `cifs_user_password` - (Optional) CIFS user password. The password must contain a combination of at least 2 English letters, numbers and special characters, which can be 8-14 characters in length.
* `description` - (Optional) NAS volume description. 1-1000 characters.
* `zone` - (Optional) Zone code. Zone in which you want to create a NAS volume. Default: The first zone of the region. Get available values using the data source `ncloud_zones`.
* `return_protection` - (Optional) Termination protection status. Default `false`

~> **NOTE:** Below arguments only support Classic environment.

Expand All @@ -46,4 +46,4 @@ The following arguments are supported:
* `snapshot_volume_size` - Snapshot volume size, in GiB
* `is_snapshot_configuration` - Indicates whether a snapshot volume is set.
* `is_event_configuration` - Indicates whether the event is set.
* `mount_information` - Mount information for NAS volume.
* `mount_information` - Mount information for NAS volume.
5 changes: 4 additions & 1 deletion docs/resources/nat_gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ In addition to all arguments above, the following attributes are exported:

* `id` - The ID of the NAT Gateway.
* `nat_gateway_no` - The ID of the NAT Gateway. (It is the same result as `id`)
* `public_ip` - Public IP on created NAT Gateway.
* `public_ip` - Public IP on created NAT Gateway.
* `subnet_name` - Subnet name on created NAT Gateway.
* `subnet_no` - Subnet ID on created NAT Gateway.
* `private_ip` - Private IP on created NAT Gateway.
2 changes: 1 addition & 1 deletion docs/resources/subnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The following arguments are supported:
* `network_acl_no` - (Required) The ID of Network ACL.
* `subnet_type` - (Required) Internet connectivity. If you use `PUBLIC` all VMs created within Subnet will be assigned a certified IP by default and will be able to communicate directly over the Internet. Considering the characteristics of Subnet, you can choose Subnet for the purpose of use. Accepted values: `PUBLIC` (Public) | `PRIVATE` (Private).
* `name` - (Optional) The name to create. If omitted, Terraform will assign a random, unique name.
* `usage_type` - (Optional) Usage type, Default `GEN`. Accepted values: `GEN` (General) | `LOADB` (For load balancer).
* `usage_type` - (Optional) Usage type, Default `GEN`. Accepted values: `GEN` (General) | `LOADB` (For load balancer) | `NATGW` (for NAT Gateway. Only pub env).

## Attributes Reference

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/terraform-providers/terraform-provider-ncloud
go 1.19

require (
github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.5.8
github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.6.2
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1
gopkg.in/yaml.v3 v3.0.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/cFDk=
github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0=
github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.5.8 h1:9NEbo6OCppxbeiIt/7f6DhEypHFQ6JBknmOKnHKaLyU=
github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.5.8/go.mod h1:KWd9AT+YSM6qgsMzPnE23h2/r0bsPSIdJzZIg3BUcfI=
github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.6.2 h1:Hv2aCNGVVD4tKXYivtENi+9+/zgHL+H05uKMkqpr5Xk=
github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.6.2/go.mod h1:KWd9AT+YSM6qgsMzPnE23h2/r0bsPSIdJzZIg3BUcfI=
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ=
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo=
github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk=
Expand Down
2 changes: 1 addition & 1 deletion ncloud/data_source_ncloud_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func dataSourceNcloudSubnet() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateDiagFunc: ToDiagFunc(validation.StringInSlice([]string{"GEN", "LOADB", "BM"}, false)),
ValidateDiagFunc: ToDiagFunc(validation.StringInSlice([]string{"GEN", "LOADB", "BM", "NATGW"}, false)),
},
"filter": dataSourceFiltersSchema(),
}
Expand Down
4 changes: 2 additions & 2 deletions ncloud/data_source_ncloud_subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ func dataSourceNcloudSubnets() *schema.Resource {
"usage_type": {
Type: schema.TypeString,
Optional: true,
ValidateDiagFunc: ToDiagFunc(validation.StringInSlice([]string{"GEN", "LOADB", "BM"}, false)),
Description: "Usage type. GEN(Normal), LOADB(Load Balance), BM(BareMetal). default : GEN(Normal).",
ValidateDiagFunc: ToDiagFunc(validation.StringInSlice([]string{"GEN", "LOADB", "BM", "NATGW"}, false)),
Description: "Usage type. GEN(Normal), LOADB(Load Balance), BM(BareMetal), NATGW(NAT Gateway). default : GEN(Normal).",
},
"filter": dataSourceFiltersSchema(),
"subnets": {
Expand Down
3 changes: 0 additions & 3 deletions ncloud/resource_ncloud_access_control_group_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"log"
"regexp"
"strconv"
"time"

"github.com/NaverCloudPlatform/ncloud-sdk-go-v2/ncloud"
Expand Down Expand Up @@ -160,8 +159,6 @@ func resourceNcloudAccessControlGroupRuleRead(d *schema.ResourceData, meta inter
var protocol string
if allowedProtocolCodes[*r.ProtocolType.Code] {
protocol = *r.ProtocolType.Code
} else {
protocol = strconv.Itoa(int(*r.ProtocolType.Number))
}

m := map[string]interface{}{
Expand Down
86 changes: 65 additions & 21 deletions ncloud/resource_ncloud_nas_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ func resourceNcloudNasVolume() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateDiagFunc: ToDiagFunc(validation.StringLenBetween(3, 30)),
ValidateDiagFunc: ToDiagFunc(validation.StringLenBetween(3, 20)),
},
"volume_size": {
Type: schema.TypeInt,
Required: true,
ValidateDiagFunc: ToDiagFunc(validation.IntBetween(100, 10000)),
ValidateDiagFunc: ToDiagFunc(validation.IntBetween(500, 10000)),
},
"volume_allotment_protocol_type": {
Type: schema.TypeString,
Expand Down Expand Up @@ -88,7 +88,11 @@ func resourceNcloudNasVolume() *schema.Resource {
Optional: true,
Computed: true,
},

"is_return_protection": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"nas_volume_no": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -233,6 +237,7 @@ func convertClassicNasVolume(inst *server.NasVolumeInstance) *NasVolume {
NasVolumeInstanceCustomIpList: flattenArrayStructByKey(inst.NasVolumeInstanceCustomIpList, "customIp"),
ServerInstanceNoList: flattenArrayStructByKey(inst.NasVolumeServerInstanceList, "serverInstanceNo"),
MountInformation: inst.MountInformation,
IsReturnProtection: inst.IsReturnProtection,
}
}

Expand Down Expand Up @@ -278,6 +283,7 @@ func convertVpcNasVolume(inst *vnas.NasVolumeInstance) *NasVolume {
ServerInstanceNoList: inst.NasVolumeServerInstanceNoList,
NasVolumeInstanceCustomIpList: []*string{},
MountInformation: inst.MountInformation,
IsReturnProtection: inst.IsReturnProtection,
}
}

Expand Down Expand Up @@ -315,20 +321,14 @@ func createClassicNasVolume(d *schema.ResourceData, config *ProviderConfig) (*st
reqParams := &server.CreateNasVolumeInstanceRequest{
RegionNo: regionNo,
ZoneNo: zoneNo,
AccessControlRuleList: makeClassicNasAclParams(d),
VolumeName: ncloud.String(d.Get("volume_name_postfix").(string)),
VolumeSize: ncloud.Int32(int32(d.Get("volume_size").(int))),
VolumeAllotmentProtocolTypeCode: ncloud.String(d.Get("volume_allotment_protocol_type").(string)),
CifsUserName: StringPtrOrNil(d.GetOk("cifs_user_name")),
CifsUserPassword: StringPtrOrNil(d.GetOk("cifs_user_password")),
NasVolumeDescription: StringPtrOrNil(d.GetOk("description")),
}

if serverInstanceNoList, ok := d.GetOk("server_instance_no_list"); ok {
reqParams.ServerInstanceNoList = expandStringInterfaceList(serverInstanceNoList.([]interface{}))
}

if customIPList, ok := d.GetOk("custom_ip_list"); ok {
reqParams.CustomIpList = expandStringInterfaceList(customIPList.([]interface{}))
IsReturnProtection: BoolPtrOrNil(d.GetOk("is_return_protection")),
}

logCommonRequest("createClassicNasVolume", reqParams)
Expand All @@ -347,17 +347,15 @@ func createVpcNasVolume(d *schema.ResourceData, config *ProviderConfig) (*string
reqParams := &vnas.CreateNasVolumeInstanceRequest{
RegionCode: &config.RegionCode,
ZoneCode: StringPtrOrNil(d.GetOk("zone")),
AccessControlRuleList: makeVpcNasAclParams(d),
VolumeName: ncloud.String(d.Get("volume_name_postfix").(string)),
VolumeSize: ncloud.Int32(int32(d.Get("volume_size").(int))),
VolumeAllotmentProtocolTypeCode: ncloud.String(d.Get("volume_allotment_protocol_type").(string)),
CifsUserName: StringPtrOrNil(d.GetOk("cifs_user_name")),
CifsUserPassword: StringPtrOrNil(d.GetOk("cifs_user_password")),
NasVolumeDescription: StringPtrOrNil(d.GetOk("description")),
IsEncryptedVolume: BoolPtrOrNil(d.GetOk("is_encrypted_volume")),
}

if serverInstanceNoList, ok := d.GetOk("server_instance_no_list"); ok {
reqParams.ServerInstanceNoList = expandStringInterfaceList(serverInstanceNoList.([]interface{}))
IsReturnProtection: BoolPtrOrNil(d.GetOk("is_return_protection")),
}

logCommonRequest("createVpcNasVolume", reqParams)
Expand Down Expand Up @@ -539,9 +537,8 @@ func setNasVolumeAccessControl(d *schema.ResourceData, config *ProviderConfig) e

func setClassicNasVolumeAccessControl(d *schema.ResourceData, config *ProviderConfig) error {
reqParams := &server.SetNasVolumeAccessControlRequest{
NasVolumeInstanceNo: ncloud.String(d.Id()),
ServerInstanceNoList: expandStringInterfaceList(d.Get("server_instance_no_list").([]interface{})),
CustomIpList: expandStringInterfaceList(d.Get("custom_ip_list").([]interface{})),
NasVolumeInstanceNo: ncloud.String(d.Id()),
AccessControlRuleList: makeClassicNasAclParams(d),
}

logCommonRequest("setClassicNasVolumeAccessControl", reqParams)
Expand All @@ -558,9 +555,9 @@ func setClassicNasVolumeAccessControl(d *schema.ResourceData, config *ProviderCo

func setVpcNasVolumeAccessControl(d *schema.ResourceData, config *ProviderConfig) error {
reqParams := &vnas.SetNasVolumeAccessControlRequest{
RegionCode: &config.RegionCode,
NasVolumeInstanceNo: ncloud.String(d.Id()),
ServerInstanceNoList: expandStringInterfaceList(d.Get("server_instance_no_list").([]interface{})),
RegionCode: &config.RegionCode,
NasVolumeInstanceNo: ncloud.String(d.Id()),
AccessControlRuleList: makeVpcNasAclParams(d),
}

logCommonRequest("setVpcNasVolumeAccessControl", reqParams)
Expand All @@ -575,6 +572,52 @@ func setVpcNasVolumeAccessControl(d *schema.ResourceData, config *ProviderConfig
return nil
}

func makeClassicNasAclParams(d *schema.ResourceData) []*server.AccessControlRuleParameter {
var aclParams []*server.AccessControlRuleParameter
var serverList []*string
var customIpList []*string

if serverInstanceNoList, ok := d.GetOk("server_instance_no_list"); ok {
serverList = expandStringInterfaceList(serverInstanceNoList.([]interface{}))

for _, v := range serverList {
aclParams = append(aclParams, &server.AccessControlRuleParameter{
ServerInstanceNo: v,
})
}
return aclParams
}

if customIPList, ok := d.GetOk("custom_ip_list"); ok {
customIpList = expandStringInterfaceList(customIPList.([]interface{}))

for _, v := range customIpList {
aclParams = append(aclParams, &server.AccessControlRuleParameter{
CustomIp: v,
})
}
}

return aclParams
}

func makeVpcNasAclParams(d *schema.ResourceData) []*vnas.AccessControlRuleParameter {
var aclParams []*vnas.AccessControlRuleParameter
var serverList []*string

if serverInstanceNoList, ok := d.GetOk("server_instance_no_list"); ok {
serverList = expandStringInterfaceList(serverInstanceNoList.([]interface{}))

for _, v := range serverList {
aclParams = append(aclParams, &vnas.AccessControlRuleParameter{
ServerInstanceNo: v,
})
}
}

return aclParams
}

// NasVolume Dto for NAS
type NasVolume struct {
NasVolumeInstanceNo *string `json:"nas_volume_no,omitempty"`
Expand All @@ -592,4 +635,5 @@ type NasVolume struct {
IsEncryptedVolume *bool `json:"is_encrypted_volume,omitempty"`
Status *string `json:"-"`
MountInformation *string `json:"mount_information,omitempty"`
IsReturnProtection *bool `json:"is_return_protection,omitempty"`
}
15 changes: 15 additions & 0 deletions ncloud/resource_ncloud_nat_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ func resourceNcloudNatGateway() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"subnet_name": {
Type: schema.TypeString,
Computed: true,
},
"subnet_no": {
Type: schema.TypeString,
Computed: true,
},
"private_ip": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -122,6 +134,9 @@ func resourceNcloudNatGatewayRead(d *schema.ResourceData, meta interface{}) erro
d.Set("public_ip", instance.PublicIp)
d.Set("vpc_no", instance.VpcNo)
d.Set("zone", instance.ZoneCode)
d.Set("subnet_name", instance.SubnetName)
d.Set("subnet_no", instance.SubnetNo)
d.Set("private_ip", instance.PrivateIp)

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion ncloud/resource_ncloud_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func resourceNcloudSubnet() *schema.Resource {
Optional: true,
Computed: true,
ForceNew: true,
ValidateDiagFunc: ToDiagFunc(validation.StringInSlice([]string{"GEN", "LOADB", "BM"}, false)),
ValidateDiagFunc: ToDiagFunc(validation.StringInSlice([]string{"GEN", "LOADB", "BM", "NATGW"}, false)),
},
"subnet_no": {
Type: schema.TypeString,
Expand Down

0 comments on commit 8444e74

Please sign in to comment.