Skip to content

Commit

Permalink
feat(mysql, mongodb, redis, hadoop): add engine version code (#474)
Browse files Browse the repository at this point in the history
* feat(mysql): add engine version code

* feat(mongodb): add engine version code

* feat(redis): add engine version code

* feat(hadoop): add engine version code

* docs: add engine version code

* docs: move engine_version attributest to argument

* fix: refresh engineVersionCode by engineVersion

* docs: update example image product code

* docs: update datasource image product code

* refactor: use WriteImageProductToFile for json convert

* chore: remove unused json convert model

* fix: extract all kind of version

* fix: change hadoop engine version planmodifiers

* docs: fix engine version code description

* fix: revert mssql image product jsoncovert

* docs: remove unused attribute
  • Loading branch information
dusdjhyeon authored Nov 6, 2024
1 parent 2de2445 commit df53730
Show file tree
Hide file tree
Showing 24 changed files with 182 additions and 185 deletions.
1 change: 1 addition & 0 deletions docs/data-sources/hadoop_image_products.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ This data source exports the following attributes in addition to the arguments a
* `product_type` - Product type code.
* `platform_type` - Platform type code.
* `os_information` - OS Information.
* `engine_version_code` - Engine version code.
19 changes: 12 additions & 7 deletions docs/data-sources/mongodb_image_products.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ data "ncloud_mongodb_image_products" "example" {
output "image_list" {
value = {
for image in data.ncloud_mongodb_image_products.example.image_product_list:
image.product_name => image.product_code
image.engine_version_code => image.product_code
}
}
```
Expand All @@ -36,12 +36,16 @@ data "ncloud_mongodb_image_products" "example" {
Outputs:
```terraform
image_list = {
"MongoDB 4.4.18 Community Edition": "SW.VMGDB.LNX64.CNTOS.0708.MNGDB.4418.CE.B050",
"MongoDB 4.4.18 Enterprise Edition": "SW.VMGDB.LNX64.CNTOS.0708.MNGDB.4418.EE.B050",
"MongoDB 4.4.25 Community Edition": "SW.VMGDB.LNX64.CNTOS.0708.MNGDB.4425.CE.B050",
"MongoDB 4.4.25 Enterprise Edition": "SW.VMGDB.LNX64.CNTOS.0708.MNGDB.4425.EE.B050",
"MongoDB 5.0.19 Community Edition": "SW.VMGDB.LNX64.CNTOS.0708.MNGDB.5019.CE.B050",
"MongoDB 5.0.19 Enterprise Edition": "SW.VMGDB.LNX64.CNTOS.0708.MNGDB.5019.EE.B050"
"6.0.15": "SW.VMGDB.OS.LNX64.ROCKY.0810.MNGDB.CE.B050",
"6.0.15": "SW.VMGDB.OS.LNX64.ROCKY.0810.MNGDB.EE.B050",
"5.0.25": "SW.VMGDB.OS.LNX64.ROCKY.0810.MNGDB.CE.B050",
"5.0.25": "SW.VMGDB.OS.LNX64.ROCKY.0810.MNGDB.EE.B050",
"5.0.19": "SW.VMGDB.OS.LNX64.ROCKY.0810.MNGDB.CE.B050",
"5.0.19": "SW.VMGDB.OS.LNX64.ROCKY.0810.MNGDB.EE.B050",
"4.4.25": "SW.VMGDB.OS.LNX64.ROCKY.0810.MNGDB.CE.B050",
"4.4.25": "SW.VMGDB.OS.LNX64.ROCKY.0810.MNGDB.EE.B050",
"4.4.18": "SW.VMGDB.OS.LNX64.ROCKY.0810.MNGDB.CE.B050",
"4.4.18": "SW.VMGDB.OS.LNX64.ROCKY.0810.MNGDB.EE.B050"
}
```

Expand All @@ -66,3 +70,4 @@ This data source exports the following attributes in addition to the arguments a
* `product_type` - Product type code.
* `platform_type` - Platform type code.
* `os_information` - OS Information.
* `engine_version_code` - Engine version code.
4 changes: 2 additions & 2 deletions docs/data-sources/mongodb_products.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Provides the list of available Cloud DB for MongoDB server specification codes.

```terraform
data "ncloud_mongodb_products" "all" {
image_product_code = "SW.VMGDB.LNX64.CNTOS.0708.MNGDB.4223.CE.B050"
image_product_code = "SW.VMGDB.OS.LNX64.ROCKY.0810.MNGDB.CE.B050"
filter {
name = "product_type"
Expand All @@ -36,7 +36,7 @@ Outputs:
product_list = {
"vCPU 2EA, Memory 8GB": "SVR.VMGDB.MNGOD.STAND.C002.M008.NET.SSD.B050.G002",
"vCPU 2EA, Memory 8GB": "SVR.VMGDB.CFGSV.STAND.C002.M008.NET.SSD.B050.G002",
"vCPU 2EA, Memory 8GB": "SVR.VMGDB.MNGOS.STAND.C002.M008.NET.SSD.B050.G002",
"vCPU 2EA, Memory 8GB": "SVR.VMGDB.MNGOS.STAND.C002.M008.NET.SSD.B050.G002"
}
```

Expand Down
9 changes: 5 additions & 4 deletions docs/data-sources/mysql_image_products.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ data "ncloud_mysql_image_products" "example" {
output "image_list" {
value = {
for image in data.ncloud_mysql_image_products.example.image_product_list:
image.product_name => image.product_code
image.engine_version_code => image.product_code
}
}
```

```terraform
data "ncloud_mysql_image_products" "example" {
filter {
name = "product_code"
values = ["SW.VDBAS.DBAAS.LNX64.CNTOS.0708.MYSQL.8021.B050"]
name = "engine_version_code"
values = ["8.0.36"]
}
}
```

Outputs:
```terraform
image_list = {
"mysql(8.0.21)": "SW.VDBAS.DBAAS.LNX64.CNTOS.0708.MYSQL.8021.B050",
"8.0.36": "SW.VMYSL.OS.LNX64.ROCKY.0810.MYSQL.B050"
}
```

Expand All @@ -61,3 +61,4 @@ This data source exports the following attributes in addition to the arguments a
* `product_type` - Product type code.
* `platform_type` - Platform type code.
* `os_information` - OS Information.
* `engine_version_code` - Engine version code.
8 changes: 6 additions & 2 deletions docs/data-sources/mysql_products.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Get a list of MySQL products.

```terraform
data "ncloud_mysql_products" "all" {
image_product_code = "SW.VDBAS.DBAAS.LNX64.CNTOS.0708.MYSQL.8025.B050"
image_product_code = "SW.VMYSL.OS.LNX64.ROCKY.0810.MYSQL.B050"
filter {
name = "product_type"
Expand All @@ -34,7 +34,11 @@ output "product_list" {
Outputs:
```terraform
list_image = {
"vCPU 2EA, Memory 8GB" = "SVR.VDBAS.STAND.C002.M008.NET.HDD.B050.G002"
"vCPU 2EA, Memory 8GB" = "SVR.VDBAS.STAND.C002.M008.NET.HDD.B050.G002",
"vCPU 4EA, Memory 16GB" = "SVR.VDBAS.STAND.C004.M016.NET.HDD.B050.G002",
"vCPU 8EA, Memory 32GB" = "SVR.VDBAS.STAND.C008.M032.NET.HDD.B050.G002",
"vCPU 16EA, Memory 64GB" = "SVR.VDBAS.STAND.C016.M064.NET.HDD.B050.G002",
"vCPU 32EA, Memory 128GB" = "SVR.VDBAS.STAND.C032.M128.NET.HDD.B050.G002"
}
```

Expand Down
8 changes: 5 additions & 3 deletions docs/data-sources/redis_image_products.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ data "ncloud_redis_image_products" "example" {
output "image_list" {
value = {
for image in data.ncloud_redis_image_products.example.image_product_list:
image.product_name => image.product_code
image.engine_version_code => image.product_code
}
}
```
Expand All @@ -36,8 +36,9 @@ data "ncloud_redis_image_products" "example" {
Outputs:
```terraform
image_list = {
"Redis(5.0.14)": "SW.VDBAS.VRDS.LNX64.CNTOS.0708.REDIS.5014.B050",
"Redis(7.0.13)": "SW.VDBAS.VRDS.LNX64.CNTOS.0708.REDIS.7013.B050"
"7.0.15": "SW.VRDS.OS.LNX64.ROCKY.0810.REDIS.B050",
"7.0.13": "SW.VRDS.OS.LNX64.ROCKY.0810.REDIS.B050",
"5.0.14": "SW.VRDS.OS.LNX64.ROCKY.0810.REDIS.B050"
}
```

Expand All @@ -62,3 +63,4 @@ This data source exports the following attributes in addition to the arguments a
* `product_type` - Product type code.
* `platform_type` - Platform type code.
* `os_information` - OS Information.
* `engine_version_code` - Engine version code.
2 changes: 1 addition & 1 deletion docs/data-sources/redis_products.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Get a list of Redis products.

```terraform
data "ncloud_redis_products" "all" {
redis_image_product_code = "SW.VDBAS.VRDS.LNX64.CNTOS.0708.REDIS.7013.B050"
redis_image_product_code = "SW.VRDS.OS.LNX64.ROCKY.0810.REDIS.B050"
filter {
name = "product_type"
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/hadoop.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ The following arguments are supported:
* `master_node_data_storage_size` - (Required) Data Storage size of master node. Must be between 100(GBi) and 2000(GBi) in 10(GBi) increaments. 4000(GBi) and 6000(GBi) also available.
* `worker_node_data_storage_size` - (Required) Data Storage size of worker node. Must be between 100(GBi) and 2000(GBi) in 10(GBi) increaments. 4000(GBi) and 6000(GBi) also available.
* `image_product_code` - (Optional) Image product code to determine the Hadoop instance server image specification to create. If not entered, the instance is created for default value. Default: Cloud Hadoop's latest version. It can be obtained through [`ncloud_hadoop_image_products` data source](../data-sources/hadoop_image_products.md)
* `engine_version_code` - (Optional) Hadoop Engine version code. Only entered when creating with a Rocky cluster, If not entered, generate with the latest version currently available.
* `edge_node_product_code` - (Optional, Changeable) Edge node product code to determine the edge node server specification to create. The specification upgrade will be performed after a full service stop, so please stop work in advance. Upgrading to a server with more memory than the current specification is only possible and incurs an additional fee. Default: Selected as minimum specification. The minimum standards are 1. memory 2. CPU. It can be obtained through [`ncloud_hadoop_products` data source](../data-source/hadoop_products.md).
* `master_node_product_code` - (Optional, Changeable) Master node product code to determine the master node server specification to create. The specification upgrade will be performed after a full service stop, so please stop work in advance. Upgrading to a server with more memory than the current specification is only possible and incurs an additional fee. Default: Selected as minimum specification. The minimum standards are 1. memory 2. CPU. It can be obtained through [`ncloud_hadoop_products` data source](../data-sources/hadoop_products.md).
* `worker_node_product_code` - (Optional, Changeable) Worker node product code to determine the worker node server specification to create. The specification upgrade will be performed after a full service stop, so please stop work in advance. Upgrading to a server with more memory than the current specification is only possible and incurs an additional fee. Default: Selected as minimum specification. The minimum standards are 1. memory 2. CPU. It can be obtained through [`ncloud_hadoop_products` data source](../data-sources/hadoop_products.md).
Expand All @@ -106,7 +107,6 @@ In addition to all arguments above, the following attributes are exported
* `region_code` - Region code.
* `ambari_server_host` - Ambari server host.
* `cluster_direct_access_account` - Account to access the cluster directly.
* `version` - The version of Hadoop.
* `is_ha` - Whether using high availability of the specific Hadoop.
* `domain` - Domain.
* `access_control_group_no_list` - Access control group number list.
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/mongodb.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ The following arguments are supported:
* `subnet_no` - (Required) The ID of the associated Subnet.
* `cluster_type_code` - (Required) MongoDB cluster type code determines the cluster type of MongoDB. Options: STAND_ALONE | SINGLE_REPLICA_SET | SHARDED_CLUSTER
* `image_product_code` - (Optional) MongoDB image product code. If not entered, it is created as a default value. It can be obtained through [`data.ncloud_mongodb_image_products`](../data-sources/mongodb_image_products.md).
* `engine_version_code` - (Optional) MongoDB engine version code. If not entered, generate with the default version currently available.
* `member_product_code` - (Optional) Member server product code. It can be obtained through [`data.ncloud_mongodb_products`](../data-sources/mongodb_products.md). Default: select the minimum specifications and must be based on 1. Memory and 2. CPU
* `arbiter_product_code` - (Optional) Arbiter server product code. It can be obtained through [`data.ncloud_mongodb_products`](../data-sources/mongodb_products.md). Default: select the minimum specifications and must be based on 1. Memory and 2. CPU
* `mongos_product_code` - (Optional) Mongos server product code. It can be obtained through [`data.ncloud_mongodb_products`](../data-sources/mongodb_products.md). Default: select the minimum specifications and must be based on 1. Memory and 2. CPU
Expand All @@ -74,7 +75,6 @@ In addition to all arguments above, the following attributes are exported:

* `id` - MondoDb instance number.
* `arbiter_port` - TCP port number for access to the MongoDB Arbiter Server.
* `engine_version` - Engine Version.
* `region_code` - Region code.
* `zone_code` - Zone code.
* `access_control_group_no_list` - The ID list of the associated Access Control Group.
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/mysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ The following arguments are supported:
* `subnet_no` - (Required) The ID of the associated Subnet. Public domain can only be used on a DB server generated on Public Subnet.
* `image_product_code` - (Optional) Image product code to determine the MySQL instance server image specification to create. If not entered, the instance is created for default value. It can be obtained through [`ncloud_mysql_image_products` data source](../data-sources/mysql_image_products.md)
* `product_code` - (Optional) Product code to determine the MySQL instance server image specification to create. It can be obtained through [`ncloud_mysql_products` data source](../data-sources/mysql_products.md). Default : Minimum specifications(1 memory, 2 cpu)
* `engine_version_code` - (Optional) MySQL engine version code. If not entered, generate with the default version currently available.
* `data_storage_type` - (Optional) Data storage type. If `generationCode` is `G2`, You can select `SSD|HDD`, else if `generationCode` is `G3`, you can select CB1. Default : SSD in G2, CB1 in G3
* `is_ha` - (Optional) High-availability (True/False). If high availability is selected, 2 servers including a Standby Master server are generated, and additional fees are incurred. If the high availability status `is_ha` is false, `is_multi_zone` and `standby_master_subnet_no` parameters are not used. Default : true.
* `is_multi_zone` - (Optional) Multi-zone (True/False). If the high availability status `is_ha` is true, multi-zone can be selected. If multi-zone is selected, the Master server and Standby Master server are generated in mutually different zones, providing higher availability. Default : false
Expand All @@ -65,7 +66,6 @@ The following arguments are supported:
In addition to all arguments above, the following attributes are exported

* `id` - MySQL Instance Number.
* `engine_version_code` - MySQL Engine version code.
* `region_code` - Region code.
* `vpc_no` - The ID of the associated Vpc.
* `access_control_group_no_list` - The ID list of the associated Access Control Group.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/redis.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ The following arguments are supported:
* `mode` - (Required) Determines the configuration of Cloud DB for Redis. When the CLUSTER setting is used, the `is_ha` setting is ignored. Options: `CLUSTER`, `SIMPLE`.
* `image_product_code` - (Optional) Image product code to determine the Redis instance server image specification to create. If not entered, the instance is created for default value. It can be obtained through [`data.ncloud_redis_image_products`](../data-sources/redis_image_products.md).
* `product_code` - (Optional) Sets the server specifications of the Cloud DB for Redis instance to be created. It can be obtained through [`data.ncloud_redis_products`](../data-sources/redis_products.md). Default : Minimum specifications(1 memory, 2 cpu)
* `engine_version_code` - (Optional) Redis engine version code. If not entered, generate with the default version currently available.
* `shard_count` - (Optional) Number of shards to be created. 3 to 10 Number of master nodes. Necessary only if the `mode` is CLUSTER. Default: 3
* `shard_copy_count` - (Optional) Replicas per shard Redis Cluster consists of the master node and slave node. A slave node is necessary for HA. When adding a replica, one slave node is assigned to each master node. For example, 3 shards, 1 replica per shard -> Master node: 3, Slave node: 3. You can enter 0 to 4 replica(s) for each shard. If the number of replicas per shard is set to 0, then high availability can't be supported. Necessary only if the `mode` is CLUSTER. Default: 0
* `is_ha` - (Optional) Whether is High Availability or not. The Cloud DB for Redis product supports automatic failure recovery using the Standby master. When high availability is supported, additional charges are incurred and backup is automatically configured. Default: false
Expand Down
2 changes: 1 addition & 1 deletion examples/mysql_products/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ provider "ncloud" {
}

data "ncloud_mysql_products" "all" {
image_product_code = "SW.VDBAS.DBAAS.LNX64.CNTOS.0708.MYSQL.8025.B050"
image_product_code = "SW.VMYSL.OS.LNX64.ROCKY.0810.MYSQL.B050"
output_file = "mysql_products.json"
}

2 changes: 1 addition & 1 deletion examples/redis/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ output "image_list" {
}

data "ncloud_redis_products" "all" {
redis_image_product_code = "SW.VDBAS.VRDS.LNX64.CNTOS.0708.REDIS.7013.B050"
redis_image_product_code = "SW.VRDS.OS.LNX64.ROCKY.0810.REDIS.B050"
output_file = "products.json"
}

Expand Down
8 changes: 8 additions & 0 deletions internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"log"
"regexp"

"strings"

Expand Down Expand Up @@ -95,3 +96,10 @@ func ContainsInStringList(str string, s []string) bool {
}
return false
}

func ExtractEngineVersion(input string) string {
re := regexp.MustCompile(`\d+\.\d+(\.\d+)?`)
version := re.FindString(input)

return version
}
13 changes: 7 additions & 6 deletions internal/common/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ func WriteImageProductToFile(path string, images types.List) error {
}

type imageProductToJson struct {
ProductCode string `json:"product_code"`
GenerationCode string `json:"generation_code"`
ProductName string `json:"product_name"`
ProductType string `json:"product_type"`
PlatformType string `json:"platform_type"`
OsInformation string `json:"os_information"`
ProductCode string `json:"product_code"`
GenerationCode string `json:"generation_code"`
ProductName string `json:"product_name"`
ProductType string `json:"product_type"`
PlatformType string `json:"platform_type"`
OsInformation string `json:"os_information"`
EngineVersionCode string `json:"engine_version_code"`
}
21 changes: 13 additions & 8 deletions internal/service/hadoop/hadoop.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ func (r *hadoopResource) Schema(_ context.Context, req resource.SchemaRequest, r
},
Description: "default: latest version",
},
"engine_version_code": schema.StringAttribute{
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
},
"edge_node_product_code": schema.StringAttribute{
Optional: true,
Computed: true,
Expand Down Expand Up @@ -335,12 +342,6 @@ func (r *hadoopResource) Schema(_ context.Context, req resource.SchemaRequest, r
stringplanmodifier.UseStateForUnknown(),
},
},
"version": schema.StringAttribute{
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"is_ha": schema.BoolAttribute{
Computed: true,
PlanModifiers: []planmodifier.Bool{
Expand Down Expand Up @@ -469,6 +470,10 @@ func (r *hadoopResource) Create(ctx context.Context, req resource.CreateRequest,
reqParams.CloudHadoopImageProductCode = plan.ImageProductCode.ValueStringPointer()
}

if !plan.EngineVersionCode.IsNull() {
reqParams.EngineVersionCode = plan.EngineVersionCode.ValueStringPointer()
}

if !plan.MasterNodeProductCode.IsNull() && !plan.MasterNodeProductCode.IsUnknown() {
reqParams.MasterNodeProductCode = plan.MasterNodeProductCode.ValueStringPointer()
}
Expand Down Expand Up @@ -862,6 +867,7 @@ type hadoopResourceModel struct {
MasterNodeDataStorageSize types.Int64 `tfsdk:"master_node_data_storage_size"`
WorkerNodeDataStorageSize types.Int64 `tfsdk:"worker_node_data_storage_size"`
ImageProductCode types.String `tfsdk:"image_product_code"`
EngineVersionCode types.String `tfsdk:"engine_version_code"`
EdgeNodeProductCode types.String `tfsdk:"edge_node_product_code"`
MasterNodeProductCode types.String `tfsdk:"master_node_product_code"`
WorkerNodeProductCode types.String `tfsdk:"worker_node_product_code"`
Expand All @@ -876,7 +882,6 @@ type hadoopResourceModel struct {
RegionCode types.String `tfsdk:"region_code"`
AmbariServerHost types.String `tfsdk:"ambari_server_host"`
ClusterDirectAccessAccount types.String `tfsdk:"cluster_direct_access_account"`
Version types.String `tfsdk:"version"`
IsHa types.Bool `tfsdk:"is_ha"`
Domain types.String `tfsdk:"domain"`
AccessControlGroupNoList types.List `tfsdk:"access_control_group_no_list"`
Expand Down Expand Up @@ -929,7 +934,7 @@ func (m *hadoopResourceModel) refreshFromOutput(ctx context.Context, output *vha
m.RegionCode = types.StringPointerValue(output.CloudHadoopServerInstanceList[0].RegionCode)
m.AmbariServerHost = types.StringPointerValue(output.AmbariServerHost)
m.ClusterDirectAccessAccount = types.StringPointerValue(output.ClusterDirectAccessAccount)
m.Version = types.StringPointerValue(output.CloudHadoopVersion.Code)
m.EngineVersionCode = types.StringPointerValue(output.CloudHadoopVersion.Code)
m.IsHa = types.BoolPointerValue(output.IsHa)
m.Domain = types.StringPointerValue(output.Domain)

Expand Down
Loading

0 comments on commit df53730

Please sign in to comment.