Skip to content

Commit 31e047e

Browse files
Merge pull request #618 from RedisLabs/develop
2.1.3
2 parents de545cd + 6964cb7 commit 31e047e

10 files changed

+425
-180
lines changed

.github/workflows/terraform_provider_pr.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ jobs:
140140

141141
go_test_smoke_misc:
142142
name: go test smoke misc
143-
needs: [go_build]
143+
needs: [ go_build ]
144144
runs-on: ubuntu-latest
145145
steps:
146146
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -149,18 +149,17 @@ jobs:
149149
go-version-file: go.mod
150150
- run: EXECUTE_TESTS=true make testacc TESTARGS='-run="TestAccResourceRedisCloud(PrivateServiceConnect_CRUDI|AclRule_CRUDI)"'
151151

152-
# TODO: remove this after release
153-
# qpf = query performance factor
154-
go_test_smoke_qpf:
155-
name: go test smoke qpf
156-
needs: [ go_build ]
152+
# TODO: remove, temporary: tests the subscription regions
153+
go_test_smoke_aa_sub_regions:
154+
name: go test smoke aa sub regions
155+
needs: [go_build]
157156
runs-on: ubuntu-latest
158157
steps:
159158
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
160159
- uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
161160
with:
162161
go-version-file: go.mod
163-
- run: EXECUTE_TESTS=true make testacc TESTARGS='-run="TestAccResourceRedisCloudProDatabase_qpf.*"'
162+
- run: EXECUTE_TESTS=true make testacc TESTARGS='-run="TestAccResourceRedisCloudActiveActiveSubscriptionRegions_CRUDI"'
164163

165164
tfproviderlint:
166165
name: tfproviderlint

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/RedisLabs/terraform-provider-rediscloud
33
go 1.22.4
44

