Skip to content

Commit

Permalink
chore(deps): bump cloud SDK to v1.56.0 (#1041)
Browse files Browse the repository at this point in the history
  • Loading branch information
chengxiangdong authored Oct 13, 2023
1 parent f653c6b commit 527394b
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,31 +176,36 @@ resource "flexibleengine_networking_secgroup_v2" "test" {
name = "%[1]s"
}
resource "flexibleengine_rds_instance_v3" "test" {
name = "%[1]s"
flavor = "rds.mysql.s3.large.2.ha"
security_group_id = flexibleengine_networking_secgroup_v2.test.id
subnet_id = flexibleengine_vpc_subnet_v1.test.id
vpc_id = flexibleengine_vpc_v1.test.id
fixed_ip = "192.168.0.58"
ha_replication_mode = "semisync"
availability_zone = [
data.flexibleengine_availability_zones.test.names[0],
data.flexibleengine_availability_zones.test.names[1],
]
db {
password = "Huangwei!120521"
type = "MySQL"
version = "5.7"
port = 3306
}
data "flexibleengine_rds_flavors_v3" "test" {
db_type = "MySQL"
db_version = "5.7"
instance_mode = "single"
vcpus = 2
memory = 4
}
volume {
type = "ULTRAHIGH"
size = 50
}
resource "flexibleengine_rds_instance_v3" "test" {
name = "%[1]s"
flavor = data.flexibleengine_rds_flavors_v3.test.flavors[0].name
security_group_id = flexibleengine_networking_secgroup_v2.test.id
subnet_id = flexibleengine_vpc_subnet_v1.test.id
vpc_id = flexibleengine_vpc_v1.test.id
availability_zone = [
data.flexibleengine_availability_zones.test.names[0]
]
db {
password = "Huangwei!120521"
type = "MySQL"
version = "5.7"
port = 3306
}
volume {
type = "ULTRAHIGH"
size = 40
}
}
`, rName)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,79 @@
package acceptance

import (
"encoding/json"
"fmt"
"strings"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

"github.com/chnsz/golangsdk/pagination"
model "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/rds/v3/model"

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/rds"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils"
)

func getRdsDatabasePrivilegeFunc(conf *config.Config, state *terraform.ResourceState) (interface{}, error) {
client, err := conf.HcRdsV3Client(OS_REGION_NAME)
func getRdsDatabasePrivilegeFunc(cfg *config.Config, state *terraform.ResourceState) (interface{}, error) {
region := OS_REGION_NAME
// getMysqlDatabasePrivilege: query RDS Mysql database privilege
var (
getMysqlDatabasePrivilegeHttpUrl = "v3/{project_id}/instances/{instance_id}/database/db_user"
getMysqlDatabasePrivilegeProduct = "rds"
)
getMysqlDatabasePrivilegeClient, err := cfg.NewServiceClient(getMysqlDatabasePrivilegeProduct, region)
if err != nil {
return nil, fmt.Errorf("error creating RDS client: %s", err)
}

// Split instance_id and database from resource id
parts := strings.SplitN(state.Primary.ID, "/", 2)
parts := strings.Split(state.Primary.ID, "/")
if len(parts) != 2 {
return nil, fmt.Errorf("invalid id format, must be <instance_id>/<database_name>")
return nil, fmt.Errorf("invalid id format, must be <instance_id>/<db_name>")
}
instanceId := parts[0]
dbName := parts[1]
return rds.QueryDatabaseUsers(client, instanceId, dbName)

getMysqlDatabasePrivilegePath := getMysqlDatabasePrivilegeClient.Endpoint + getMysqlDatabasePrivilegeHttpUrl
getMysqlDatabasePrivilegePath = strings.ReplaceAll(getMysqlDatabasePrivilegePath, "{project_id}",
getMysqlDatabasePrivilegeClient.ProjectID)
getMysqlDatabasePrivilegePath = strings.ReplaceAll(getMysqlDatabasePrivilegePath, "{instance_id}", instanceId)

getMysqlDatabasePrivilegeQueryParams := buildGetMysqlDatabasePrivilegeQueryParams(dbName)
getMysqlDatabasePrivilegePath += getMysqlDatabasePrivilegeQueryParams

getMysqlDatabasePrivilegeResp, err := pagination.ListAllItems(
getMysqlDatabasePrivilegeClient,
"page",
getMysqlDatabasePrivilegePath,
&pagination.QueryOpts{MarkerField: ""})
if err != nil {
return nil, fmt.Errorf("error retrieving Mysql database privilege: %s", err)
}

getMysqlDatabasePrivilegeRespJson, err := json.Marshal(getMysqlDatabasePrivilegeResp)
if err != nil {
return nil, fmt.Errorf("error retrieving Mysql database privilege: %s", err)
}
var getMysqlDatabasePrivilegeRespBody interface{}
err = json.Unmarshal(getMysqlDatabasePrivilegeRespJson, &getMysqlDatabasePrivilegeRespBody)
if err != nil {
return nil, fmt.Errorf("error retrieving Mysql database privilege: %s", err)
}

curJson := utils.PathSearch("users", getMysqlDatabasePrivilegeRespBody, make([]interface{}, 0))
if len(curJson.([]interface{})) == 0 {
return nil, fmt.Errorf("error get RDS Mysql database privilege")
}

return getMysqlDatabasePrivilegeRespBody, nil
}

func buildGetMysqlDatabasePrivilegeQueryParams(dbName string) string {
return fmt.Sprintf("?db-name=%s&page=1&limit=100", dbName)
}

func TestAccRdsDatabasePrivilege_basic(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package acceptance

import (
"encoding/json"
"fmt"
"strings"
"testing"
Expand All @@ -9,25 +10,63 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/rds/v3/model"

"github.com/chnsz/golangsdk/pagination"

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/rds"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils"
)

func getRdsDatabaseFunc(conf *config.Config, state *terraform.ResourceState) (interface{}, error) {
client, err := conf.HcRdsV3Client(OS_REGION_NAME)
func getRdsDatabaseFunc(cfg *config.Config, state *terraform.ResourceState) (interface{}, error) {
region := OS_REGION_NAME
// getMysqlDatabase: query RDS Mysql database
var (
getMysqlDatabaseHttpUrl = "v3/{project_id}/instances/{instance_id}/database/detail?page=1&limit=100"
getMysqlDatabaseProduct = "rds"
)
getMysqlDatabaseClient, err := cfg.NewServiceClient(getMysqlDatabaseProduct, region)
if err != nil {
return nil, fmt.Errorf("error creating RDS client: %s", err)
}

// Split instance_id and database from resource id
parts := strings.SplitN(state.Primary.ID, "/", 2)
parts := strings.Split(state.Primary.ID, "/")
if len(parts) != 2 {
return nil, fmt.Errorf("invalid id format, must be <instance_id>/<database_name>")
return nil, fmt.Errorf("invalid id format, must be <instance_id>/<name>")
}
instanceId := parts[0]
dbName := parts[1]
return rds.QueryDatabases(client, instanceId, dbName)

getMysqlDatabasePath := getMysqlDatabaseClient.Endpoint + getMysqlDatabaseHttpUrl
getMysqlDatabasePath = strings.ReplaceAll(getMysqlDatabasePath, "{project_id}", getMysqlDatabaseClient.ProjectID)
getMysqlDatabasePath = strings.ReplaceAll(getMysqlDatabasePath, "{instance_id}", instanceId)

getMysqlDatabaseResp, err := pagination.ListAllItems(
getMysqlDatabaseClient,
"page",
getMysqlDatabasePath,
&pagination.QueryOpts{MarkerField: ""})

if err != nil {
return nil, fmt.Errorf("error retrieving MysqlDatabase")
}

getMysqlDatabaseRespJson, err := json.Marshal(getMysqlDatabaseResp)
if err != nil {
return nil, err
}
var getMysqlDatabaseRespBody interface{}
err = json.Unmarshal(getMysqlDatabaseRespJson, &getMysqlDatabaseRespBody)
if err != nil {
return nil, err
}

database := utils.PathSearch(fmt.Sprintf("databases[?name=='%s']|[0]", dbName), getMysqlDatabaseRespBody, nil)
if database != nil {
return database, nil
}

return nil, fmt.Errorf("error get RDS Mysql database by instanceID %s and database %s", instanceId, dbName)
}

func TestAccRdsDatabase_basic(t *testing.T) {
Expand Down
10 changes: 6 additions & 4 deletions flexibleengine/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import (
"time"

"github.com/chnsz/golangsdk"
"github.com/chnsz/golangsdk/auth"
huaweisdk "github.com/chnsz/golangsdk/openstack"
"github.com/chnsz/golangsdk/openstack/identity/v3/domains"

huaweiconfig "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/helper/pathorcontents"
)
Expand Down Expand Up @@ -152,10 +154,10 @@ func genClient(c *Config, ao golangsdk.AuthOptionsProvider) (*golangsdk.Provider
},
CheckRedirect: func(req *http.Request, via []*http.Request) error {
if client.AKSKAuthOptions.AccessKey != "" {
golangsdk.ReSign(req, golangsdk.SignOptions{
AccessKey: client.AKSKAuthOptions.AccessKey,
SecretKey: client.AKSKAuthOptions.SecretKey,
})
err := auth.Sign(req, client.AKSKAuthOptions.AccessKey, client.AKSKAuthOptions.SecretKey)
if err != nil {
return err
}
}
return nil
},
Expand Down
12 changes: 6 additions & 6 deletions flexibleengine/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func Provider() *schema.Provider {
"flexibleengine_as_groups": as.DataSourceASGroups(),

"flexibleengine_enterprise_project": eps.DataSourceEnterpriseProject(),
"flexibleengine_cbr_vaults": cbr.DataSourceCbrVaultsV3(),
"flexibleengine_cbr_vaults": cbr.DataSourceVaults(),
"flexibleengine_cbr_backup": cbr.DataSourceBackup(),
"flexibleengine_cce_clusters": cce.DataSourceCCEClusters(),

Expand Down Expand Up @@ -467,7 +467,7 @@ func Provider() *schema.Provider {
"flexibleengine_as_notification": as.ResourceAsNotification(),

"flexibleengine_enterprise_project": eps.ResourceEnterpriseProject(),
"flexibleengine_cbr_policy": cbr.ResourceCBRPolicyV3(),
"flexibleengine_cbr_policy": cbr.ResourcePolicy(),
"flexibleengine_cbr_vault": cbr.ResourceVault(),
"flexibleengine_cce_namespace": cce.ResourceCCENamespaceV1(),
"flexibleengine_cce_pvc": cce.ResourceCcePersistentVolumeClaimsV1(),
Expand Down Expand Up @@ -519,9 +519,9 @@ func Provider() *schema.Provider {

"flexibleengine_obs_bucket_acl": obs.ResourceOBSBucketAcl(),

"flexibleengine_rds_account": rds.ResourceRdsAccount(),
"flexibleengine_rds_database": rds.ResourceRdsDatabase(),
"flexibleengine_rds_database_privilege": rds.ResourceRdsDatabasePrivilege(),
"flexibleengine_rds_account": rds.ResourceMysqlAccount(),
"flexibleengine_rds_database": rds.ResourceMysqlDatabase(),
"flexibleengine_rds_database_privilege": rds.ResourceMysqlDatabasePrivilege(),
"flexibleengine_sms_server_template": sms.ResourceServerTemplate(),
"flexibleengine_sms_task": sms.ResourceMigrateTask(),
"flexibleengine_swr_organization": swr.ResourceSWROrganization(),
Expand Down Expand Up @@ -559,7 +559,7 @@ func Provider() *schema.Provider {
"flexibleengine_lb_member_v3": elb.ResourceMemberV3(), // v1.35.0
"flexibleengine_smn_topic_v2": smn.ResourceTopic(), // v1.39.0
"flexibleengine_smn_subscription_v2": smn.ResourceSubscription(), // v1.39.0
"flexibleengine_sfs_turbo": huaweicloud.ResourceSFSTurbo(), // v1.41.0
"flexibleengine_sfs_turbo": sfs.ResourceSFSTurbo(),

// Deprecated resource
"flexibleengine_as_group_v1": resourceASGroup(),
Expand Down
20 changes: 12 additions & 8 deletions flexibleengine/resource_flexibleengine_cce_node_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import (
"strings"
"time"

"github.com/chnsz/golangsdk"
"github.com/chnsz/golangsdk/openstack/cce/v3/nodepools"
"github.com/chnsz/golangsdk/openstack/cce/v3/nodes"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/chnsz/golangsdk"
"github.com/chnsz/golangsdk/openstack/cce/v3/nodepools"
"github.com/chnsz/golangsdk/openstack/cce/v3/nodes"

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils"
)

func resourceCCENodePool() *schema.Resource {
Expand Down Expand Up @@ -462,27 +465,28 @@ func resourceCCENodePoolUpdate(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Error creating Flexibleengine CCE client: %s", err)
}

initialNodeCount := d.Get("initial_node_count").(int)
specLogin := buildCCENodePoolLoginSpec(d)
rootVolume := resourceCCERootVolume(d)
updateOpts := nodepools.UpdateOpts{
Kind: "NodePool",
ApiVersion: "v3",
Metadata: nodepools.UpdateMetaData{
Name: d.Get("name").(string),
},
Spec: nodepools.UpdateSpec{
InitialNodeCount: &initialNodeCount,
InitialNodeCount: utils.Int(d.Get("initial_node_count").(int)),
Autoscaling: nodepools.AutoscalingSpec{
Enable: d.Get("scale_enable").(bool) || d.Get("scall_enable").(bool),
MinNodeCount: d.Get("min_node_count").(int),
MaxNodeCount: d.Get("max_node_count").(int),
ScaleDownCooldownTime: d.Get("scale_down_cooldown_time").(int),
Priority: d.Get("priority").(int),
},
NodeTemplate: nodes.Spec{
NodeTemplate: nodepools.UpdateNodeTemplate{
Flavor: d.Get("flavor_id").(string),
Az: d.Get("availability_zone").(string),
Login: buildCCENodePoolLoginSpec(d),
RootVolume: resourceCCERootVolume(d),
Login: &specLogin,
RootVolume: &rootVolume,
DataVolumes: resourceCCEDataVolume(d),
Count: 1,
K8sTags: resourceCCENodeK8sTags(d),
Expand Down
9 changes: 6 additions & 3 deletions flexibleengine/resource_flexibleengine_identity_user_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import (
"regexp"
"strings"

iam_users "github.com/chnsz/golangsdk/openstack/identity/v3.0/users"
"github.com/chnsz/golangsdk/openstack/identity/v3/users"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"

iam_users "github.com/chnsz/golangsdk/openstack/identity/v3.0/users"
"github.com/chnsz/golangsdk/openstack/identity/v3/users"

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils"
)

func resourceIdentityUserV3() *schema.Resource {
Expand Down Expand Up @@ -158,7 +161,7 @@ func resourceIdentityUserV3Update(ctx context.Context, d *schema.ResourceData, m
}

if d.HasChange("description") {
updateOpts.Description = d.Get("description").(string)
updateOpts.Description = utils.String(d.Get("description").(string))
}

if d.HasChange("email") {
Expand Down
Loading

0 comments on commit 527394b

Please sign in to comment.