@@ -3,47 +3,72 @@ package provider
33import (
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
1311func 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}
0 commit comments