You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
page_title: "Multi-Organization Support - SkySQL Terraform Provider"
3
+
description: |-
4
+
Guide for managing services across multiple SkySQL organizations using the org_id parameter
5
+
---
6
+
7
+
# Multi-Organization Support
8
+
9
+
**Version 3.2.0+** supports managing services across multiple organizations using the `org_id` parameter.
10
+
11
+
## Overview
12
+
13
+
When a user belongs to multiple SkySQL organizations, the provider can manage services in different organizations by specifying the `org_id` parameter on each service resource. This parameter adds the `X-MDB-Org` header to all API requests for that service, allowing the backend to operate in the context of the specified organization.
14
+
15
+
## Usage
16
+
17
+
### Single Organization (Default Behavior)
18
+
19
+
If you only work with one organization or want to use the organization associated with your API key, simply omit the `org_id` parameter:
20
+
21
+
```hcl
22
+
resource "skysql_service" "my_service" {
23
+
name = "my-database"
24
+
service_type = "transactional"
25
+
topology = "standalone"
26
+
cloud_provider = "aws"
27
+
region = "us-east-1"
28
+
size = "sky-2x8"
29
+
storage = 100
30
+
ssl_enabled = true
31
+
# org_id is not specified - uses the API key's default organization
32
+
}
33
+
```
34
+
35
+
### Multiple Organizations
36
+
37
+
When managing services across multiple organizations, specify the `org_id` for each service:
38
+
39
+
```hcl
40
+
# Production database in organization A
41
+
resource "skysql_service" "prod_db" {
42
+
org_id = "org-12345-production"
43
+
name = "prod-database"
44
+
service_type = "transactional"
45
+
topology = "standalone"
46
+
cloud_provider = "aws"
47
+
region = "us-east-1"
48
+
size = "sky-4x16"
49
+
storage = 500
50
+
ssl_enabled = true
51
+
}
52
+
53
+
# Development database in organization B
54
+
resource "skysql_service" "dev_db" {
55
+
org_id = "org-67890-development"
56
+
name = "dev-database"
57
+
service_type = "transactional"
58
+
topology = "standalone"
59
+
cloud_provider = "gcp"
60
+
region = "us-central1"
61
+
size = "sky-2x8"
62
+
storage = 100
63
+
ssl_enabled = true
64
+
}
65
+
66
+
# Staging database in organization C
67
+
resource "skysql_service" "staging_db" {
68
+
org_id = "org-11223-staging"
69
+
name = "staging-database"
70
+
service_type = "analytical"
71
+
topology = "standalone"
72
+
cloud_provider = "aws"
73
+
region = "eu-west-1"
74
+
size = "sky-2x8"
75
+
storage = 200
76
+
ssl_enabled = true
77
+
}
78
+
```
79
+
80
+
## Important Notes
81
+
82
+
1.**Replacement Required**: Changing the `org_id` of an existing service will destroy and recreate the service. Plan carefully when setting this value.
83
+
2.**API Key Permissions**: Your API key must have access to all organizations specified in your Terraform configuration. If the API key doesn't have access to an organization, requests will fail with a forbidden error.
84
+
3.**Backward Compatibility**: The `org_id` parameter is optional. Existing Terraform configurations will continue to work without modification.
85
+
86
+
## Finding Your Organization ID
87
+
88
+
You can find your organization IDs through:
89
+
90
+
- The SkySQL web console (Organization Settings)
91
+
- The SkySQL API (`/organization/v1/orgs` endpoint)
92
+
- Your organization administrator
93
+
94
+
## Example: Team-Based Infrastructure
95
+
96
+
```hcl
97
+
# Variables for organization IDs
98
+
variable "team_a_org_id" {
99
+
description = "Organization ID for Team A"
100
+
type = string
101
+
}
102
+
103
+
variable "team_b_org_id" {
104
+
description = "Organization ID for Team B"
105
+
type = string
106
+
}
107
+
108
+
# Team A's production database
109
+
resource "skysql_service" "team_a_prod" {
110
+
org_id = var.team_a_org_id
111
+
name = "team-a-prod"
112
+
service_type = "transactional"
113
+
topology = "standalone"
114
+
cloud_provider = "aws"
115
+
region = "us-east-1"
116
+
size = "sky-8x32"
117
+
storage = 1000
118
+
ssl_enabled = true
119
+
}
120
+
121
+
# Team B's production database
122
+
resource "skysql_service" "team_b_prod" {
123
+
org_id = var.team_b_org_id
124
+
name = "team-b-prod"
125
+
service_type = "transactional"
126
+
topology = "standalone"
127
+
cloud_provider = "aws"
128
+
region = "us-west-2"
129
+
size = "sky-4x16"
130
+
storage = 500
131
+
ssl_enabled = true
132
+
}
133
+
```
134
+
135
+
## Troubleshooting
136
+
137
+
**Error: "access to this organization is forbidden"**
138
+
- Your API key doesn't have permission to access the specified organization
139
+
- Verify the `org_id` value is correct
140
+
- Check with your organization administrator to ensure your user account has access
141
+
142
+
**Service created in wrong organization**
143
+
- Double-check the `org_id` value in your configuration
144
+
- Remember that omitting `org_id` uses the API key's default organization
145
+
146
+
**Unexpected replacement during plan**
147
+
- Changing `org_id` requires resource replacement - this is by design
148
+
- Services cannot be moved between organizations; they must be recreated
-`maxscale_size` (String) The size of the MaxScale nodes. Valid values are: sky-2x4, sky-2x8 etc
64
64
-`nodes` (Number) The number of nodes
65
65
-`nosql_enabled` (Boolean) Whether to enable NoSQL. Valid values are: true or false
66
+
-`org_id` (String) The organization ID to create the service in. When specified, adds the X-MDB-Org header to API requests. **Note:** Changing this value will destroy and recreate the service. See the [Multi-Organization Support guide](../guides/multi-organization-support.md) for more information.
66
67
-`primary_host` (String) The primary host of the service
67
68
-`project_id` (String) The ID of the project to create the service in
68
69
-`replication_enabled` (Boolean) Whether to enable global replication. Valid values are: true or false. Works for xpand-direct topology only
// ServiceResourceNamedPortModel is an endpoint port
@@ -410,6 +411,13 @@ var serviceResourceSchemaV0 = schema.Schema{
410
411
&tagsNamePlanModifier{},
411
412
},
412
413
},
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.",
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))
0 commit comments