Skip to content

Commit

Permalink
Merge pull request #20 from volcengine/feat/doc
Browse files Browse the repository at this point in the history
Feat/doc
  • Loading branch information
xuyaming0800 authored Aug 29, 2022
2 parents 0aa0a4f + 0d17e5f commit 35bf8c9
Show file tree
Hide file tree
Showing 55 changed files with 605 additions and 143 deletions.
6 changes: 6 additions & 0 deletions common/common_volcengine_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ func ResponseToResourceData(d *schema.ResourceData, resource *schema.Resource, d
} else {
targetValue = v
}
} else if _, ok3 := r.Elem.(schema.ValueType); ok3 {
if convert.Convert != nil {
targetValue = convert.Convert(v)
} else {
targetValue = v
}
}
} else {
if convert.Convert != nil {
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.17"
TerraformProviderVersion = "0.0.18"
)
4 changes: 2 additions & 2 deletions example/clb/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
resource "volcengine_clb" "foo" {
type = "public"
subnet_id = "subnet-2744i7u9alnnk7fap8tkq8aft"
subnet_id = "subnet-273xjcb6wohs07fap8sz3ihhs"
load_balancer_spec = "small_1"
region_id = "cn-north-3"
description = "Demo"
load_balancer_name = "terraform-auto-create"
}
42 changes: 39 additions & 3 deletions example/listener/main.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,55 @@
resource "volcengine_listener" "foo" {
load_balancer_id = "clb-273ylkl0a3i807fap8t4unbsq"
load_balancer_id = "clb-274xltt3rfmyo7fap8sv1jq39"
listener_name = "Demo-HTTP-90"
protocol = "HTTP"
port = 90
server_group_id = "rsp-273yv0kir1vk07fap8tt9jtwg"
server_group_id = "rsp-274xltv2sjoxs7fap8tlv3q3s"
health_check {
enabled = "on"
interval = 10
timeout = 3
healthy_threshold = 5
un_healthy_threshold = 2
domain = "github.com"
domain = "volcengine.com"
http_code = "http_2xx"
method = "GET"
uri = "/"
}
enabled = "on"
}

resource "volcengine_listener" "bar" {
load_balancer_id = "clb-274xltt3rfmyo7fap8sv1jq39"
listener_name = "Demo-HTTP-91"
protocol = "HTTP"
port = 91
server_group_id = "rsp-274xltv2sjoxs7fap8tlv3q3s"
health_check {
enabled = "on"
interval = 10
timeout = 3
healthy_threshold = 5
un_healthy_threshold = 2
domain = "volcengine.com"
http_code = "http_2xx"
method = "GET"
uri = "/"
}
enabled = "on"
}

resource "volcengine_listener" "demo" {
load_balancer_id = "clb-274xltt3rfmyo7fap8sv1jq39"
protocol = "TCP"
port = 92
server_group_id = "rsp-274xltv2sjoxs7fap8tlv3q3s"
health_check {
enabled = "on"
interval = 10
timeout = 3
healthy_threshold = 5
un_healthy_threshold = 2
}
enabled = "on"
established_timeout = 10
}
5 changes: 2 additions & 3 deletions example/serverGroupServer/main.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
resource "volcengine_server_group_server" "foo" {
server_group_id = "rsp-273zn4ewlhkw07fap8tig9ujz"
instance_id = "i-72q1zvko6i5lnawvg940"
server_group_id = "rsp-274xltv2sjoxs7fap8tlv3q3s"
instance_id = "i-ybp1scasbe72q1vq35wv"
type = "ecs"
weight = 100
ip = "192.168.100.99"
port = 80
description = "This is a server"
}
9 changes: 5 additions & 4 deletions volcengine/clb/clb/resource_volcengine_clb.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func ResourceVolcengineClb() *schema.Resource {
Schema: map[string]*schema.Schema{
"region_id": {
Type: schema.TypeString,
Required: true,
Optional: true,
Computed: true,
ForceNew: true,
Description: "The region of the request.",
},
Expand Down Expand Up @@ -75,7 +76,7 @@ func ResourceVolcengineClb() *schema.Resource {
"modification_protection_status": {
Type: schema.TypeString,
Optional: true,
Description: "The status of the console modification protection.",
Description: "The status of the console modification protection, the value can be `NonProtection` or `ConsoleProtection`.",
ValidateFunc: validation.StringInSlice([]string{"NonProtection", "ConsoleProtection"}, false),
},
"modification_protection_reason": {
Expand All @@ -86,14 +87,14 @@ func ResourceVolcengineClb() *schema.Resource {
"load_balancer_spec": {
Type: schema.TypeString,
Required: true,
Description: "The specification of the CLB.",
Description: "The specification of the CLB, the value can be `small_1`, `small_2`, `medium_1`, `medium_2`, `large_1`, `large_2`.",
},
"load_balancer_billing_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
Description: "The billing type of the CLB.",
Description: "The billing type of the CLB, the value can be `PostPaid`.",
ValidateFunc: validation.StringInSlice([]string{"PostPaid"}, false),
},
//"period_unit": {
Expand Down
11 changes: 11 additions & 0 deletions volcengine/clb/clb/service_volcengine_clb.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ func (s *VolcengineClbService) ReadResource(resourceData *schema.ResourceData, c
if len(data) == 0 {
return data, fmt.Errorf("Clb %s not exist ", clbId)
}

data["RegionId"] = *s.Client.ClbClient.Config.Region

return data, err
}

Expand Down Expand Up @@ -171,6 +174,14 @@ func (s *VolcengineClbService) CreateResource(resourceData *schema.ResourceData,
},
},
},
BeforeCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (bool, error) {
if regionId, ok := (*call.SdkParam)["RegionId"]; !ok {
(*call.SdkParam)["RegionId"] = *s.Client.ClbClient.Config.Region
} else if regionId.(string) != *s.Client.ClbClient.Config.Region {
return false, fmt.Errorf("region_id is not equal to provider region config(%s)", *s.Client.ClbClient.Config.Region)
}
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)
//创建clb
Expand Down
14 changes: 7 additions & 7 deletions volcengine/clb/listener/resource_volcengine_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func ResourceVolcengineListener() *schema.Resource {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Description: "The port receiving request of the Listener.",
Description: "The port receiving request of the Listener, the value range in 1~65535.",
},
"scheduler": {
Type: schema.TypeString,
Expand Down Expand Up @@ -139,31 +139,31 @@ func ResourceVolcengineListener() *schema.Resource {
"interval": {
Type: schema.TypeInt,
Optional: true,
Description: "The interval executing health check.",
Description: "The interval executing health check, default 2, range in 1~300.",
DiffSuppressFunc: HealthCheckFieldDiffSuppress,
},
"timeout": {
Type: schema.TypeInt,
Optional: true,
Description: "The response timeout of health check.",
Description: "The response timeout of health check, default 2, range in 1~60..",
DiffSuppressFunc: HealthCheckFieldDiffSuppress,
},
"healthy_threshold": {
Type: schema.TypeInt,
Optional: true,
Description: "The healthy threshold of health check.",
Description: "The healthy threshold of health check, default 3, range in 2~10.",
DiffSuppressFunc: HealthCheckFieldDiffSuppress,
},
"un_healthy_threshold": {
Type: schema.TypeInt,
Optional: true,
Description: "The unhealthy threshold of health check.",
Description: "The unhealthy threshold of health check, default 3, range in 2~10.",
DiffSuppressFunc: HealthCheckFieldDiffSuppress,
},
"method": {
Type: schema.TypeString,
Optional: true,
Description: "The method of health check.",
Description: "The method of health check, the value can be `GET` or `HEAD`.",
DiffSuppressFunc: HealthCheckHTTPOnlyFieldDiffSuppress,
},
"domain": {
Expand All @@ -181,7 +181,7 @@ func ResourceVolcengineListener() *schema.Resource {
"http_code": {
Type: schema.TypeString,
Optional: true,
Description: "The normal http status code of health check.",
Description: "The normal http status code of health check, the value can be `http_2xx` or `http_3xx` or `http_4xx` or `http_5xx`.",
DiffSuppressFunc: HealthCheckHTTPOnlyFieldDiffSuppress,
},
},
Expand Down
59 changes: 49 additions & 10 deletions volcengine/clb/listener/service_volcengine_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,32 +90,40 @@ func (s *VolcengineListenerService) ReadResource(resourceData *schema.ResourceDa

clbClient := s.Client.ClbClient

listenerAttr, err := clbClient.DescribeListenerAttributesCommon(&map[string]interface{}{
listenerResp, err := clbClient.DescribeListenerAttributesCommon(&map[string]interface{}{
"ListenerId": listenerId,
})
if err != nil {
return nil, err
}
timeout, err := ve.ObtainSdkValue("Result.EstablishedTimeout", *listenerAttr)

listenerAttrMap := make(map[string]interface{})

timeout, err := ve.ObtainSdkValue("Result.EstablishedTimeout", *listenerResp)
if err != nil {
return nil, err
}
desc, err := ve.ObtainSdkValue("Result.Description", *listenerAttr)
desc, err := ve.ObtainSdkValue("Result.Description", *listenerResp)
if err != nil {
return nil, err
}
loadBalancerId, err := ve.ObtainSdkValue("Result.LoadBalancerId", *listenerAttr)
loadBalancerId, err := ve.ObtainSdkValue("Result.LoadBalancerId", *listenerResp)
if err != nil {
return nil, err
}
scheduler, err := ve.ObtainSdkValue("Result.Scheduler", *listenerAttr)
scheduler, err := ve.ObtainSdkValue("Result.Scheduler", *listenerResp)
if err != nil {
return nil, err
}
_ = resourceData.Set("established_timeout", int(timeout.(float64)))
_ = resourceData.Set("description", desc.(string))
_ = resourceData.Set("load_balancer_id", loadBalancerId.(string))
_ = resourceData.Set("scheduler", scheduler.(string))

listenerAttrMap["EstablishedTimeout"] = timeout
listenerAttrMap["Description"] = desc
listenerAttrMap["LoadBalancerId"] = loadBalancerId
listenerAttrMap["Scheduler"] = scheduler

for k, v := range listenerAttrMap {
data[k] = v
}

return data, err
}
Expand Down Expand Up @@ -147,7 +155,7 @@ func (s *VolcengineListenerService) RefreshResourceState(resourceData *schema.Re

}

func (VolcengineListenerService) WithResourceResponseHandlers(listener map[string]interface{}) []ve.ResourceResponseHandler {
func (*VolcengineListenerService) WithResourceResponseHandlers(listener map[string]interface{}) []ve.ResourceResponseHandler {
handler := func() (map[string]interface{}, map[string]ve.ResponseConvert, error) {
return listener, nil, nil
}
Expand All @@ -168,6 +176,23 @@ func (s *VolcengineListenerService) CreateResource(resourceData *schema.Resource
ConvertType: ve.ConvertListUnique,
},
},
BeforeCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (bool, error) {
protocol := (*call.SdkParam)["Protocol"].(string)
// 1. established_timeout
if protocol == "HTTP" || protocol == "HTTPS" {
// not allow establish_timeout
if _, ok := (*call.SdkParam)["EstablishedTimeout"]; ok {
return false, errors.New("established_timeout is not allowed for HTTP or HTTPS")
}
}

// 2. certificate_id
if protocol != "HTTPS" && (*call.SdkParam)["CertificateId"] != nil {
return false, errors.New("certificate_id is only allowed for HTTPS")
}

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)
//创建listener
Expand Down Expand Up @@ -220,6 +245,20 @@ func (s *VolcengineListenerService) ModifyResource(resourceData *schema.Resource
},
},
BeforeCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (bool, error) {
protocol := d.Get("protocol").(string)
// 1. established_timeout
if protocol == "HTTP" || protocol == "HTTPS" {
// not allow establish_timeout
if _, ok := (*call.SdkParam)["EstablishedTimeout"]; ok {
return false, errors.New("established_timeout is not allowed for HTTP or HTTPS")
}
}

// 2. certificate_id
if protocol != "HTTPS" && (*call.SdkParam)["CertificateId"] != nil {
return false, errors.New("certificate_id is only allowed for HTTPS")
}

(*call.SdkParam)["ListenerId"] = d.Id()
aclStatus := d.Get("acl_status")
if aclStatus, ok := aclStatus.(string); ok && aclStatus == "on" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
Import
ServerGroupServer can be imported using the id, e.g.
```
$ terraform import volcengine_server_group_server.default rs-3ciynux6i1x4w****rszh49sj
$ terraform import volcengine_server_group_server.default rsp-274xltv2*****8tlv3q3s:rs-3ciynux6i1x4w****rszh49sj
```
*/
Expand All @@ -30,7 +30,7 @@ func ResourceVolcengineServerGroupServer() *schema.Resource {
Schema: map[string]*schema.Schema{
"server_group_id": {
Type: schema.TypeString,
Optional: true,
Required: true,
ForceNew: true,
Description: "The ID of the ServerGroup.",
},
Expand All @@ -41,31 +41,32 @@ func ResourceVolcengineServerGroupServer() *schema.Resource {
},
"instance_id": {
Type: schema.TypeString,
Optional: true,
Required: true,
ForceNew: true,
Description: "The ID of ecs instance or the network card bound to ecs instance.",
},
"type": {
Type: schema.TypeString,
Optional: true,
Required: true,
ForceNew: true,
Description: "The type of instance. Optional choice contains `ecs`, `eni`.",
ValidateFunc: validation.StringInSlice([]string{"ecs", "eni"}, false),
},
"weight": {
Type: schema.TypeInt,
Optional: true,
Description: "The weight of the instance.",
Description: "The weight of the instance, range in 0~100.",
},
"ip": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
Description: "The private ip of the instance.",
},
"port": {
Type: schema.TypeInt,
Optional: true,
Required: true,
Description: "The port receiving request.",
},
"description": {
Expand Down
Loading

0 comments on commit 35bf8c9

Please sign in to comment.