Skip to content

Commit

Permalink
Merge pull request #18 from volcengine/for_rds_v1
Browse files Browse the repository at this point in the history
For rds v1
  • Loading branch information
xuyaming0800 authored Aug 15, 2022
2 parents cfe925d + d1c27e7 commit 5f0c740
Show file tree
Hide file tree
Showing 64 changed files with 5,257 additions and 82 deletions.
2 changes: 1 addition & 1 deletion common/common_volcengine_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package common

const (
TerraformProviderName = "terraform-provider-volcengine"
TerraformProviderVersion = "0.0.15"
TerraformProviderVersion = "0.0.16"
)
2 changes: 2 additions & 0 deletions docgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ var resourceKeys = map[string]string{
"vke": "VKE",
"iam": "IAM",
"escloud": "ESCLOUD",
"rds": "RDS_MYSQL",
"rds_v2": "RDS_MYSQL",
}

type Products struct {
Expand Down
3 changes: 3 additions & 0 deletions example/dataRdsAccounts/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "volcengine_rds_accounts" "default" {
instance_id = "mysql-0fdd3bab2e7c"
}
3 changes: 3 additions & 0 deletions example/dataRdsDatabases/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "volcengine_rds_databases" "default" {
instance_id = "mysql-0fdd3bab2e7c"
}
3 changes: 3 additions & 0 deletions example/dataRdsInstances/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "volcengine_rds_instances" "default" {
instance_id = "mysql-0fdd3bab2e7c"
}
3 changes: 3 additions & 0 deletions example/dataRdsInstancesV2/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "volcengine_rds_instances_v2" "default" {

}
3 changes: 3 additions & 0 deletions example/dataRdsIpLists/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "volcengine_rds_ip_lists" "default" {
instance_id = "mysql-0fdd3bab2e7c"
}
3 changes: 3 additions & 0 deletions example/dataRdsParameterTemplates/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "volcengine_rds_parameter_templates" "default" {

}
6 changes: 6 additions & 0 deletions example/rdsAccount/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "volcengine_rds_account" "foo" {
instance_id = "mysql-0fdd3bab2e7c"
account_name = "test"
account_password = "Aatest123"
account_type = "Normal"
}
27 changes: 27 additions & 0 deletions example/rdsAccountPrivilege/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
resource "volcengine_rds_account" "app_name" {
instance_id = "mysql-0fdd3bab2e7c"
account_name = "terraform-test-app"
account_password = "Aatest123"
account_type = "Normal"
}

resource "volcengine_rds_account_privilege" "foo" {
instance_id = "mysql-0fdd3bab2e7c"
account_name = volcengine_rds_account.app_name.account_name

db_privileges {
db_name = "foo"
account_privilege = "Custom"
account_privilege_str = "ALTER,ALTER ROUTINE,CREATE,CREATE ROUTINE,CREATE TEMPORARY TABLES"
}

db_privileges {
db_name = "bar"
account_privilege = "DDLOnly"
}

db_privileges {
db_name = "demo"
account_privilege = "ReadWrite"
}
}
5 changes: 5 additions & 0 deletions example/rdsDatabase/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "volcengine_rds_database" "foo" {
instance_id = "mysql-0fdd3bab2e7c"
db_name = "foo"
character_set_name = "utf8mb4"
}
14 changes: 14 additions & 0 deletions example/rdsInstance/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
resource "volcengine_rds_instance" "foo" {
region = "cn-north-4"
zone = "cn-langfang-b"
instance_name = "tf-test"
db_engine = "MySQL"
db_engine_version = "MySQL_Community_5_7"
vpc_id = "vpc-3cj17x7u9bzeo6c6rrtzfpaeb"
instance_type = "HA"
charge_type = "PostPaid"
storage_type = "LocalSSD"
storage_space_gb = 100
instance_spec_name = "rds.mysql.1c2g"
subnet_id = "subnet-1g0d4fkh1nabk8ibuxx1jtvss"
}
28 changes: 28 additions & 0 deletions example/rdsInstanceV2/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
resource "volcengine_rds_instance_v2" "foo" {
db_engine_version = "MySQL_5_7"
instance_type = "HA"
node_info {
node_type = "Primary"
node_spec = "rds.mysql.2c4g"
zone_id = "cn-guilin-a"
}
node_info {
node_type = "Secondary"
node_spec = "rds.mysql.2c4g"
zone_id = "cn-guilin-a"
}
node_info {
node_type = "ReadOnly"
node_spec = "rds.mysql.1c2g"
zone_id = "cn-guilin-a"
}
storage_type = "LocalSSD"
storage_space = 100
vpc_id = "vpc-2d6ym9l9mqlfk58ozfd64sej3"
subnet_id = "subnet-2d6yma8y0394w58ozfemu5vmi"
instance_name = "tf-test-v2"
lower_case_table_names = "1"
charge_info {
charge_type = "PostPaid"
}
}
5 changes: 5 additions & 0 deletions example/rdsIpList/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "volcengine_rds_ip_list" "foo" {
instance_id = "mysql-0fdd3bab2e7c"
group_name = "foo"
ip_list = ["1.1.1.1", "2.2.2.2"]
}
18 changes: 18 additions & 0 deletions example/rdsParameterTemplate/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
resource "volcengine_rds_parameter_template" "foo" {
template_desc = "created by terraform"
template_name = "tf-template"
template_type = "MySQL"
template_type_version = "MySQL_Community_5_7"
template_params {
name = "auto_increment_increment"
running_value = "2"
}
template_params {
name = "slow_query_log"
running_value = "ON"
}
template_params {
name = "net_retry_count"
running_value = "33"
}
}
2 changes: 1 addition & 1 deletion example/vkeCluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ resource "volcengine_vke_cluster" "foo" {
}
}
services_config {
service_cidrsv4 = ["172.30.0.0/17"]
service_cidrsv4 = ["192.168.0.0/16"]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
Import
ECS Instance can be imported using the id, e.g.
If Import,The data_volumes is sort by volume name
```
$ terraform import volcengine_ecs_instance.default i-mizl7m1kqccg5smt1bdpijuj
```
Expand Down Expand Up @@ -191,7 +192,7 @@ func ResourceVolcengineEcsInstance() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The type of system volume.",
Description: "The type of system volume, the value is `PTSSD` or `ESSD_PL0` or `ESSD_PL1` or `ESSD_PL2` or `ESSD_FlexPL`.",
},