55
require (
6-
github.com/RedisLabs/rediscloud-go-api v0.25.0
6+
github.com/RedisLabs/rediscloud-go-api v0.26.0
77
github.com/bflad/tfproviderlint v0.31.0
88
github.com/hashicorp/go-cty v1.5.0
99
github.com/hashicorp/terraform-plugin-sdk/v2 v2.36.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ 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.3 h1:nRBOetoydLeUb4nHajyO2bKqMLfWQ/ZPwkXqXxPxCFk=
66
github.com/ProtonMail/go-crypto v1.1.3/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
7-
github.com/RedisLabs/rediscloud-go-api v0.25.0 h1:44q7fPxjkS94slkUxZCueaDB5i+axxjkFqOXIx3D44M=
8-
github.com/RedisLabs/rediscloud-go-api v0.25.0/go.mod h1:3/oVb71rv2OstFRYEc65QCIbfwnJTgZeQhtPCcdHook=
7+
github.com/RedisLabs/rediscloud-go-api v0.26.0 h1:ka6CN2O+Ti6igkfH8lDT9Ua1/ksEh2H5dj1GF/pnKKQ=
8+
github.com/RedisLabs/rediscloud-go-api v0.26.0/go.mod h1:3/oVb71rv2OstFRYEc65QCIbfwnJTgZeQhtPCcdHook=
99
github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE=
1010
github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
1111
github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec=

provider/datasource_rediscloud_active_active_subscription.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func dataSourceRedisCloudActiveActiveSubscriptionRead(ctx context.Context, d *sc
155155

156156
var filters []func(method *subscriptions.Subscription) bool
157157

158-
// Filter to AA subscriptions only (active-active subs) come from the same endpoint
158+
// Filter to AA subscriptions only (pro subs come from the same endpoint)
159159
filters = append(filters, func(sub *subscriptions.Subscription) bool {
160160
return redis.StringValue(sub.DeploymentType) == "active-active"
161161
})
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
package provider
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"github.com/RedisLabs/rediscloud-go-api/redis"
7+
"github.com/RedisLabs/rediscloud-go-api/service/subscriptions"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10+
)
11+
12+
func dataSourceRedisCloudActiveActiveSubscriptionRegions() *schema.Resource {
13+
return &schema.Resource{
14+
Description: "Gets a list of regions in the specified Active-Active subscription.",
15+
ReadContext: dataSourceRedisCloudActiveActiveRegionsRead,
16+
17+
Schema: map[string]*schema.Schema{
18+
"subscription_name": {
19+
Description: "The name of the subscription",
20+
Type: schema.TypeString,
21+
Required: true,
22+
},
23+
"regions": {
24+
Description: "A list of regions from an active active subscription",
25+
Type: schema.TypeList,
26+
Computed: true,
27+
Elem: &schema.Resource{
28+
Schema: map[string]*schema.Schema{
29+
"region": {
30+
Description: "Deployment region as defined by cloud provider",
31+
Type: schema.TypeString,
32+
Computed: true,
33+
},
34+
"networking_deployment_cidr": {
35+
Description: "Deployment CIDR mask",
36+
Type: schema.TypeString,
37+
Computed: true,
38+
},
39+
"vpc_id": {
40+
Description: "VPC ID for the region",
41+
Computed: true,
42+
Type: schema.TypeString,
43+
},
44+
"databases": {
45+
Description: "A list of databases found in the region",
46+
Computed: true,
47+
Type: schema.TypeList,
48+
Elem: &schema.Resource{
49+
Schema: map[string]*schema.Schema{
50+
"database_id": {
51+
Description: "A numeric id for the database",
52+
Type: schema.TypeInt,
53+
Computed: true,
54+
},
55+
"database_name": {
56+
Description: "A meaningful name to identify the database",
57+
Type: schema.TypeString,
58+
Computed: true,
59+
},
60+
"write_operations_per_second": {
61+
Description: "Write operations per second for the database",
62+
Type: schema.TypeInt,
63+
Computed: true,
64+
},
65+
"read_operations_per_second": {
66+
Description: "Read operations per second for the database",
67+
Type: schema.TypeInt,
68+
Computed: true,
69+
},
70+
},
71+
},
72+
},
73+
},
74+
},
75+
},
76+
},
77+
}
78+
}
79+
80+
func dataSourceRedisCloudActiveActiveRegionsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
81+
var diags diag.Diagnostics
82+
api := meta.(*apiClient)
83+
84+
subs, err := api.client.Subscription.List(ctx)
85+
86+
if err != nil {
87+
return diag.FromErr(err)
88+
}
89+
90+
var filters []func(method *subscriptions.Subscription) bool
91+
92+
// Filter to active-active subscriptions only (pro subs come from the same endpoint)
93+
filters = append(filters, func(sub *subscriptions.Subscription) bool {
94+
return redis.StringValue(sub.DeploymentType) == "active-active"
95+
})
96+
97+
// Filter down to requested subscription by name
98+
if name, ok := d.GetOk("subscription_name"); ok {
99+
filters = append(filters, func(sub *subscriptions.Subscription) bool {
100+
return redis.StringValue(sub.Name) == name
101+
})
102+
}
103+
104+
subs = filterSubscriptions(subs, filters)
105+
106+
if len(subs) == 0 {
107+
return diag.Errorf("Your query returned no results. Please change your search criteria and try again.")
108+
}
109+
110+
if len(subs) > 1 {
111+
return diag.Errorf("Your query returned more than one result. Please change try a more specific search criteria and try again.")
112+
}
113+
114+
sub := subs[0]
115+
116+
regions, err := api.client.Subscription.ListActiveActiveRegions(ctx, *sub.ID)
117+
118+
if err != nil {
119+
return diag.FromErr(err)
120+
}
121+
122+
if len(regions) == 0 {
123+
return diag.Errorf("Your query returned no results. Please change your search criteria and try again.")
124+
}
125+
126+
var genericRegions = flattenActiveActiveRegions(regions)
127+
128+
id := fmt.Sprintf("%d-active-active-regions", *sub.ID)
129+
d.SetId(id)
130+
131+
if err := d.Set("regions", genericRegions); err != nil {
132+
return diag.FromErr(err)
133+
}
134+
135+
return diags
136+
}
137+
138+
// generifies the region/db data so it can be put into the terraform schema
139+
func flattenActiveActiveRegions(regionList []*subscriptions.ActiveActiveRegion) []map[string]interface{} {
140+
var rl []map[string]interface{}
141+
for _, currentRegion := range regionList {
142+
143+
var dbs []map[string]interface{}
144+
for _, db := range currentRegion.Databases {
145+
dbMap := map[string]interface{}{
146+
"database_id": db.DatabaseId,
147+
"database_name": db.DatabaseName,
148+
"write_operations_per_second": db.WriteOperationsPerSecond,
149+
"read_operations_per_second": db.ReadOperationsPerSecond,
150+
}
151+
dbs = append(dbs, dbMap)
152+
}
153+
154+
regionMap := map[string]interface{}{
155+
"region": currentRegion.Region,
156+
"networking_deployment_cidr": currentRegion.DeploymentCIDR,
157+
"vpc_id": currentRegion.VpcId,
158+
"databases": dbs,
159+
}
160+
rl = append(rl, regionMap)
161+
}
162+
return rl
163+
}

