Skip to content

Commit

Permalink
Merge pull request #91 from volcengine/feat/redis
Browse files Browse the repository at this point in the history
feat: add support for redis
  • Loading branch information
zpp12354321 authored May 26, 2023
2 parents 8a7632b + 84edae4 commit 92db18c
Show file tree
Hide file tree
Showing 67 changed files with 5,707 additions and 3 deletions.
3 changes: 2 additions & 1 deletion common/common_volcengine_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ func ResourceNotFoundError(err error) bool {
strings.Contains(errMessage, "not exist") ||
strings.Contains(errMessage, "not associate") ||
strings.Contains(errMessage, "invalid") ||
strings.Contains(errMessage, "not_found") {
strings.Contains(errMessage, "not_found") ||
strings.Contains(errMessage, "notexist") {
return true
}
return false
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.74"
TerraformProviderVersion = "0.0.75"
)
1 change: 1 addition & 0 deletions docgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ var resourceKeys = map[string]string{
"bioos": "BIOOS",
"rds_mysql": "RDS_MYSQL",
"privatelink": "PRIVATELINK",
"redis": "REDIS",
}

type Products struct {
Expand Down
3 changes: 3 additions & 0 deletions example/dataRedisAccounts/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "volcengine_redis_accounts" "default" {
instance_id = "redis-cn0398aizj8cwmopx"
}
3 changes: 3 additions & 0 deletions example/dataRedisAllowLists/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "volcengine_redis_allow_lists" "default" {
region_id = "cn-beijing"
}
4 changes: 4 additions & 0 deletions example/dataRedisBackups/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
data "volcengine_redis_backups" "default" {
instance_id = "redis-cnlfvrv4qye6u4lpa"
backup_strategy_list = ["ManualBackup"]
}
3 changes: 3 additions & 0 deletions example/dataRedisDBInstances/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "volcengine_redis_instances" "default"{
instance_id = "redis-cnlf2lh1kksvv****"
}
3 changes: 3 additions & 0 deletions example/dataRedisPitrTimeWindows/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "volcengine_redis_pitr_time_windows" "default" {
ids = ["redis-cnlficlt4974swtbz", "redis-cnlfq69d1y1tnguxz"]
}
3 changes: 3 additions & 0 deletions example/dataRedisRegions/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "volcengine_redis_regions" "default"{
region_id="cn-north-3"
}
3 changes: 3 additions & 0 deletions example/dataRedisZones/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "volcengine_redis_zones" "default"{
region_id="cn-north-3"
}
7 changes: 7 additions & 0 deletions example/redisAccount/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "volcengine_redis_account" "foo" {
instance_id = "redis-cn0398aizj8cwmopx"
account_name = "test"
password = "1qaz!QAZ"
role_name = "ReadOnly"
description = "test12345"
}
5 changes: 5 additions & 0 deletions example/redisAllowList/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "volcengine_redis_allow_list" "foo" {
allow_list_name = "rx_test_tf_allowlist_create"
allow_list = ["0.0.0.0/0", "192.168.0.0/24", "192.168.1.1", "192.168.2.22"]
allow_list_desc = "renxin terraform测试白xxxxxxx"
}
9 changes: 9 additions & 0 deletions example/redisAllowListAssociate/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "volcengine_redis_allow_list_associate" "default" {
instance_id = "redis-cnlfbzifs7bpvundz"
allow_list_id = "acl-cnlfc5zsxscu1gg2ajh"
}

resource "volcengine_redis_allow_list_associate" "default1" {
instance_id = "redis-cnlfbzifs7bpvundz"
allow_list_id = "acl-cnlff2mb31zo85p5am7"
}
3 changes: 3 additions & 0 deletions example/redisBackup/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "volcengine_redis_backup" "default" {
instance_id = "redis-cnlfvrv4qye6u4lpa"
}
4 changes: 4 additions & 0 deletions example/redisBackupRestore/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "volcengine_redis_backup_restore" "default" {
instance_id = "redis-cnlfvrv4qye6u4lpa"
time_point = "2023-04-14T02:51:51Z"
}
3 changes: 3 additions & 0 deletions example/redisContinuousBackup/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "volcengine_redis_continuous_backup" "foo" {
instance_id = "redis-cnlficlt4974s****"
}
42 changes: 42 additions & 0 deletions example/redisDBInstance/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
resource "volcengine_redis_instance" "foo"{
zone_ids = ["cn-beijing-a", "cn-beijing-b"]
instance_name = "tf-test"
sharded_cluster = 1
password = "1qaz!QAZ12"
node_number = 2
shard_capacity = 1024
shard_number = 2
engine_version = "5.0"
subnet_id = "subnet-13g7c3lot0lc03n6nu4wj****"
deletion_protection = "disabled"
vpc_auth_mode = "close"
charge_type = "PostPaid"
# purchase_months = 1
# auto_renew = false
port = 6381
project_name = "default"
tags {
key = "k1"
value = "v1"
}
tags {
key = "k3"
value = "v3"
}

param_values{
name = "active-defrag-cycle-min"
value = "5"
}
param_values{
name = "active-defrag-cycle-max"
value = "28"
}

backup_period = [1, 2, 3]
backup_hour = 4
backup_active = true

create_backup = false
apply_immediately = true
}
4 changes: 4 additions & 0 deletions example/redisEndpoint/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "volcengine_redis_endpoint" "foo" {
instance_id = "redis-cn03bb67g3tr2****"
eip_id = "eip-274ho3mtx543k7fap8tyi****"
}
4 changes: 4 additions & 0 deletions example/redisInstanceState/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "volcengine_redis_instance_state" "foo" {
action = "Restart"
instance_id = "redis-cnlficlt4974swtbz"
}
35 changes: 34 additions & 1 deletion volcengine/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package volcengine
import (
"strings"

"github.com/volcengine/terraform-provider-volcengine/volcengine/rds/rds_parameter_template"
"github.com/volcengine/terraform-provider-volcengine/volcengine/redis/instance_state"
"github.com/volcengine/terraform-provider-volcengine/volcengine/redis/pitr_time_period"

"github.com/volcengine/terraform-provider-volcengine/volcengine/mongodb/ssl_state"
"github.com/volcengine/terraform-provider-volcengine/volcengine/tos/bucket_policy"

Expand Down Expand Up @@ -98,12 +102,21 @@ import (
"github.com/volcengine/terraform-provider-volcengine/volcengine/rds/rds_database"
"github.com/volcengine/terraform-provider-volcengine/volcengine/rds/rds_instance"
"github.com/volcengine/terraform-provider-volcengine/volcengine/rds/rds_ip_list"
"github.com/volcengine/terraform-provider-volcengine/volcengine/rds/rds_parameter_template"
"github.com/volcengine/terraform-provider-volcengine/volcengine/rds_mysql/allowlist"
"github.com/volcengine/terraform-provider-volcengine/volcengine/rds_mysql/allowlist_associate"
"github.com/volcengine/terraform-provider-volcengine/volcengine/rds_mysql/rds_mysql_instance"
"github.com/volcengine/terraform-provider-volcengine/volcengine/rds_mysql/rds_mysql_instance_readonly_node"
"github.com/volcengine/terraform-provider-volcengine/volcengine/rds_v2/rds_instance_v2"
redisAccount "github.com/volcengine/terraform-provider-volcengine/volcengine/redis/account"
redis_allow_list "github.com/volcengine/terraform-provider-volcengine/volcengine/redis/allow_list"
redis_allow_list_associate "github.com/volcengine/terraform-provider-volcengine/volcengine/redis/allow_list_associate"
redis_backup "github.com/volcengine/terraform-provider-volcengine/volcengine/redis/backup"
redis_backup_restore "github.com/volcengine/terraform-provider-volcengine/volcengine/redis/backup_restore"
redisContinuousBackup "github.com/volcengine/terraform-provider-volcengine/volcengine/redis/continuous_backup"
redis_endpoint "github.com/volcengine/terraform-provider-volcengine/volcengine/redis/endpoint"
redisInstance "github.com/volcengine/terraform-provider-volcengine/volcengine/redis/instance"
redisRegion "github.com/volcengine/terraform-provider-volcengine/volcengine/redis/region"
redisZone "github.com/volcengine/terraform-provider-volcengine/volcengine/redis/zone"
"github.com/volcengine/terraform-provider-volcengine/volcengine/tos/bucket"
"github.com/volcengine/terraform-provider-volcengine/volcengine/tos/object"
"github.com/volcengine/terraform-provider-volcengine/volcengine/veenedge/available_resource"
Expand Down Expand Up @@ -288,6 +301,15 @@ func Provider() terraform.ResourceProvider {
"volcengine_tos_buckets": bucket.DataSourceVolcengineTosBuckets(),
"volcengine_tos_objects": object.DataSourceVolcengineTosObjects(),

// ================ Redis =============
"volcengine_redis_allow_lists": redis_allow_list.DataSourceVolcengineRedisAllowLists(),
"volcengine_redis_backups": redis_backup.DataSourceVolcengineRedisBackups(),
"volcengine_redis_regions": redisRegion.DataSourceVolcengineRedisRegions(),
"volcengine_redis_zones": redisZone.DataSourceVolcengineRedisZones(),
"volcengine_redis_accounts": redisAccount.DataSourceVolcengineRedisAccounts(),
"volcengine_redis_instances": redisInstance.DataSourceVolcengineRedisDbInstances(),
"volcengine_redis_pitr_time_windows": pitr_time_period.DataSourceVolcengineRedisPitrTimeWindows(),

// ================ CR ================
"volcengine_cr_registries": cr_registry.DataSourceVolcengineCrRegistries(),
"volcengine_cr_namespaces": cr_namespace.DataSourceVolcengineCrNamespaces(),
Expand Down Expand Up @@ -441,6 +463,17 @@ func Provider() terraform.ResourceProvider {
"volcengine_tos_object": object.ResourceVolcengineTosObject(),
"volcengine_tos_bucket_policy": bucket_policy.ResourceVolcengineTosBucketPolicy(),

// ================ Redis ==============
"volcengine_redis_allow_list": redis_allow_list.ResourceVolcengineRedisAllowList(),
"volcengine_redis_endpoint": redis_endpoint.ResourceVolcengineRedisEndpoint(),
"volcengine_redis_allow_list_associate": redis_allow_list_associate.ResourceVolcengineRedisAllowListAssociate(),
"volcengine_redis_backup": redis_backup.ResourceVolcengineRedisBackup(),
"volcengine_redis_backup_restore": redis_backup_restore.ResourceVolcengineRedisBackupRestore(),
"volcengine_redis_account": redisAccount.ResourceVolcengineRedisAccount(),
"volcengine_redis_instance": redisInstance.ResourceVolcengineRedisDbInstance(),
"volcengine_redis_instance_state": instance_state.ResourceVolcengineRedisInstanceState(),
"volcengine_redis_continuous_backup": redisContinuousBackup.ResourceVolcengineRedisContinuousBackup(),

// ================ CR ================
"volcengine_cr_registry": cr_registry.ResourceVolcengineCrRegistry(),
"volcengine_cr_registry_state": cr_registry_state.ResourceVolcengineCrRegistryState(),
Expand Down
68 changes: 68 additions & 0 deletions volcengine/redis/account/data_source_volcengine_redis_accounts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package account

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
volc "github.com/volcengine/terraform-provider-volcengine/common"
)

func DataSourceVolcengineRedisAccounts() *schema.Resource {
return &schema.Resource{
Read: dataSourceVolcengineRedisAccountsRead,
Schema: map[string]*schema.Schema{
"output_file": {
Type: schema.TypeString,
Optional: true,
Description: "File name where to save data source results.",
},
"total_count": {
Type: schema.TypeInt,
Computed: true,
Description: "The total count of redis accounts query.",
},
"instance_id": {
Type: schema.TypeString,
Required: true,
Description: "The id of the Redis instance.",
},
"account_name": {
Type: schema.TypeString,
Optional: true,
Description: "The name of the redis account.",
},
"accounts": {
Description: "The collection of redis instance account query.",
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"account_name": {
Type: schema.TypeString,
Computed: true,
Description: "The name of the redis account.",
},
"instance_id": {
Type: schema.TypeString,
Computed: true,
Description: "The id of instance.",
},
"role_name": {
Type: schema.TypeString,
Computed: true,
Description: "The role info.",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "The description of the redis account.",
},
},
},
},
},
}
}

func dataSourceVolcengineRedisAccountsRead(d *schema.ResourceData, meta interface{}) error {
redisAccountService := NewAccountService(meta.(*volc.SdkClient))
return volc.DefaultDispatcher().Data(redisAccountService, d, DataSourceVolcengineRedisAccounts())
}
Loading

0 comments on commit 92db18c

Please sign in to comment.