"system_volume_size": {
Expand All @@ -217,14 +218,14 @@ func ResourceVolcengineEcsInstance() *schema.Resource {
Optional: true,
MaxItems: 15,
MinItems: 1,
Description: "The data volume collection of ECS instance.",
Description: "The data volumes collection of ECS instance.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"volume_type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The type of volume.",
Description: "The type of volume, the value is `PTSSD` or `ESSD_PL0` or `ESSD_PL1` or `ESSD_PL2` or `ESSD_FlexPL`.",
},
"size": {
Type: schema.TypeInt,
Expand Down
25 changes: 23 additions & 2 deletions volcengine/ecs/ecs_instance/service_volcengine_ecs_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"reflect"
"sort"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -308,7 +309,7 @@ func (s *VolcengineEcsService) WithResourceResponseHandlers(ecs map[string]inter
}
}

//split System volume and Data volume
//split System volume and Data volumes
if volumes, ok1 := ecs["Volumes"].([]interface{}); ok1 {
var dataVolumes []interface{}
for _, volume := range volumes {
Expand All @@ -323,7 +324,11 @@ func (s *VolcengineEcsService) WithResourceResponseHandlers(ecs map[string]inter
}
}
if len(dataVolumes) > 0 {
ecs["DataVolumes"] = dataVolumes
v1 := volumeInfo{
list: dataVolumes,
}
sort.Sort(&v1)
ecs["DataVolumes"] = v1.list
}
}
return ecs, s.CommonResponseConvert(), nil
Expand Down Expand Up @@ -1191,3 +1196,19 @@ func getUniversalInfo(actionName string) ve.UniversalInfo {
Action: actionName,
}
}