provider/datasource_rediscloud_pro_subscription.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func dataSourceRedisCloudProSubscription() *schema.Resource {
6363
Computed: true,
6464
},
6565
"region": {
66-
Description: "Cloud networking details, per region (single region or multiple regions for Active-Active cluster only)",
66+
Description: "Cloud networking details, per region",
6767
Type: schema.TypeSet,
6868
Computed: true,
6969
Elem: &schema.Resource{
@@ -231,7 +231,7 @@ func dataSourceRedisCloudProSubscriptionRead(ctx context.Context, d *schema.Reso
231231

232232
var filters []func(method *subscriptions.Subscription) bool
233233

234-
// Filter to pro subscriptions only (active-active subs) come from the same endpoint
234+
// Filter to pro subscriptions only (active-active subs come from the same endpoint)
235235
filters = append(filters, func(sub *subscriptions.Subscription) bool {
236236
return redis.StringValue(sub.DeploymentType) != "active-active"
237237
})

provider/provider.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,20 @@ func New(version string) func() *schema.Provider {
4646
// Note the difference in public data-source name and the file/method name.
4747
// This is to help the developer relate their changes to what they would see happening in the Redis Console.
4848
// <default> == flexible == pro
49-
"rediscloud_subscription": dataSourceRedisCloudProSubscription(),
50-
"rediscloud_database": dataSourceRedisCloudProDatabase(),
51-
"rediscloud_database_modules": dataSourceRedisCloudDatabaseModules(),
52-
"rediscloud_payment_method": dataSourceRedisCloudPaymentMethod(),
53-
"rediscloud_regions": dataSourceRedisCloudRegions(),
54-
"rediscloud_essentials_plan": dataSourceRedisCloudEssentialsPlan(),
55-
"rediscloud_essentials_subscription": dataSourceRedisCloudEssentialsSubscription(),
56-
"rediscloud_essentials_database": dataSourceRedisCloudEssentialsDatabase(),
57-
"rediscloud_subscription_peerings": dataSourceRedisCloudSubscriptionPeerings(),
58-
"rediscloud_private_service_connect": dataSourcePrivateServiceConnect(),
59-
"rediscloud_private_service_connect_endpoints": dataSourcePrivateServiceConnectEndpoints(),
60-
"rediscloud_active_active_subscription": dataSourceRedisCloudActiveActiveSubscription(),
49+
"rediscloud_subscription": dataSourceRedisCloudProSubscription(),
50+
"rediscloud_database": dataSourceRedisCloudProDatabase(),
51+
"rediscloud_database_modules": dataSourceRedisCloudDatabaseModules(),
52+
"rediscloud_payment_method": dataSourceRedisCloudPaymentMethod(),
53+
"rediscloud_regions": dataSourceRedisCloudRegions(),
54+
"rediscloud_essentials_plan": dataSourceRedisCloudEssentialsPlan(),
55+
"rediscloud_essentials_subscription": dataSourceRedisCloudEssentialsSubscription(),
56+
"rediscloud_essentials_database": dataSourceRedisCloudEssentialsDatabase(),
57+
"rediscloud_subscription_peerings": dataSourceRedisCloudSubscriptionPeerings(),
58+
"rediscloud_private_service_connect": dataSourcePrivateServiceConnect(),
59+
"rediscloud_private_service_connect_endpoints": dataSourcePrivateServiceConnectEndpoints(),
60+
"rediscloud_active_active_subscription": dataSourceRedisCloudActiveActiveSubscription(),
61+
"rediscloud_active_active_subscription_regions": dataSourceRedisCloudActiveActiveSubscriptionRegions(),
62+
6163
// Note the difference in public data-source name and the file/method name.
6264
// active_active_subscription_database == active_active_database
6365
"rediscloud_active_active_subscription_database": dataSourceRedisCloudActiveActiveDatabase(),

0 commit comments

Comments
 (0)