@@ -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
690698func (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
@@ -1068,7 +1077,7 @@ var serviceUpdateWaitStates = []string{"ready", "failed", "stopped"}
10681077func (r * ServiceResource ) waitForUpdate (ctx context.Context , state * ServiceResourceModel , resp * resource.UpdateResponse ) {
10691078 if state .WaitForUpdate .ValueBool () {
10701079 err := sdkresource .RetryContext (ctx , defaultUpdateTimeout , func () * sdkresource.RetryError {
1071- service , err := r .client .GetServiceByID (ctx , state .ID .ValueString ())
1080+ service , err := r .client .GetServiceByID (ctx , state .ID .ValueString (), skysql . WithOrgID ( state . OrgID . ValueString ()) )
10721081 if err != nil {
10731082 return sdkresource .NonRetryableError (fmt .Errorf ("error retrieving service details: %v" , err ))
10741083 }
@@ -1105,7 +1114,7 @@ func (r *ServiceResource) Delete(ctx context.Context, req resource.DeleteRequest
11051114 return
11061115 }
11071116
1108- err := r .client .DeleteServiceByID (ctx , state .ID .ValueString ())
1117+ err := r .client .DeleteServiceByID (ctx , state .ID .ValueString (), skysql . WithOrgID ( state . OrgID . ValueString ()) )
11091118 if err != nil {
11101119 if errors .Is (err , skysql .ErrorServiceNotFound ) {
11111120 tflog .Warn (ctx , "SkySQL service not found, removing from state" , map [string ]interface {}{
@@ -1126,7 +1135,7 @@ func (r *ServiceResource) Delete(ctx context.Context, req resource.DeleteRequest
11261135 }
11271136
11281137 err = sdkresource .RetryContext (ctx , deleteTimeout , func () * sdkresource.RetryError {
1129- service , err := r .client .GetServiceByID (ctx , state .ID .ValueString ())
1138+ service , err := r .client .GetServiceByID (ctx , state .ID .ValueString (), skysql . WithOrgID ( state . OrgID . ValueString ()) )
11301139 if err != nil {
11311140 if errors .Is (err , skysql .ErrorServiceNotFound ) {
11321141 return nil
@@ -1452,7 +1461,7 @@ func (r *ServiceResource) updateServiceTags(ctx context.Context, plan *ServiceRe
14521461 "id" : state .ID .ValueString (),
14531462 })
14541463
1455- err := r .client .UpdateServiceTags (ctx , state .ID .ValueString (), planTags )
1464+ err := r .client .UpdateServiceTags (ctx , state .ID .ValueString (), planTags , skysql . WithOrgID ( state . OrgID . ValueString ()) )
14561465 if err != nil {
14571466 if errors .Is (err , skysql .ErrorServiceNotFound ) {
14581467 tflog .Warn (ctx , "SkySQL service not found, removing from state" , map [string ]interface {}{
0 commit comments