Skip to content

Commit

Permalink
feat(nks): nks_versions_data_source hypervisor_code (#419)
Browse files Browse the repository at this point in the history
* update(nks):
- nks_versions_data_source : hypervisor_code

* update(nks):
- go.sum

* update(nks): kvm cluster_type

* update(nks): ncloud_nks_verions add hypervisor_code

---------

Co-authored-by: Mingyum Kim <mingyum.kim@navercorp.com>
  • Loading branch information
gimmetm and Mingyum Kim committed Apr 22, 2024
1 parent 335e47e commit a05185a
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 10 deletions.
3 changes: 1 addition & 2 deletions docs/data-sources/nks_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ In addition to all arguments above, the following attributes are exported:
* 10 ea : `SVR.VNKS.STAND.C002.M008.NET.SSD.B050.G002`
* 50 ea : `SVR.VNKS.STAND.C004.M016.NET.SSD.B050.G002`
* `KVM`
* 10 ea : `SVR.VNKS.STAND.C002.M008.G003`
* 50 ea : `SVR.VNKS.STAND.C004.M016.G003`
* 250 ea : `SVR.VNKS.STAND.C004.M016.G003`
* `login_key_name` - Login key name.
* `zone` - zone Code.
* `vpc_no` - VPC No.
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/nks_versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ data "ncloud_nks_versions" "v1_20" {

The following arguments are supported:

* `hypervisor_code` - (Optional) Hypervisor code. (Default `XEN`)
* `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 Down
3 changes: 1 addition & 2 deletions docs/resources/nks_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ The following arguments are supported:
* 10 ea : `SVR.VNKS.STAND.C002.M008.NET.SSD.B050.G002`
* 50 ea : `SVR.VNKS.STAND.C004.M016.NET.SSD.B050.G002`
* `KVM`
* 10 ea : `SVR.VNKS.STAND.C002.M008.G003`
* 50 ea : `SVR.VNKS.STAND.C004.M016.G003`
* 250 ea : `SVR.VNKS.STAND.C004.M016.G003`
* `login_key_name` - (Required) Login key name.
* `zone` - (Required) zone Code.
* `vpc_no` - (Required) VPC No.
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.6.10
github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.6.11
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/terraform-plugin-framework v1.3.2
github.com/hashicorp/terraform-plugin-go v0.17.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA=
github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.6.10 h1:DT3zE1158NECPmkyLxZQV73yN4J8vbB7H5hK5TkpFlI=
github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.6.10/go.mod h1:jRp8KZ64MUevBWNqehghhG2oF5/JU3Dmt/Cu7dp1mQE=
github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.6.11 h1:5+mB3hzj2gRJV12AvIW8eV8S9xdWey9F+YkuIFDLVV0=
github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.6.11/go.mod h1:jRp8KZ64MUevBWNqehghhG2oF5/JU3Dmt/Cu7dp1mQE=
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA=
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g=
github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ=
Expand Down
17 changes: 14 additions & 3 deletions internal/service/nks/nks_versions_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func DataSourceNcloudNKSVersions() *schema.Resource {

Schema: map[string]*schema.Schema{
"filter": DataSourceFiltersSchema(),
"hypervisor_code": {
Type: schema.TypeString,
Optional: true,
},
"versions": {
Type: schema.TypeList,
Computed: true,
Expand All @@ -45,7 +49,7 @@ func dataSourceNcloudVersionsRead(d *schema.ResourceData, meta interface{}) erro
return NotSupportClassic("datasource `ncloud_nks_versions`")
}

resources, err := getNKSVersion(config)
resources, err := getNKSVersion(config, d)
if err != nil {
return err
}
Expand All @@ -63,10 +67,17 @@ func dataSourceNcloudVersionsRead(d *schema.ResourceData, meta interface{}) erro

}

func getNKSVersion(config *conn.ProviderConfig) ([]map[string]interface{}, error) {
func getNKSVersion(config *conn.ProviderConfig, d *schema.ResourceData) ([]map[string]interface{}, error) {

LogCommonRequest("GetNKSVersion", "")
resp, err := config.Client.Vnks.V2Api.OptionVersionGet(context.Background(), map[string]interface{}{})
hypervisorCode := StringPtrOrNil(d.GetOk("hypervisor_code"))

opt := make(map[string]interface{})
if hypervisorCode != nil {
opt["hypervisorCode"] = hypervisorCode
}

resp, err := config.Client.Vnks.V2Api.OptionVersionGet(context.Background(), opt)

if err != nil {
LogErrorResponse("GetNKSVersion", err, "")
Expand Down
42 changes: 42 additions & 0 deletions internal/service/nks/nks_versions_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,48 @@ func TestAccDataSourceNcloudVersions(t *testing.T) {
})
}

func TestAccDataSourceNcloudVersions_XEN(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { TestAccPreCheck(t) },
ProtoV6ProviderFactories: ProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDataSourceNcloudVersionConfig_XEN,
Check: resource.ComposeTestCheckFunc(
TestAccCheckDataSourceID("data.ncloud_nks_versions.versions"),
),
},
},
})
}

func TestAccDataSourceNcloudVersions_KVM(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { TestAccPreCheck(t) },
ProtoV6ProviderFactories: ProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDataSourceNcloudVersionConfig_KVM,
Check: resource.ComposeTestCheckFunc(
TestAccCheckDataSourceID("data.ncloud_nks_versions.versions"),
),
},
},
})
}

var testAccDataSourceNcloudVersionConfig = `
data "ncloud_nks_versions" "versions" {}
`

var testAccDataSourceNcloudVersionConfig_XEN = `
data "ncloud_nks_versions" "versions" {
hypervisor_code = "XEN"
}
`

var testAccDataSourceNcloudVersionConfig_KVM = `
data "ncloud_nks_versions" "versions" {
hypervisor_code = "KVM"
}
`

0 comments on commit a05185a

Please sign in to comment.