diff --git a/docs/data-sources/subnet.md b/docs/data-sources/subnet.md index db8539f4d..238bb7253 100644 --- a/docs/data-sources/subnet.md +++ b/docs/data-sources/subnet.md @@ -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. @@ -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. \ No newline at end of file +* `name` - The name of Subnet. diff --git a/docs/data-sources/subnets.md b/docs/data-sources/subnets.md index 37e7f20bc..b525531a6 100644 --- a/docs/data-sources/subnets.md +++ b/docs/data-sources/subnets.md @@ -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. @@ -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. \ No newline at end of file +* `usage_type` - Usage type. diff --git a/docs/resources/nas_volume.md b/docs/resources/nas_volume.md index 92ce96c3f..db2c741d8 100644 --- a/docs/resources/nas_volume.md +++ b/docs/resources/nas_volume.md @@ -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. @@ -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. \ No newline at end of file +* `mount_information` - Mount information for NAS volume. diff --git a/docs/resources/nat_gateway.md b/docs/resources/nat_gateway.md index 3fa0570bf..bb19099ef 100644 --- a/docs/resources/nat_gateway.md +++ b/docs/resources/nat_gateway.md @@ -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. \ No newline at end of file +* `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. diff --git a/docs/resources/subnet.md b/docs/resources/subnet.md index b3426a82d..059f4b556 100644 --- a/docs/resources/subnet.md +++ b/docs/resources/subnet.md @@ -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 diff --git a/go.mod b/go.mod index 22a379295..7e4df329a 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 0222918ac..a2ccf48da 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/ncloud/data_source_ncloud_subnet.go b/ncloud/data_source_ncloud_subnet.go index ff1d64921..64e2a21a7 100644 --- a/ncloud/data_source_ncloud_subnet.go +++ b/ncloud/data_source_ncloud_subnet.go @@ -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(), } diff --git a/ncloud/data_source_ncloud_subnets.go b/ncloud/data_source_ncloud_subnets.go index 1248cc9c4..845188940 100644 --- a/ncloud/data_source_ncloud_subnets.go +++ b/ncloud/data_source_ncloud_subnets.go @@ -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": { diff --git a/ncloud/resource_ncloud_access_control_group_rule.go b/ncloud/resource_ncloud_access_control_group_rule.go index e50b05522..3c4c19423 100644 --- a/ncloud/resource_ncloud_access_control_group_rule.go +++ b/ncloud/resource_ncloud_access_control_group_rule.go @@ -4,7 +4,6 @@ import ( "fmt" "log" "regexp" - "strconv" "time" "github.com/NaverCloudPlatform/ncloud-sdk-go-v2/ncloud" @@ -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{}{ diff --git a/ncloud/resource_ncloud_nas_volume.go b/ncloud/resource_ncloud_nas_volume.go index 20ef7f6ab..9f13bc83f 100644 --- a/ncloud/resource_ncloud_nas_volume.go +++ b/ncloud/resource_ncloud_nas_volume.go @@ -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, @@ -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, @@ -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, } } @@ -278,6 +283,7 @@ func convertVpcNasVolume(inst *vnas.NasVolumeInstance) *NasVolume { ServerInstanceNoList: inst.NasVolumeServerInstanceNoList, NasVolumeInstanceCustomIpList: []*string{}, MountInformation: inst.MountInformation, + IsReturnProtection: inst.IsReturnProtection, } } @@ -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) @@ -347,6 +347,7 @@ 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)), @@ -354,10 +355,7 @@ func createVpcNasVolume(d *schema.ResourceData, config *ProviderConfig) (*string 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) @@ -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) @@ -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) @@ -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"` @@ -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"` } diff --git a/ncloud/resource_ncloud_nat_gateway.go b/ncloud/resource_ncloud_nat_gateway.go index 07444f0ca..1bc498199 100644 --- a/ncloud/resource_ncloud_nat_gateway.go +++ b/ncloud/resource_ncloud_nat_gateway.go @@ -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, + }, }, } } @@ -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 } diff --git a/ncloud/resource_ncloud_subnet.go b/ncloud/resource_ncloud_subnet.go index 42c3cffa6..13789c8ad 100644 --- a/ncloud/resource_ncloud_subnet.go +++ b/ncloud/resource_ncloud_subnet.go @@ -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,