type volumeInfo struct {
list []interface{}
}

func (v *volumeInfo) Len() int {
return len(v.list)
}

func (v *volumeInfo) Less(i, j int) bool {
return v.list[i].(map[string]interface{})["VolumeName"].(string) < v.list[j].(map[string]interface{})["VolumeName"].(string)
}

func (v *volumeInfo) Swap(i, j int) {
v.list[i], v.list[j] = v.list[j], v.list[i]
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func ResourceVolcengineEipAssociate() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The type of the associated instance.",
Description: "The type of the associated instance,the value is `NAT` or `NetworkInterface` or `ClbInstance` or `EcsInstance` or `HaVip`.",
},
"private_ip_address": {
Type: schema.TypeString,
Expand Down
39 changes: 33 additions & 6 deletions volcengine/provider.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package volcengine

import (
"github.com/volcengine/terraform-provider-volcengine/volcengine/rds/rds_parameter_template"
"strings"

"github.com/volcengine/terraform-provider-volcengine/volcengine/ecs/ecs_deployment_set"
"github.com/volcengine/terraform-provider-volcengine/volcengine/ecs/ecs_deployment_set_associate"
"github.com/volcengine/terraform-provider-volcengine/volcengine/escloud/instance"
"github.com/volcengine/terraform-provider-volcengine/volcengine/escloud/region"
"github.com/volcengine/terraform-provider-volcengine/volcengine/vke/node_pool"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
ve "github.com/volcengine/terraform-provider-volcengine/common"
Expand All @@ -22,12 +17,16 @@ import (
"github.com/volcengine/terraform-provider-volcengine/volcengine/clb/server_group_server"
"github.com/volcengine/terraform-provider-volcengine/volcengine/ebs/volume"
"github.com/volcengine/terraform-provider-volcengine/volcengine/ebs/volume_attach"
"github.com/volcengine/terraform-provider-volcengine/volcengine/ecs/ecs_deployment_set"
"github.com/volcengine/terraform-provider-volcengine/volcengine/ecs/ecs_deployment_set_associate"
"github.com/volcengine/terraform-provider-volcengine/volcengine/ecs/ecs_instance"
"github.com/volcengine/terraform-provider-volcengine/volcengine/ecs/ecs_instance_state"
"github.com/volcengine/terraform-provider-volcengine/volcengine/ecs/image"
"github.com/volcengine/terraform-provider-volcengine/volcengine/ecs/zone"
"github.com/volcengine/terraform-provider-volcengine/volcengine/eip/eip_address"
"github.com/volcengine/terraform-provider-volcengine/volcengine/eip/eip_associate"
"github.com/volcengine/terraform-provider-volcengine/volcengine/escloud/instance"
"github.com/volcengine/terraform-provider-volcengine/volcengine/escloud/region"
esZone "github.com/volcengine/terraform-provider-volcengine/volcengine/escloud/zone"
"github.com/volcengine/terraform-provider-volcengine/volcengine/iam/iam_access_key"
"github.com/volcengine/terraform-provider-volcengine/volcengine/iam/iam_login_profile"
Expand All @@ -38,8 +37,15 @@ import (
"github.com/volcengine/terraform-provider-volcengine/volcengine/iam/iam_user_policy_attachment"
"github.com/volcengine/terraform-provider-volcengine/volcengine/nat/nat_gateway"
"github.com/volcengine/terraform-provider-volcengine/volcengine/nat/snat_entry"
"github.com/volcengine/terraform-provider-volcengine/volcengine/rds/rds_account"
"github.com/volcengine/terraform-provider-volcengine/volcengine/rds/rds_account_privilege"
"github.com/volcengine/terraform-provider-volcengine/volcengine/rds/rds_database"
"github.com/volcengine/terraform-provider-volcengine/volcengine/rds/rds_instance"
"github.com/volcengine/terraform-provider-volcengine/volcengine/rds/rds_ip_list"
"github.com/volcengine/terraform-provider-volcengine/volcengine/rds_v2/rds_instance_v2"
"github.com/volcengine/terraform-provider-volcengine/volcengine/vke/cluster"
"github.com/volcengine/terraform-provider-volcengine/volcengine/vke/node"
"github.com/volcengine/terraform-provider-volcengine/volcengine/vke/node_pool"
"github.com/volcengine/terraform-provider-volcengine/volcengine/vpc/network_interface"
"github.com/volcengine/terraform-provider-volcengine/volcengine/vpc/network_interface_attach"
"github.com/volcengine/terraform-provider-volcengine/volcengine/vpc/route_entry"
Expand Down Expand Up @@ -146,6 +152,16 @@ func Provider() terraform.ResourceProvider {
"volcengine_iam_roles": iam_role.DataSourceVolcengineIamRoles(),
"volcengine_iam_users": iam_user.DataSourceVolcengineIamUsers(),

// ================ RDS V1 ==============
"volcengine_rds_instances": rds_instance.DataSourceVolcengineRdsInstances(),
"volcengine_rds_databases": rds_database.DataSourceVolcengineRdsDatabases(),
"volcengine_rds_accounts": rds_account.DataSourceVolcengineRdsAccounts(),
"volcengine_rds_ip_lists": rds_ip_list.DataSourceVolcengineRdsIpLists(),
"volcengine_rds_parameter_templates": rds_parameter_template.DataSourceVolcengineRdsParameterTemplates(),

// ================ RDS V2 ==============
"volcengine_rds_instances_v2": rds_instance_v2.DataSourceVolcengineRdsInstances(),

// ================ ESCloud =============
"volcengine_escloud_instances": instance.DataSourceVolcengineESCloudInstances(),
"volcengine_escloud_regions": region.DataSourceVolcengineESCloudRegions(),
Expand Down Expand Up @@ -204,6 +220,17 @@ func Provider() terraform.ResourceProvider {
"volcengine_iam_login_profile": iam_login_profile.ResourceVolcengineIamLoginProfile(),
"volcengine_iam_user_policy_attachment": iam_user_policy_attachment.ResourceVolcengineIamUserPolicyAttachment(),

// ================ RDS V1 ==============
"volcengine_rds_instance": rds_instance.ResourceVolcengineRdsInstance(),
"volcengine_rds_database": rds_database.ResourceVolcengineRdsDatabase(),
"volcengine_rds_account": rds_account.ResourceVolcengineRdsAccount(),
"volcengine_rds_ip_list": rds_ip_list.ResourceVolcengineRdsIpList(),
"volcengine_rds_account_privilege": rds_account_privilege.ResourceVolcengineRdsAccountPrivilege(),
"volcengine_rds_parameter_template": rds_parameter_template.ResourceVolcengineRdsParameterTemplate(),

// ================ RDS V2 ==============
"volcengine_rds_instance_v2": rds_instance_v2.ResourceVolcengineRdsInstance(),

// ================ ESCloud ================
"volcengine_escloud_instance": instance.ResourceVolcengineESCloudInstance(),
},
Expand Down
22 changes: 22 additions & 0 deletions volcengine/rds/rds_account/common_volcengine_rds_account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package rds_account

import (
"fmt"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

var rdsAccountImporter = func(data *schema.ResourceData, i interface{}) ([]*schema.ResourceData, error) {
items := strings.Split(data.Id(), ":")
if len(items) != 2 {
return []*schema.ResourceData{data}, fmt.Errorf("import id must split with ':'")
}
if err := data.Set("instance_id", items[0]); err != nil {
return []*schema.ResourceData{data}, err
}
if err := data.Set("account_name", items[1]); err != nil {
return []*schema.ResourceData{data}, err
}
return []*schema.ResourceData{data}, nil
}
Loading

0 comments on commit 5f0c740

Please sign in to comment.