Skip to content

Commit

Permalink
feat: merge
Browse files Browse the repository at this point in the history
  • Loading branch information
zpp12354321 committed Feb 16, 2023
2 parents 38a0f2c + dba442a commit 58fce06
Show file tree
Hide file tree
Showing 73 changed files with 2,127 additions and 14 deletions.
33 changes: 33 additions & 0 deletions common/common_volcengine_dispatcher.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
package common

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"golang.org/x/time/rate"
)

type Dispatcher struct {
rateInfo *RateInfo
}

type RateInfo struct {
Create *rate.Limiter
Read *rate.Limiter
Update *rate.Limiter
Delete *rate.Limiter
Data *rate.Limiter
}

func NewRateLimitDispatcher(r *RateInfo) *Dispatcher {
return &Dispatcher{
rateInfo: r,
}
}

func (d *Dispatcher) Create(resourceService ResourceService, resourceDate *schema.ResourceData, resource *schema.Resource) (err error) {
if d.rateInfo != nil && d.rateInfo.Create != nil {
_ = d.rateInfo.Create.Wait(context.Background())
}
callbacks := resourceService.CreateResource(resourceDate, resource)
var calls []SdkCall
for _, callback := range callbacks {
Expand All @@ -24,6 +45,9 @@ func (d *Dispatcher) Create(resourceService ResourceService, resourceDate *schem
}

func (d *Dispatcher) Update(resourceService ResourceService, resourceDate *schema.ResourceData, resource *schema.Resource) (err error) {
if d.rateInfo != nil && d.rateInfo.Update != nil {
_ = d.rateInfo.Update.Wait(context.Background())
}
callbacks := resourceService.ModifyResource(resourceDate, resource)
var calls []SdkCall
for _, callback := range callbacks {
Expand All @@ -40,6 +64,9 @@ func (d *Dispatcher) Update(resourceService ResourceService, resourceDate *schem
}

func (d *Dispatcher) Read(resourceService ResourceService, resourceDate *schema.ResourceData, resource *schema.Resource) (err error) {
if d.rateInfo != nil && d.rateInfo.Read != nil {
_ = d.rateInfo.Read.Wait(context.Background())
}
instance, err := resourceService.ReadResource(resourceDate, resourceDate.Id())
if err != nil {
return err
Expand Down Expand Up @@ -67,6 +94,9 @@ func (d *Dispatcher) Read(resourceService ResourceService, resourceDate *schema.
}

func (d *Dispatcher) Delete(resourceService ResourceService, resourceDate *schema.ResourceData, resource *schema.Resource) (err error) {
if d.rateInfo != nil && d.rateInfo.Delete != nil {
_ = d.rateInfo.Delete.Wait(context.Background())
}
callbacks := resourceService.RemoveResource(resourceDate, resource)
var calls []SdkCall
for _, callback := range callbacks {
Expand All @@ -88,6 +118,9 @@ func (d *Dispatcher) Data(resourceService ResourceService, resourceDate *schema.
condition map[string]interface{}
collection []interface{}
)
if d.rateInfo != nil && d.rateInfo.Data != nil {
_ = d.rateInfo.Data.Wait(context.Background())
}
info = resourceService.DatasourceResources(resourceDate, resource)
condition, err = DataSourceToRequest(resourceDate, resource, info)
if err != 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.48"
TerraformProviderVersion = "0.0.51"
)
2 changes: 2 additions & 0 deletions example/dataClbZones/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
data "volcengine_clb_zones" "default" {
}
6 changes: 6 additions & 0 deletions example/dataNetworkAcls/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
data "volcengine_network_acls" "default"{
# ids = ["nacl-172leak37mi9s4d1w33pswqkh"]
# vpc_id = "vpc-ru0wv9alfoxsu3nuld85rpp"
# subnet_id = "subnet-637jxq81u5mon3gd6ivc7rj"
network_acl_name = "ms-tf-acl"
}
16 changes: 16 additions & 0 deletions example/networkAcl/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
resource "volcengine_network_acl" "foo" {
vpc_id = "vpc-ru0wv9alfoxsu3nuld85rpp"
network_acl_name = "tf-test-acl"
ingress_acl_entries {
network_acl_entry_name = "ingress1"
policy = "accept"
protocol = "all"
source_cidr_ip = "192.168.0.0/24"
}
egress_acl_entries {
network_acl_entry_name = "egress2"
policy = "accept"
protocol = "all"
destination_cidr_ip = "192.168.0.0/16"
}
}
9 changes: 9 additions & 0 deletions example/networkAclAssociate/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "volcengine_network_acl" "foo" {
vpc_id = "vpc-ru0wv9alfoxsu3nuld85rpp"
network_acl_name = "tf-test-acl"
}

resource "volcengine_network_acl_associate" "foo1" {
network_acl_id = volcengine_network_acl.foo.id
resource_id = "subnet-637jxq81u5mon3gd6ivc7rj"
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ require (
github.com/stretchr/testify v1.7.0
github.com/volcengine/volcengine-go-sdk v1.0.3
golang.org/x/sync v0.0.0-20190423024810-112230192c58
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
)
2 changes: 2 additions & 0 deletions volcengine/cen/cen/data_source_volcengine_cens.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func DataSourceVolcengineCens() *schema.Resource {
Computed: true,
Description: "The total count of cen query.",
},
"tags": ve.TagsSchema(),
"cens": {
Description: "The collection of cen query.",
Type: schema.TypeList,
Expand Down Expand Up @@ -99,6 +100,7 @@ func DataSourceVolcengineCens() *schema.Resource {
},
Description: "A list of bandwidth package IDs of the cen.",
},
"tags": ve.TagsSchemaComputed(),
},
},
},
Expand Down
1 change: 1 addition & 0 deletions volcengine/cen/cen/resource_volcengine_cen.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func ResourceVolcengineCen() *schema.Resource {
Computed: true,
Description: "The description of the cen.",
},
"tags": ve.TagsSchema(),
},
}
s := DataSourceVolcengineCens().Schema["cens"].Elem.(*schema.Resource).Schema
Expand Down
22 changes: 21 additions & 1 deletion volcengine/cen/cen/service_volcengine_cen.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,27 @@ func (s *VolcengineCenService) CreateResource(resourceData *schema.ResourceData,
Target: []string{"Available"},
Timeout: resourceData.Timeout(schema.TimeoutCreate),
},
Convert: map[string]ve.RequestConvert{
"tags": {
TargetField: "Tags",
ConvertType: ve.ConvertListN,
},
},
},
}
return []ve.Callback{callback}

}

