Skip to content

Commit a583d64

Browse files
committed
feat: updating schema for regions and databases for active-active datasource
1 parent cb485f3 commit a583d64

File tree

3 files changed

+60
-23
lines changed

3 files changed

+60
-23
lines changed

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
44
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
55
github.com/ProtonMail/go-crypto v1.1.0-alpha.2 h1:bkyFVUP+ROOARdgCiJzNQo2V2kiB97LyUpzH9P6Hrlg=
66
github.com/ProtonMail/go-crypto v1.1.0-alpha.2/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
7+
github.com/RedisLabs/rediscloud-go-api v0.22.0/go.mod h1:3/oVb71rv2OstFRYEc65QCIbfwnJTgZeQhtPCcdHook=
78
github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE=
89
github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
910
github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec=

provider/datasource_rediscloud_active_active_subscription_regions.go

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,72 @@ package provider
33
import (
44
"context"
55
"github.com/RedisLabs/rediscloud-go-api/redis"
6-
"github.com/RedisLabs/rediscloud-go-api/service/cloud_accounts"
76
"github.com/RedisLabs/rediscloud-go-api/service/subscriptions"
87
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
98
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
119
)
1210

1311
func dataSourceRedisCloudActiveActiveSubscriptionRegions() *schema.Resource {
1412
return &schema.Resource{
15-
Description: "The Active Active Subscription Regions data source allows access to a list of supported cloud provider regions. These regions can be used with the active active subscription resource.",
13+
Description: "Gets a list of regions in the specified Active-Active subscription.",
1614
ReadContext: dataSourceRedisCloudActiveActiveRegionsRead,
1715

1816
Schema: map[string]*schema.Schema{
19-
"subscription_id": {
20-
Description: "The name of the cloud provider to filter returned regions, (accepted values are `AWS` or `GCP`).",
21-
Optional: true,
22-
Type: schema.TypeString,
23-
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice(cloud_accounts.ProviderValues(), false)),
24-
},
25-
"provider_name": {
26-
Description: "The name of the cloud provider to filter returned regions, (accepted values are `AWS` or `GCP`).",
27-
Optional: true,
28-
Type: schema.TypeString,
29-
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice(cloud_accounts.ProviderValues(), false)),
17+
"subscription_name": {
18+
Description: "The name of the subscription",
19+
Type: schema.TypeString,
20+
Required: true,
3021
},
3122
"regions": {
32-
Description: "A list of regions from either a single or multiple cloud providers",
23+
Description: "A list of regions from an active active subscription",
3324
Type: schema.TypeSet,
3425
Computed: true,
3526
Elem: &schema.Resource{
3627
Schema: map[string]*schema.Schema{
37-
"name": {
38-
Description: "The identifier assigned by the cloud provider, (for example `eu-west-1` for `AWS`)",
28+
"region": {
29+
Description: "Deployment region as defined by cloud provider",
30+
Type: schema.TypeString,
3931
Computed: true,
32+
},
33+
"networking_deployment_cidr": {
34+
Description: "Deployment CIDR mask",
4035
Type: schema.TypeString,
36+
Computed: true,
4137
},
42-
"provider_name": {
43-
Description: "The identifier of the owning cloud provider, (either `AWS` or `GCP`)",
38+
"vpc_id": {
39+
Description: "VPC ID for the region",
4440
Computed: true,
4541
Type: schema.TypeString,
4642
},
43+
"databases": {
44+
Description: "A list of databases found in the region",
45+
Computed: true,
46+
Type: schema.TypeList,
47+
Elem: &schema.Resource{
48+
Schema: map[string]*schema.Schema{
49+
"database_id": {
50+
Description: "A numeric id for the database",
51+
Type: schema.TypeInt,
52+
Required: true,
53+
},
54+
"database_name": {
55+
Description: "A meaningful name to identify the database",
56+
Type: schema.TypeString,
57+
Required: true,
58+
},
59+
"write_operations_per_second": {
60+
Description: "Write operations per second for the database",
61+
Type: schema.TypeInt,
62+
Required: true,
63+
},
64+
"read_operations_per_second": {
65+
Description: "Read operations per second for the database",
66+
Type: schema.TypeInt,
67+
Required: true,
68+
},
69+
},
70+
},
71+
},
4772
},
4873
},
4974
},
@@ -68,7 +93,8 @@ func dataSourceRedisCloudActiveActiveRegionsRead(ctx context.Context, d *schema.
6893
return redis.StringValue(sub.DeploymentType) == "active-active"
6994
})
7095

71-
if name, ok := d.GetOk("name"); ok {
96+
// Filter down to requested subscription by name
97+
if name, ok := d.GetOk("subscription_name"); ok {
7298
filters = append(filters, func(sub *subscriptions.Subscription) bool {
7399
return redis.StringValue(sub.Name) == name
74100
})
@@ -88,10 +114,19 @@ func dataSourceRedisCloudActiveActiveRegionsRead(ctx context.Context, d *schema.
88114

89115
regions, err := api.client.Subscription.ListActiveActiveRegions(ctx, *sub.ID)
90116

117+
if err != nil {
118+
return diag.FromErr(err)
119+
}
120+
91121
if len(regions) == 0 {
92122
return diag.Errorf("Your query returned no results. Please change your search criteria and try again.")
93123
}
94124

95-
return diags
125+
// TODO: may have to manipulate regions to be output in a friendly way here
96126

127+
if err := d.Set("regions", regions); err != nil {
128+
return diag.FromErr(err)
129+
}
130+
131+
return diags
97132
}

provider/rediscloud_active_active_subscription_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func TestAccResourceRedisCloudActiveActiveSubscription_CRUDI(t *testing.T) {
2626
name := acctest.RandomWithPrefix(testResourcePrefix)
2727
const resourceName = "rediscloud_active_active_subscription.example"
2828
const datasourceName = "data.rediscloud_active_active_subscription.example"
29+
const datasourceRegion = "data.rediscloud_active_active_subscription_region.regions"
2930

3031
var subId int
3132

@@ -370,8 +371,8 @@ data "rediscloud_active_active_subscription" "example" {
370371
name = rediscloud_active_active_subscription.example.name
371372
}
372373
373-
data "redis_active_active_subscription_regions" "regions" {
374-
subscription_id = rediscloud_active_active_subscription.example.id
374+
data "rediscloud_active_active_subscription_regions" "regions" {
375+
subscription_name = rediscloud_active_active_subscription.example.name
375376
}
376377
`
377378

0 commit comments

Comments
 (0)