Skip to content

Commit

Permalink
Merge pull request #87 from volcengine/feat/optRdsMysql
Browse files Browse the repository at this point in the history
Feat/opt rds mysql
  • Loading branch information
xuyaming0800 authored Apr 27, 2023
2 parents f34f22f + 2050c28 commit 33cd2b1
Show file tree
Hide file tree
Showing 34 changed files with 174 additions and 25 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.71"
TerraformProviderVersion = "0.0.72"
)
34 changes: 30 additions & 4 deletions docgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ description: |-
---
# {{.name}}
{{.description}}
{{- if eq .hasPaid "true" }}
## Notice
When Destroy this resource,If the resource charge type is PrePaid,Please unsubscribe the resource
in [Volcengine Console](https://console.volcengine.com/finance/unsubscribe/),when complete console operation,yon can
use 'terraform state rm ${resourceId}' to remove.
{{- end }}
## Example Usage
{{.example}}
## Argument Reference
Expand Down Expand Up @@ -108,6 +114,12 @@ type Product struct {
ResourcePath string
DataSourceExample string
ResourceExample string
ResourceName string
}

var deprecatedMapping = map[string]string{
"rds": "Recommend use volcengine_rds_mysql_*** replace",
"rds_v2": "Recommend use volcengine_rds_mysql_*** replace",
}

var resourceKeys = map[string]string{
Expand Down Expand Up @@ -162,12 +174,12 @@ func main() {
// document for DataSources
if product.DataSource != "" {
_dataSource := cloudMark + "_" + product.DataSource
genDoc(pwd, product.Name, "data_source", product.DataSourcePath, _dataSource, provider.DataSourcesMap[_dataSource], product.DataSourceExample)
genDoc(pwd, product.ResourceName, product.Name, "data_source", product.DataSourcePath, _dataSource, provider.DataSourcesMap[_dataSource], product.DataSourceExample)
}

// document for Resources
_resource := cloudMark + "_" + product.Resource
genDoc(pwd, product.Name, "resource", product.ResourcePath, _resource, provider.ResourcesMap[_resource], product.ResourceExample)
genDoc(pwd, product.ResourceName, product.Name, "resource", product.ResourcePath, _resource, provider.ResourcesMap[_resource], product.ResourceExample)
}
}

Expand All @@ -185,7 +197,10 @@ func genIndex(pwd string) (prods []Product) {
fs1, _ := ioutil.ReadDir(p1)
for _, f1 := range fs1 {
if f1.IsDir() {
product := Product{Name: name}
product := Product{
Name: name,
ResourceName: file.Name(),
}
p2 := p1 + "/" + f1.Name()
fs2, _ := ioutil.ReadDir(p2)
for _, f2 := range fs2 {
Expand Down Expand Up @@ -284,7 +299,7 @@ func genIndex(pwd string) (prods []Product) {
}

// genDoc generating doc for data source and resource
func genDoc(pwd string, product, docType, filename, name string, resource *schema.Resource, example string) {
func genDoc(pwd string, resourceName, product, docType, filename, name string, resource *schema.Resource, example string) {
if resource == nil {
return
}
Expand All @@ -299,6 +314,7 @@ func genDoc(pwd string, product, docType, filename, name string, resource *schem
"description": "",
"description_short": "",
"import": "",
"hasPaid": "",
}

//filename := fmt.Sprintf("%s_%s_%s.go", docType, cloudMarkShort, data["resource"])
Expand Down Expand Up @@ -336,9 +352,16 @@ func genDoc(pwd string, product, docType, filename, name string, resource *schem
if docType == "resource" {
data["description"] = "Provides a resource to manage " + common.DownLineToSpace(data["resource"])
data["description_short"] = data["description"]
if s, ok := deprecatedMapping[resourceName]; ok {
data["description"] = "(Deprecated! " + s + ") " + data["description"]
}

} else {
data["description"] = "Use this data source to query detailed information of " + common.DownLineToSpace(data["resource"])
data["description_short"] = data["description"]
if s, ok := deprecatedMapping[resourceName]; ok {
data["description"] = "(Deprecated! " + s + ") " + data["description"]
}
}

var (
Expand All @@ -363,6 +386,9 @@ func genDoc(pwd string, product, docType, filename, name string, resource *schem
message("[FAIL!]Don't set Required and Optional at the same time: '%s'", k)
os.Exit(1)
}
if docType == "resource" && (strings.Contains(v.Description, "PostPaid") || strings.Contains(v.Description, "PrePaid")) {
data["hasPaid"] = "true"
}
if v.Required {
opt := "Required"
if v.ForceNew {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/hashicorp/hcl/v2 v2.0.0
github.com/hashicorp/terraform-plugin-sdk v1.7.0
github.com/stretchr/testify v1.7.0
github.com/volcengine/volcengine-go-sdk v1.0.3
github.com/volcengine/volcengine-go-sdk v1.0.75
golang.org/x/sync v0.0.0-20190423024810-112230192c58
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
)
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ func ResourceVolcengineRdsMysqlInstance() *schema.Resource {
"PostPaid",
"PrePaid",
}, false),
Description: "Payment type. Value:\nPostPaid - Pay-As-You-Go\nPrePaid - Yearly and monthly (default).",
Description: "Payment type. Value:\nPostPaid - Pay-As-You-Go\nPrePaid - Yearly and monthly (default). \n" +
"When the value of this field is `PrePaid`, the mysql instance cannot be deleted through terraform. Please unsubscribe the instance from the Volcengine console first, and then use `terraform state rm volcengine_rds_mysql_instance.resource_name` command to remove it from terraform state file and management.",
},
"auto_renew": {
Type: schema.TypeBool,
Expand All @@ -119,6 +120,7 @@ func ResourceVolcengineRdsMysqlInstance() *schema.Resource {
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"Month", "Year"}, false),
DiffSuppressFunc: RdsMysqlInstanceImportDiffSuppress,
Description: "The purchase cycle in the prepaid scenario.\nMonth - monthly subscription (default)\nYear - Package year.",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,13 @@ func (s *VolcengineRdsMysqlInstanceService) ModifyResource(resourceData *schema.
func (s *VolcengineRdsMysqlInstanceService) RemoveResource(resourceData *schema.ResourceData, r *schema.Resource) []ve.Callback {
var callbacks []ve.Callback

// 删除包年包月实例时报错
if chargeType := resourceData.Get("charge_info.0.charge_type"); chargeType.(string) == "PrePaid" {
return []ve.Callback{{
Err: fmt.Errorf("can not delete PrePaid mysql instance"),
}}
}

// 1. Disassociate Allow List
allowListCallback := ve.Callback{
Call: ve.SdkCall{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,41 @@ func DataSourceVolcengineVpnConnections() *schema.Resource {
Computed: true,
Description: "The IPsec attach type.",
},
"ip_address": {
Type: schema.TypeString,
Computed: true,
Description: "The ip address of transit router, valid when the attach type is 'TransitRouter'.",
},
"transit_router_id": {
Type: schema.TypeString,
Computed: true,
Description: "The id of transit router, valid when the attach type is 'TransitRouter'.",
},
"zone_id": {
Type: schema.TypeString,
Computed: true,
Description: "The zone id of transit router, valid when the attach type is 'TransitRouter'.",
},
"business_status": {
Type: schema.TypeString,
Computed: true,
Description: "The business status of IPsec connection, valid when the attach type is 'TransitRouter'.",
},
"deleted_time": {
Type: schema.TypeString,
Computed: true,
Description: "The delete time of resource, valid when the attach type is 'TransitRouter'.",
},
"overdue_time": {
Type: schema.TypeString,
Computed: true,
Description: "The overdue time of resource, valid when the attach type is 'TransitRouter'.",
},
"log_enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "Whether to enable the connection log.",
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func ResourceVolcengineVpnConnection() *schema.Resource {
},
"vpn_gateway_id": {
Type: schema.TypeString,
Required: true,
Optional: true,
ForceNew: true,
Description: "The ID of the vpn gateway.",
},
Expand Down
24 changes: 22 additions & 2 deletions volcengine/vpn/vpn_connection/service_volcengine_vpn_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,21 @@ func (s *VolcengineVpnConnectionService) RefreshResourceState(resourceData *sche
failStates []string
)
failStates = append(failStates, "Error")
demo, err = s.ReadResource(resourceData, id)
if err != nil {

if err = resource.Retry(20*time.Minute, func() *resource.RetryError {
demo, err = s.ReadResource(resourceData, id)
if err != nil {
if ve.ResourceNotFoundError(err) {
return resource.RetryableError(err)
} else {
return resource.NonRetryableError(err)
}
}
return nil
}); err != nil {
return nil, "", err
}

status, err = ve.ObtainSdkValue("Status", demo)
if err != nil {
return nil, "", err
Expand Down Expand Up @@ -284,6 +295,9 @@ func (s *VolcengineVpnConnectionService) CreateResource(resourceData *schema.Res
Target: []string{"Available"},
Timeout: resourceData.Timeout(schema.TimeoutCreate),
},
LockId: func(d *schema.ResourceData) string {
return d.Get("customer_gateway_id").(string)
},
},
}
callbacks = append(callbacks, createVpnConnection)
Expand Down Expand Up @@ -385,6 +399,9 @@ func (s *VolcengineVpnConnectionService) ModifyResource(resourceData *schema.Res
logger.Debug(logger.RespFormat, call.Action, call.SdkParam)
return s.Client.UniversalClient.DoCall(getUniversalInfo(call.Action), call.SdkParam)
},
LockId: func(d *schema.ResourceData) string {
return d.Get("customer_gateway_id").(string)
},
},
}
callbacks = append(callbacks, modifyCallback)
Expand Down Expand Up @@ -426,6 +443,9 @@ func (s *VolcengineVpnConnectionService) RemoveResource(resourceData *schema.Res
AfterCall: func(d *schema.ResourceData, client *ve.SdkClient, resp *map[string]interface{}, call ve.SdkCall) error {
return ve.CheckResourceUtilRemoved(d, s.ReadResource, 5*time.Minute)
},
LockId: func(d *schema.ResourceData) string {
return d.Get("customer_gateway_id").(string)
},
},
}
return []ve.Callback{callback}
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/rds_accounts.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: |-
Use this data source to query detailed information of rds accounts
---
# volcengine_rds_accounts
Use this data source to query detailed information of rds accounts
(Deprecated! Recommend use volcengine_rds_mysql_*** replace) Use this data source to query detailed information of rds accounts
## Example Usage
```hcl
data "volcengine_rds_accounts" "default" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/rds_databases.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: |-
Use this data source to query detailed information of rds databases
---
# volcengine_rds_databases
Use this data source to query detailed information of rds databases
(Deprecated! Recommend use volcengine_rds_mysql_*** replace) Use this data source to query detailed information of rds databases
## Example Usage
```hcl
data "volcengine_rds_databases" "default" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/rds_instances.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: |-
Use this data source to query detailed information of rds instances
---
# volcengine_rds_instances
Use this data source to query detailed information of rds instances
(Deprecated! Recommend use volcengine_rds_mysql_*** replace) Use this data source to query detailed information of rds instances
## Example Usage
```hcl
data "volcengine_rds_instances" "default" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/rds_instances_v2.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: |-
Use this data source to query detailed information of rds instances v2
---
# volcengine_rds_instances_v2
Use this data source to query detailed information of rds instances v2
(Deprecated! Recommend use volcengine_rds_mysql_*** replace) Use this data source to query detailed information of rds instances v2
## Example Usage
```hcl
data "volcengine_rds_instances_v2" "default" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/rds_ip_lists.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: |-
Use this data source to query detailed information of rds ip lists
---
# volcengine_rds_ip_lists
Use this data source to query detailed information of rds ip lists
(Deprecated! Recommend use volcengine_rds_mysql_*** replace) Use this data source to query detailed information of rds ip lists
## Example Usage
```hcl
data "volcengine_rds_ip_lists" "default" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/rds_parameter_templates.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: |-
Use this data source to query detailed information of rds parameter templates
---
# volcengine_rds_parameter_templates
Use this data source to query detailed information of rds parameter templates
(Deprecated! Recommend use volcengine_rds_mysql_*** replace) Use this data source to query detailed information of rds parameter templates
## Example Usage
```hcl
data "volcengine_rds_parameter_templates" "default" {
Expand Down
7 changes: 7 additions & 0 deletions website/docs/d/vpn_connections.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ In addition to all arguments above, the following attributes are exported:
* `account_id` - The account ID of the VPN connection.
* `attach_status` - The IPsec attach status.
* `attach_type` - The IPsec attach type.
* `business_status` - The business status of IPsec connection, valid when the attach type is 'TransitRouter'.
* `connect_status` - The connect status of the VPN connection.
* `creation_time` - The create time of VPN connection.
* `customer_gateway_id` - The ID of the customer gateway.
* `deleted_time` - The delete time of resource, valid when the attach type is 'TransitRouter'.
* `description` - The description of the VPN connection.
* `dpd_action` - The dpd action of the VPN connection.
* `id` - The ID of the VPN connection.
Expand All @@ -45,18 +47,23 @@ In addition to all arguments above, the following attributes are exported:
* `ike_config_psk` - The psk of the ike config of the VPN connection.
* `ike_config_remote_id` - The remote id of the ike config of the VPN connection.
* `ike_config_version` - The version of the ike config of the VPN connection.
* `ip_address` - The ip address of transit router, valid when the attach type is 'TransitRouter'.
* `ipsec_config_auth_alg` - The auth alg of the ipsec config of the VPN connection.
* `ipsec_config_dh_group` - The dh group of the ipsec config of the VPN connection.
* `ipsec_config_enc_alg` - The enc alg of the ipsec config of the VPN connection.
* `ipsec_config_lifetime` - The lifetime of the ike config of the VPN connection.
* `local_subnet` - The local subnet of the VPN connection.
* `log_enabled` - Whether to enable the connection log.
* `nat_traversal` - The nat traversal of the VPN connection.
* `negotiate_instantly` - Whether to initiate negotiation mode immediately.
* `overdue_time` - The overdue time of resource, valid when the attach type is 'TransitRouter'.
* `remote_subnet` - The remote subnet of the VPN connection.
* `status` - The status of the VPN connection.
* `transit_router_id` - The id of transit router, valid when the attach type is 'TransitRouter'.
* `update_time` - The update time of VPN connection.
* `vpn_connection_id` - The ID of the VPN connection.
* `vpn_connection_name` - The name of the VPN connection.
* `vpn_gateway_id` - The ID of the vpn gateway.
* `zone_id` - The zone id of transit router, valid when the attach type is 'TransitRouter'.


4 changes: 4 additions & 0 deletions website/docs/r/cen_bandwidth_package.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ description: |-
---
# volcengine_cen_bandwidth_package
Provides a resource to manage cen bandwidth package
## Notice
When Destroy this resource,If the resource charge type is PrePaid,Please unsubscribe the resource
in [Volcengine Console](https://console.volcengine.com/finance/unsubscribe/),when complete console operation,yon can
use 'terraform state rm ${resourceId}' to remove.
## Example Usage
```hcl
resource "volcengine_cen_bandwidth_package" "foo" {
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/clb.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ description: |-
---
# volcengine_clb
Provides a resource to manage clb
## Notice
When Destroy this resource,If the resource charge type is PrePaid,Please unsubscribe the resource
in [Volcengine Console](https://console.volcengine.com/finance/unsubscribe/),when complete console operation,yon can
use 'terraform state rm ${resourceId}' to remove.
## Example Usage
```hcl
resource "volcengine_clb" "foo" {
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/ecs_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ description: |-
---
# volcengine_ecs_instance
Provides a resource to manage ecs instance
## Notice
When Destroy this resource,If the resource charge type is PrePaid,Please unsubscribe the resource
in [Volcengine Console](https://console.volcengine.com/finance/unsubscribe/),when complete console operation,yon can
use 'terraform state rm ${resourceId}' to remove.
## Example Usage
```hcl
resource "volcengine_vpc" "foo" {
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/eip_address.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ description: |-
---
# volcengine_eip_address
Provides a resource to manage eip address
## Notice
When Destroy this resource,If the resource charge type is PrePaid,Please unsubscribe the resource
in [Volcengine Console](https://console.volcengine.com/finance/unsubscribe/),when complete console operation,yon can
use 'terraform state rm ${resourceId}' to remove.
## Example Usage
```hcl
resource "volcengine_eip_address" "foo" {
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/mongodb_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ description: |-
---
# volcengine_mongodb_instance
Provides a resource to manage mongodb instance
## Notice
When Destroy this resource,If the resource charge type is PrePaid,Please unsubscribe the resource
in [Volcengine Console](https://console.volcengine.com/finance/unsubscribe/),when complete console operation,yon can
use 'terraform state rm ${resourceId}' to remove.
## Example Usage
```hcl
resource "volcengine_mongodb_instance" "foo" {
Expand Down
Loading

0 comments on commit 33cd2b1

Please sign in to comment.