func (s *VolcengineCenService) ModifyResource(resourceData *schema.ResourceData, resource *schema.Resource) []ve.Callback {
var callbacks []ve.Callback
callback := ve.Callback{
Call: ve.SdkCall{
Action: "ModifyCenAttributes",
ConvertMode: ve.RequestConvertAll,
BeforeCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (bool, error) {
(*call.SdkParam)["CenId"] = d.Id()
delete(*call.SdkParam, "Tags")
return true, nil
},
ExecuteCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (*map[string]interface{}, error) {
Expand All @@ -202,7 +210,10 @@ func (s *VolcengineCenService) ModifyResource(resourceData *schema.ResourceData,
},
},
}
return []ve.Callback{callback}
callbacks = append(callbacks, callback)
tagCallback := ve.SetResourceTags(s.Client, "TagResources", "UntagResources", "cen", resourceData, getUniversalInfo)
callbacks = append(callbacks, tagCallback...)
return callbacks
}

func (s *VolcengineCenService) RemoveResource(resourceData *schema.ResourceData, r *schema.Resource) []ve.Callback {
Expand Down Expand Up @@ -251,6 +262,15 @@ func (s *VolcengineCenService) DatasourceResources(*schema.ResourceData, *schema
TargetField: "CenNames",
ConvertType: ve.ConvertWithN,
},
"tags": {
TargetField: "TagFilters",
ConvertType: ve.ConvertListN,
NextLevelConvert: map[string]ve.RequestConvert{
"value": {
TargetField: "Values.1",
},
},
},
},
NameField: "CenName",
IdField: "CenId",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func DataSourceVolcengineCenBandwidthPackages() *schema.Resource {
Computed: true,
Description: "The total count of cen bandwidth package query.",
},
"tags": ve.TagsSchema(),
"bandwidth_packages": {
Description: "The collection of cen bandwidth package query.",
Type: schema.TypeList,
Expand Down Expand Up @@ -154,6 +155,7 @@ func DataSourceVolcengineCenBandwidthPackages() *schema.Resource {
Computed: true,
Description: "The deleted time of the cen bandwidth package.",
},
"tags": ve.TagsSchemaComputed(),
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func ResourceVolcengineCenBandwidthPackage() *schema.Resource {
DiffSuppressFunc: periodDiffSuppress,
Description: "The period of the cen bandwidth package.",
},
"tags": ve.TagsSchema(),
},
}
s := DataSourceVolcengineCenBandwidthPackages().Schema["bandwidth_packages"].Elem.(*schema.Resource).Schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ func (s *VolcengineCenBandwidthPackageService) CreateResource(resourceData *sche
TargetField: "BillingType",
Convert: billingTypeRequestConvert,
},
"tags": {
TargetField: "Tags",
ConvertType: ve.ConvertListN,
},
},
BeforeCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (bool, error) {
(*call.SdkParam)["ClientToken"] = uuid.New().String()
Expand All @@ -211,6 +215,7 @@ func (s *VolcengineCenBandwidthPackageService) CreateResource(resourceData *sche
}

func (s *VolcengineCenBandwidthPackageService) ModifyResource(resourceData *schema.ResourceData, resource *schema.Resource) []ve.Callback {
var callbacks []ve.Callback
callback := ve.Callback{
Call: ve.SdkCall{
Action: "ModifyCenBandwidthPackageAttributes",
Expand All @@ -231,6 +236,7 @@ func (s *VolcengineCenBandwidthPackageService) ModifyResource(resourceData *sche
return false, nil
}
(*call.SdkParam)["CenBandwidthPackageId"] = d.Id()
delete(*call.SdkParam, "Tags")
return true, nil
},
ExecuteCall: func(d *schema.ResourceData, client *ve.SdkClient, call ve.SdkCall) (*map[string]interface{}, error) {
Expand All @@ -239,6 +245,9 @@ func (s *VolcengineCenBandwidthPackageService) ModifyResource(resourceData *sche
},
},
}
callbacks = append(callbacks, callback)
setResourceTagsCallbacks := ve.SetResourceTags(s.Client, "TagResources", "UntagResources", "cenbandwidthpackage", resourceData, getUniversalInfo)
callbacks = append(callbacks, setResourceTagsCallbacks...)
return []ve.Callback{callback}
}

Expand Down Expand Up @@ -292,6 +301,15 @@ func (s *VolcengineCenBandwidthPackageService) DatasourceResources(*schema.Resou
TargetField: "CenBandwidthPackageNames",
ConvertType: ve.ConvertWithN,
},
"tags": {
TargetField: "TagFilters",
ConvertType: ve.ConvertListN,
NextLevelConvert: map[string]ve.RequestConvert{
"value": {
TargetField: "Values.1",
},
},
},
},
NameField: "CenBandwidthPackageName",
IdField: "CenBandwidthPackageId",
Expand Down
10 changes: 10 additions & 0 deletions volcengine/clb/clb/data_source_volcengine_clbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ func DataSourceVolcengineClbs() *schema.Resource {
Description: "The ProjectName of the Clb.",
},
"tags": ve.TagsSchemaComputed(),
"master_zone_id": {
Type: schema.TypeString,
Computed: true,
Description: "The master zone ID of the CLB.",
},
"slave_zone_id": {
Type: schema.TypeString,
Computed: true,
Description: "The slave zone ID of the CLB.",
},
},
},
},
Expand Down
10 changes: 10 additions & 0 deletions volcengine/clb/clb/resource_volcengine_clb.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ func ResourceVolcengineClb() *schema.Resource {
Description: "The ProjectName of the CLB.",
},
"tags": ve.TagsSchema(),
"master_zone_id": {
Type: schema.TypeString,
Optional: true,
Description: "The master zone ID of the CLB.",
},
"slave_zone_id": {
Type: schema.TypeString,
Optional: true,
Description: "The slave zone ID of the CLB.",
},
//"period_unit": {
// Type: schema.TypeString,
// Optional: true,
Expand Down
10 changes: 10 additions & 0 deletions volcengine/clb/listener/data_source_volcengine_listeners.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ func DataSourceVolcengineListeners() *schema.Resource {
Computed: true,
Description: "The normal http status code of health check.",
},
"health_check_udp_request": {
Type: schema.TypeString,
Computed: true,
Description: "A request string to perform a health check.",
},
"health_check_udp_expect": {
Type: schema.TypeString,
Computed: true,
Description: "The expected response string for the health check.",
},
},
},
},
Expand Down
6 changes: 6 additions & 0 deletions volcengine/clb/listener/service_volcengine_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,12 @@ func (s *VolcengineListenerService) DatasourceResources(*schema.ResourceData, *s
"HealthCheck.HttpCode": {
TargetField: "health_check_http_code",
},
"HealthCheck.UdpRequest": {
TargetField: "health_check_udp_request",
},
"HealthCheck.UdpExpect": {
TargetField: "health_check_udp_expect",
},
},
}
}
Expand Down
Loading

0 comments on commit 58fce06

Please sign in to comment.