-
Notifications
You must be signed in to change notification settings - Fork 10
/
resource_volcengine_rds_account.go
89 lines (80 loc) · 3.5 KB
/
resource_volcengine_rds_account.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package rds_account
import (
"fmt"
"time"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
volc "github.com/volcengine/terraform-provider-volcengine/common"
)
/*
Import
RDS account can be imported using the id, e.g.
```
$ terraform import volcengine_rds_account.default mysql-42b38c769c4b:test
```
*/
func ResourceVolcengineRdsAccount() *schema.Resource {
return &schema.Resource{
Create: resourceVolcengineRdsAccountCreate,
Read: resourceVolcengineRdsAccountRead,
Delete: resourceVolcengineRdsAccountDelete,
Importer: &schema.ResourceImporter{
State: rdsAccountImporter,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(30 * time.Minute),
Delete: schema.DefaultTimeout(30 * time.Minute),
},
Schema: map[string]*schema.Schema{
"instance_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The ID of the RDS instance.",
},
"account_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Database account name. The rules are as follows:\nUnique name.\nStart with a letter and end with a letter or number.\nConsists of lowercase letters, numbers, or underscores (_).\nThe length is 2~32 characters.\nThe [keyword list](https://www.volcengine.com/docs/6313/66162) is disabled for database accounts, and certain reserved words, including root, admin, etc., cannot be used.",
},
"account_password": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The password of the database account.\nillustrate\nCannot start with `!` or `@`.\nThe length is 8~32 characters.\nIt consists of any three of uppercase letters, lowercase letters, numbers, and special characters.\nThe special characters are `!@#$%^*()_+-=`. When importing resources, this attribute will not be imported. If this attribute is set, please use lifecycle and ignore_changes ignore changes in fields.",
},
"account_type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Database account type, value:\nSuper: A high-privilege account. Only one database account can be created for an instance.\nNormal: An account with ordinary privileges.",
ValidateFunc: validation.StringInSlice([]string{"Super", "Normal"}, false),
},
},
}
}
func resourceVolcengineRdsAccountCreate(d *schema.ResourceData, meta interface{}) (err error) {
rdsAccountService := NewRdsAccountService(meta.(*volc.SdkClient))
err = volc.DefaultDispatcher().Create(rdsAccountService, d, ResourceVolcengineRdsAccount())
if err != nil {
return fmt.Errorf("error on creating rds account %q, %w", d.Id(), err)
}
return resourceVolcengineRdsAccountRead(d, meta)
}
func resourceVolcengineRdsAccountRead(d *schema.ResourceData, meta interface{}) (err error) {
rdsAccountService := NewRdsAccountService(meta.(*volc.SdkClient))
err = volc.DefaultDispatcher().Read(rdsAccountService, d, ResourceVolcengineRdsAccount())
if err != nil {
return fmt.Errorf("error on reading rds account %q, %w", d.Id(), err)
}
return err
}
func resourceVolcengineRdsAccountDelete(d *schema.ResourceData, meta interface{}) (err error) {
rdsAccountService := NewRdsAccountService(meta.(*volc.SdkClient))
err = volc.DefaultDispatcher().Delete(rdsAccountService, d, ResourceVolcengineRdsAccount())
if err != nil {
return fmt.Errorf("error on deleting rds account %q, %w", d.Id(), err)
}
return err
}