Skip to content

Commit

Permalink
Merge pull request #21 from volcengine/feat/vke-opt
Browse files Browse the repository at this point in the history
feat
  • Loading branch information
xuyaming0800 authored Aug 31, 2022
2 parents 35bf8c9 + 1399fc7 commit 8819832
Show file tree
Hide file tree
Showing 23 changed files with 1,389 additions and 147 deletions.
26 changes: 16 additions & 10 deletions common/common_volcengine_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,18 +369,24 @@ func RequestConvertListN(v interface{}, k string, t RequestConvert, req *map[str
var (
err error
isSet bool
m *schema.Set
ok bool
list []interface{}
)

if m, ok := v.(*schema.Set); ok {
if m, ok = v.(*schema.Set); ok {
v = m.List()
isSet = true
}
if list, ok := v.([]interface{}); ok {
if list, ok = v.([]interface{}); ok {
for index, v1 := range list {
if m1, ok := v1.(map[string]interface{}); ok {
if m1, ok1 := v1.(map[string]interface{}); ok1 {
if isSet {
index = m.F(m1)
}
for k2, v2 := range m1 {
flag := false
if isSet {
if t.NextLevelConvert != nil && t.NextLevelConvert[k2].ForceGet {
flag = true
} else {
schemaKey := fmt.Sprintf("%s.%d.%s", schemaChain+k, index, k2)
Expand All @@ -389,7 +395,7 @@ func RequestConvertListN(v interface{}, k string, t RequestConvert, req *map[str
flag = true
}
} else {
if _, ok := d.GetOk(schemaKey); ok {
if _, ok2 := d.GetOk(schemaKey); ok2 {
flag = true
}
}
Expand All @@ -405,21 +411,21 @@ func RequestConvertListN(v interface{}, k string, t RequestConvert, req *map[str
switch reflect.TypeOf(v2).Kind() {
case reflect.Slice:
if t.NextLevelConvert[k2].Convert != nil {
err = Convert(d, k2, t.NextLevelConvert[k2].Convert(d, v2), t.NextLevelConvert[k2], 0, req, k3, forceGet, contentType, k4)
err = Convert(d, k2, t.NextLevelConvert[k2].Convert(d, v2), t.NextLevelConvert[k2], 0, req, k3, t.NextLevelConvert[k2].ForceGet, contentType, k4)
} else {
err = Convert(d, k2, v2, t.NextLevelConvert[k2], 0, req, k3, forceGet, contentType, k4)
err = Convert(d, k2, v2, t.NextLevelConvert[k2], 0, req, k3, t.NextLevelConvert[k2].ForceGet, contentType, k4)
}

if err != nil {
return err
}
break
case reflect.Ptr:
if _v2, ok := v2.(*schema.Set); ok {
if _v2, ok2 := v2.(*schema.Set); ok2 {
if t.NextLevelConvert[k2].Convert != nil {
err = Convert(d, k2, t.NextLevelConvert[k2].Convert(d, _v2.List()), t.NextLevelConvert[k2], 0, req, k3, forceGet, contentType, k4)
err = Convert(d, k2, t.NextLevelConvert[k2].Convert(d, _v2.List()), t.NextLevelConvert[k2], 0, req, k3, t.NextLevelConvert[k2].ForceGet, contentType, k4)
} else {
err = Convert(d, k2, _v2.List(), t.NextLevelConvert[k2], 0, req, k3, forceGet, contentType, k4)
err = Convert(d, k2, _v2.List(), t.NextLevelConvert[k2], 0, req, k3, t.NextLevelConvert[k2].ForceGet, contentType, k4)
}
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion common/common_volcengine_diff_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func GetSetDifference(key string, d *schema.ResourceData, f schema.SchemaSetFunc
remove = removeProbably.Difference(addProbably)

if supportUpdate {
modify = removeProbably.Difference(remove)
modify = removeProbably.Difference(add)
}

return add, remove, modify, cache
Expand Down
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.18"
TerraformProviderVersion = "0.0.19"
)
19 changes: 6 additions & 13 deletions example/esCloudInstance/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
resource "volcengine_escloud_instance" "foo" {
instance_configuration {
version = "V7_10"
region_id = "cn-north-4"
zone_id = "cn-langfang-a"
region_id = "cn-xxx"
zone_id = "cn-xxx"
zone_number = 1
enable_https = true
admin_user_name = "admin"
admin_password = "1qaz!QAZ"
admin_password = "xxxxxx"
charge_type = "PostPaid"
configuration_code = "es.standard"
enable_pure_master = false
instance_name = "from-tf2"
instance_name = "from-tf4"
node_specs_assigns {
type = "Master"
number = 3
Expand All @@ -30,16 +30,9 @@ resource "volcengine_escloud_instance" "foo" {
type = "Kibana"
number = 1
resource_spec_name = "kibana.x2.small"
storage_spec_name = ""
storage_spec_name = "es.volume.essd.pl0"
storage_size = 0
}
subnet {
subnet_id = "subnet-1g0d5yqrsxszk8ibuxxzile2l"
subnet_name = "subnet-1g0d5yqrsxszk8ibuxxzile2l"
}
vpc {
vpc_id= "vpc-3cj17x7u9bzeo6c6rrtzfpaeb"
vpc_name = "test-1231新建"
}
subnet_id = "subnet-2bz9vxrixqigw2dx0eextz50p"
}
}
45 changes: 45 additions & 0 deletions example/vkeDefaultNodePool/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
resource "volcengine_vke_default_node_pool" "default" {
cluster_id = "ccc2umdnqtoflv91lqtq0"
node_config {
security {
login {
password = "amw4WTdVcTRJVVFsUXpVTw=="
}
security_group_ids = ["sg-2d6t6djr2wge858ozfczv41xq", "sg-3re6v4lz76yv45zsk2hjvvwcj"]
security_strategies = ["Hids"]
}
initialize_script = "ISMvYmluL2Jhc2gKZWNobyAx"
}
kubernetes_config {
labels {
key = "aa"
value = "bb"
}
labels {
key = "cccc"
value = "dddd"
}
taints {
key = "cccc"
value = "dddd"
effect = "NoSchedule"
}
taints {
key = "aa11"
value = "111"
effect = "NoSchedule"
}
cordon = true
}
instances {
instance_id = "i-ybvza90ohwexzk8emaa3"
keep_instance_name = false
additional_container_storage_enabled = false
}
instances {
instance_id = "i-ybvza90ohxexzkm4zihf"
keep_instance_name = false
additional_container_storage_enabled = true
container_storage_path = "/"
}
}
9 changes: 6 additions & 3 deletions example/vkeNodePool/main.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
resource "volcengine_vke_node_pool" "vke_test" {
cluster_id = "ccah01nnqtofnluts98j0"
name = "demo20"
cluster_id = "ccc2umdnqtoflv91lqtq0"
name = "tf-test"
node_config {
instance_type_ids = ["ecs.r1.large"]
subnet_ids = ["subnet-3recgzi7hfim85zsk2i8l9ve7"]
subnet_ids = ["subnet-3reyr9ld3obnk5zsk2iqb1kk3"]
security {
login {
# ssh_key_pair_name = "ssh-6fbl66fxqm"
password = "UHdkMTIzNDU2"
}
security_group_ids = ["sg-2bz8cga08u48w2dx0eeym1fzy", "sg-2d6t6djr2wge858ozfczv41xq"]
}
data_volumes {
type = "ESSD_PL0"
size = "60"
}
instance_charge_type = "PrePaid"
period = 1
}
kubernetes_config {
labels {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ func ResourceVolcengineESCloudInstance() *schema.Resource {
},
"region_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Optional: true,
Computed: true,
Description: "The region ID of ESCloud instance.",
},
"zone_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Optional: true,
Computed: true,
Description: "The available zone ID of ESCloud instance.",
},
"zone_number": {
Expand Down Expand Up @@ -145,45 +145,11 @@ func ResourceVolcengineESCloudInstance() *schema.Resource {
Optional: true,
Description: "The name of ESCloud instance.",
},
"vpc": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Description: "Information about the VPC where the instance is located.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"vpc_id": {
Type: schema.TypeString,
Required: true,
Description: "The ID of vpc.",
},
"vpc_name": {
Type: schema.TypeString,
Required: true,
Description: "The name of vpc.",
},
},
},
},
"subnet": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
"subnet_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The ID of subnet, the subnet must belong to the AZ selected.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"subnet_id": {
Type: schema.TypeString,
Required: true,
Description: "The ID of subnet.",
},
"subnet_name": {
Type: schema.TypeString,
Required: true,
Description: "The name of subnet.",
},
},
},
},
"project_name": {
Type: schema.TypeString,
Expand Down
98 changes: 90 additions & 8 deletions volcengine/escloud/instance/service_volcengine_escloud_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (s *VolcengineESCloudInstanceService) RefreshResourceState(resourceData *sc
status interface{}
failStates []string
)
failStates = append(failStates, "Failed")
failStates = append(failStates, "CreateFailed", "Error")
demo, err = s.ReadResource(resourceData, id)
if err != nil {
return nil, "", err
Expand Down Expand Up @@ -249,16 +249,98 @@ func (s *VolcengineESCloudInstanceService) CreateResource(resourceData *schema.R
},
},
},
"subnet": {
ConvertType: ve.ConvertJsonObject,
},
"vpc": {
ConvertType: ve.ConvertJsonObject,
TargetField: "VPC",
},
},
},
},
BeforeCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (bool, error) {
var (
results interface{}
subnets []interface{}
vpcs []interface{}
ok bool
)

// check region
regionId := *(s.Client.ClbClient.Config.Region)
if regionCustom, ok := (*call.SdkParam)["InstanceConfiguration.RegionId"]; ok {
if regionId != regionCustom.(string) {
return false, fmt.Errorf("region does not match")
}
}

// describe subnet
subnetId := (*call.SdkParam)["InstanceConfiguration.SubnetId"]
req := map[string]interface{}{
"SubnetIds.1": subnetId,
}
action := "DescribeSubnets"
resp, err := s.Client.VpcClient.DescribeSubnetsCommon(&req)
if err != nil {
return false, err
}
logger.Debug(logger.RespFormat, action, req, *resp)
results, err = ve.ObtainSdkValue("Result.Subnets", *resp)
if err != nil {
return false, err
}
if results == nil {
results = []interface{}{}
}
if subnets, ok = results.([]interface{}); !ok {
return false, errors.New("Result.Subnets is not Slice")
}
if len(subnets) == 0 {
return false, fmt.Errorf("subnet %s not exist", subnetId.(string))
}
subnetName := subnets[0].(map[string]interface{})["SubnetName"]
vpcId := subnets[0].(map[string]interface{})["VpcId"]
zoneId := subnets[0].(map[string]interface{})["ZoneId"]

//check zone
if zoneCustom, ok := (*call.SdkParam)["InstanceConfiguration.ZoneId"]; ok {
if zoneCustom.(string) != zoneId {
return false, fmt.Errorf("zone does not match")
}
}

// describe vpc
req = map[string]interface{}{
"Vpcs.1": vpcId,
}
action = "DescribeVpcs"
resp, err = s.Client.VpcClient.DescribeVpcsCommon(&req)
if err != nil {
return false, err
}
logger.Debug(logger.RespFormat, action, req, *resp)
results, err = ve.ObtainSdkValue("Result.Vpcs", *resp)
if err != nil {
return false, err
}
if results == nil {
results = []interface{}{}
}
if vpcs, ok = results.([]interface{}); !ok {
return false, errors.New("Result.Vpcs is not Slice")
}
if len(vpcs) == 0 {
return false, fmt.Errorf("vpc %s not exist", subnetId.(string))
}
vpcName := vpcs[0].(map[string]interface{})["VpcName"]
(*call.SdkParam)["InstanceConfiguration.VPC"] = map[string]interface{}{
"VpcId": vpcId,
"VpcName": vpcName,
}
(*call.SdkParam)["InstanceConfiguration.Subnet"] = map[string]interface{}{
"SubnetId": subnetId,
"SubnetName": subnetName,
}
(*call.SdkParam)["InstanceConfiguration.RegionId"] = regionId
(*call.SdkParam)["InstanceConfiguration.ZoneId"] = zoneId

logger.DebugInfo("sdk param:%v", *call.SdkParam)
return true, nil
},

ExecuteCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (*map[string]interface{}, error) {
logger.Debug(logger.RespFormat, call.Action, call.SdkParam)
Expand Down
Loading

0 comments on commit 8819832

Please sign in to comment.