Skip to content

Commit 2ceab4d

Browse files
Merge pull request #23 from skysqlinc/320
[3.2.0] Multi-organization support added
2 parents db0682b + 44cc5d2 commit 2ceab4d

File tree

6 files changed

+511
-60
lines changed

6 files changed

+511
-60
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [3.2.0] - 2025-10-23
4+
### Added
5+
- Multi-organization support.
6+
37
## [3.1.5] - 2025-10-23
48
### Fixed
59
- prevent start/stop operations on serverless-standalone services.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@ See the examples in `/docs` in this repository for usage examples.
2020
```shell
2121
go install
2222
```
23+
24+
## Documentation
25+
26+
See the [documentation](docs/) for usage examples and detailed guides, including:
27+
28+
- [Multi-Organization Support](docs/guides/multi-organization-support.md) - Managing services across multiple SkySQL organizations

docs/resources/skysql_service.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ resource "skysql_service" "default" {
6363
- `maxscale_size` (String) The size of the MaxScale nodes. Valid values are: sky-2x4, sky-2x8 etc
6464
- `nodes` (Number) The number of nodes
6565
- `nosql_enabled` (Boolean) Whether to enable NoSQL. Valid values are: true or false
66+
- `org_id` (String) The organization ID to use for this service. When specified, all API requests will include the X-MDB-Org header to operate in this organization's context. This allows managing services across multiple organizations.
6667
- `primary_host` (String) The primary host of the service
6768
- `project_id` (String) The ID of the project to create the service in
6869
- `replication_enabled` (Boolean) Whether to enable global replication. Valid values are: true or false. Works for xpand-direct topology only

internal/provider/service_resource.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ type ServiceResourceModel struct {
9999
FQDN types.String `tfsdk:"fqdn"`
100100
AvailabilityZone types.String `tfsdk:"availability_zone"`
101101
Tags types.Map `tfsdk:"tags"`
102+
OrgID types.String `tfsdk:"org_id"`
102103
}
103104

104105
// ServiceResourceNamedPortModel is an endpoint port
@@ -410,6 +411,13 @@ var serviceResourceSchemaV0 = schema.Schema{
410411
&tagsNamePlanModifier{},
411412
},
412413
},
414+
"org_id": schema.StringAttribute{
415+
Optional: true,
416+
Description: "The organization ID to use for this service. When specified, all API requests will include the X-MDB-Org header to operate in this organization's context. This allows managing services across multiple organizations.",
417+
PlanModifiers: []planmodifier.String{
418+
stringplanmodifier.RequiresReplace(),
419+
},
420+
},
413421
},
414422
Blocks: map[string]schema.Block{
415423
"timeouts": timeouts.Block(context.Background(), timeouts.Opts{
@@ -532,7 +540,7 @@ func (r *ServiceResource) Create(ctx context.Context, req resource.CreateRequest
532540
}
533541
}
534542

535-
service, err := r.client.CreateService(ctx, createServiceRequest)
543+
service, err := r.client.CreateService(ctx, createServiceRequest, skysql.WithOrgID(state.OrgID.ValueString()))
536544
if err != nil {
537545
resp.Diagnostics.AddError("Error creating service", err.Error())
538546
return
@@ -595,7 +603,7 @@ func (r *ServiceResource) Create(ctx context.Context, req resource.CreateRequest
595603
}
596604

597605
err = sdkresource.RetryContext(ctx, createTimeout, func() *sdkresource.RetryError {
598-
service, err := r.client.GetServiceByID(ctx, service.ID)
606+
service, err := r.client.GetServiceByID(ctx, service.ID, skysql.WithOrgID(state.OrgID.ValueString()))
599607
if err != nil {
600608
return sdkresource.NonRetryableError(fmt.Errorf("error retrieving service details: %v", err))
601609
}
@@ -688,7 +696,7 @@ func (r *ServiceResource) Read(ctx context.Context, req resource.ReadRequest, re
688696
}
689697

690698
func (r *ServiceResource) readServiceState(ctx context.Context, data *ServiceResourceModel) error {
691-
service, err := r.client.GetServiceByID(ctx, data.ID.ValueString())
699+
service, err := r.client.GetServiceByID(ctx, data.ID.ValueString(), skysql.WithOrgID(data.OrgID.ValueString()))
692700
if err != nil {
693701
return err
694702
}
@@ -863,7 +871,7 @@ func (r *ServiceResource) updateServiceStorage(ctx context.Context, plan *Servic
863871
"throughput_to": plan.VolumeThroughput.ValueInt64(),
864872
})
865873

866-
err := r.client.ModifyServiceStorage(ctx, state.ID.ValueString(), plan.Storage.ValueInt64(), plan.VolumeIOPS.ValueInt64(), plan.VolumeThroughput.ValueInt64())
874+
err := r.client.ModifyServiceStorage(ctx, state.ID.ValueString(), plan.Storage.ValueInt64(), plan.VolumeIOPS.ValueInt64(), plan.VolumeThroughput.ValueInt64(), skysql.WithOrgID(state.OrgID.ValueString()))
867875
if err != nil {
868876
resp.Diagnostics.AddError("Error updating a storage for the service",
869877
fmt.Sprintf("Unable to update a storage size for the service, got error: %s", err))
@@ -888,7 +896,7 @@ func (r *ServiceResource) updateNumberOfNodeForService(ctx context.Context, plan
888896
"to": plan.Nodes.ValueInt64(),
889897
})
890898

891-
err := r.client.ModifyServiceNodeNumber(ctx, state.ID.ValueString(), plan.Nodes.ValueInt64())
899+
err := r.client.ModifyServiceNodeNumber(ctx, state.ID.ValueString(), plan.Nodes.ValueInt64(), skysql.WithOrgID(state.OrgID.ValueString()))
892900
if err != nil {
893901
resp.Diagnostics.AddError("Error updating a number of nodes for the service", fmt.Sprintf("Unable to update a nodes number for the service, got error: %s", err))
894902
return
@@ -911,7 +919,7 @@ func (r *ServiceResource) updateServiceSize(ctx context.Context, plan *ServiceRe
911919
"to": plan.Size.ValueString(),
912920
})
913921

914-
err := r.client.ModifyServiceSize(ctx, state.ID.ValueString(), plan.Size.ValueString())
922+
err := r.client.ModifyServiceSize(ctx, state.ID.ValueString(), plan.Size.ValueString(), skysql.WithOrgID(state.OrgID.ValueString()))
915923
if err != nil {
916924
resp.Diagnostics.AddError("Error updating service size", fmt.Sprintf("Unable to update service size, got error: %s", err))
917925
return
@@ -963,7 +971,8 @@ func (r *ServiceResource) updateServiceEndpoints(ctx context.Context, plan *Serv
963971
state.ID.ValueString(),
964972
plan.Mechanism.ValueString(),
965973
planAllowedAccounts,
966-
visibility)
974+
visibility,
975+
skysql.WithOrgID(state.OrgID.ValueString()))
967976
if err != nil {
968977
resp.Diagnostics.AddError("Can not update service", err.Error())
969978
return
@@ -1010,7 +1019,7 @@ func (r *ServiceResource) updateAllowList(ctx context.Context, plan *ServiceReso
10101019
})
10111020
}
10121021

1013-
allowListResp, err := r.client.UpdateServiceAllowListByID(ctx, plan.ID.ValueString(), allowListUpdateRequest)
1022+
allowListResp, err := r.client.UpdateServiceAllowListByID(ctx, plan.ID.ValueString(), allowListUpdateRequest, skysql.WithOrgID(plan.OrgID.ValueString()))
10141023
if err != nil {
10151024
if errors.Is(err, skysql.ErrorServiceNotFound) {
10161025
tflog.Warn(ctx, "SkySQL service not found, removing from state", map[string]interface{}{
@@ -1048,7 +1057,7 @@ func (r *ServiceResource) updateServicePowerState(ctx context.Context, plan *Ser
10481057
"id": state.ID.ValueString(),
10491058
"is_active": plan.IsActive.ValueBool(),
10501059
})
1051-
err := r.client.SetServicePowerState(ctx, state.ID.ValueString(), plan.IsActive.ValueBool())
1060+
err := r.client.SetServicePowerState(ctx, state.ID.ValueString(), plan.IsActive.ValueBool(), skysql.WithOrgID(state.OrgID.ValueString()))
10521061
if err != nil {
10531062
resp.Diagnostics.AddError("Can not update service", err.Error())
10541063
return
@@ -1093,7 +1102,7 @@ func (r *ServiceResource) updateServiceTags(ctx context.Context, plan *ServiceRe
10931102
"id": state.ID.ValueString(),
10941103
})
10951104

1096-
err := r.client.UpdateServiceTags(ctx, state.ID.ValueString(), planTags)
1105+
err := r.client.UpdateServiceTags(ctx, state.ID.ValueString(), planTags, skysql.WithOrgID(state.OrgID.ValueString()))
10971106
if err != nil {
10981107
if errors.Is(err, skysql.ErrorServiceNotFound) {
10991108
tflog.Warn(ctx, "SkySQL service not found, removing from state", map[string]interface{}{
@@ -1125,7 +1134,7 @@ var serviceUpdateWaitStates = []string{"ready", "failed", "stopped"}
11251134
func (r *ServiceResource) waitForUpdate(ctx context.Context, state *ServiceResourceModel, resp *resource.UpdateResponse) {
11261135
if state.WaitForUpdate.ValueBool() {
11271136
err := sdkresource.RetryContext(ctx, defaultUpdateTimeout, func() *sdkresource.RetryError {
1128-
service, err := r.client.GetServiceByID(ctx, state.ID.ValueString())
1137+
service, err := r.client.GetServiceByID(ctx, state.ID.ValueString(), skysql.WithOrgID(state.OrgID.ValueString()))
11291138
if err != nil {
11301139
return sdkresource.NonRetryableError(fmt.Errorf("error retrieving service details: %v", err))
11311140
}
@@ -1162,7 +1171,7 @@ func (r *ServiceResource) Delete(ctx context.Context, req resource.DeleteRequest
11621171
return
11631172
}
11641173

1165-
err := r.client.DeleteServiceByID(ctx, state.ID.ValueString())
1174+
err := r.client.DeleteServiceByID(ctx, state.ID.ValueString(), skysql.WithOrgID(state.OrgID.ValueString()))
11661175
if err != nil {
11671176
if errors.Is(err, skysql.ErrorServiceNotFound) {
11681177
tflog.Warn(ctx, "SkySQL service not found, removing from state", map[string]interface{}{
@@ -1183,7 +1192,7 @@ func (r *ServiceResource) Delete(ctx context.Context, req resource.DeleteRequest
11831192
}
11841193

11851194
err = sdkresource.RetryContext(ctx, deleteTimeout, func() *sdkresource.RetryError {
1186-
service, err := r.client.GetServiceByID(ctx, state.ID.ValueString())
1195+
service, err := r.client.GetServiceByID(ctx, state.ID.ValueString(), skysql.WithOrgID(state.OrgID.ValueString()))
11871196
if err != nil {
11881197
if errors.Is(err, skysql.ErrorServiceNotFound) {
11891198
return nil

0 commit comments

Comments
 (0)