Skip to content

Commit 0e2cc95

Browse files
committed
refactor: reduce code duplication
1 parent 0fb1a22 commit 0e2cc95

File tree

8 files changed

+116
-238
lines changed

8 files changed

+116
-238
lines changed

docs/data-sources/platform.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ Read-Only:
648648
- `subscription` (String) The Subscription that will contain all the created Resource Groups. Once you set the Subscription, you must not change it.
649649
- `tenant_tags` (Attributes) Tenant tags configuration (see [below for nested schema](#nestedatt--spec--config--azurerg--replication--tenant_tags))
650650
- `user_group_name_pattern` (String) Configures the pattern that defines the desired name of AAD groups managed by meshStack. It follows the usual replicator string pattern features and provides the additional replacement 'platformGroupAlias', which contains the role name suffix. This suffix is configurable via Role Mappings in this platform config.
651-
- `user_lookup_strategy` (String) User lookup strategy (`userPrincipalName` or `email`). Users can either be looked up in cloud platforms by email or UPN (User Principal Name). In most cases email is the matching way as it is the only identifier that is consistently used throughout all cloud platforms and meshStack.
651+
- `user_lookup_strategy` (String) User lookup strategy (`UserByMailLookupStrategy` or `UserByUsernameLookupStrategy`). Users can either be looked up in cloud platforms by email or UPN (User Principal Name). In most cases email is the matching way as it is the only identifier that is consistently used throughout all cloud platforms and meshStack.
652652

653653
<a id="nestedatt--spec--config--azurerg--replication--b2b_user_invitation"></a>
654654
### Nested Schema for `spec.config.azurerg.replication.b2b_user_invitation`

docs/resources/platform.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ Read-Only:
237237

238238
Required:
239239

240-
- `base_url` (String) Base URL of the AKS cluster
240+
- `base_url` (String) This is the base URL to your AKS cluster, which is used to call the APIs to create new AKS tenants, get raw data for metering the AKS tenants, etc. An example base URL is: https://myaks-dns.westeurope.azmk8s.io:443
241241

242242
Optional:
243243

244-
- `disable_ssl_validation` (Boolean) Flag to disable SSL validation for the AKS cluster. (SSL Validation should at best never be disabled, but for integration of some private cloud platforms in an early state, they might not yet be using valid SSL certificates. In that case it can make sense to disable SSL validation here to already test integration of these platforms.)
244+
- `disable_ssl_validation` (Boolean) Flag to disable SSL validation for the AKS cluster. SSL Validation should at best never be disabled, but for integration of some private cloud platforms in an early state, they might not yet be using valid SSL certificates. In that case it can make sense to disable SSL validation here to already test integration of these platforms.
245245
- `metering` (Attributes) Metering configuration for AKS (optional, but required for metering) (see [below for nested schema](#nestedatt--spec--config--aks--metering))
246246
- `replication` (Attributes) Replication configuration for AKS (optional, but required for replication) (see [below for nested schema](#nestedatt--spec--config--aks--replication))
247247

@@ -292,7 +292,7 @@ Required:
292292
- `namespace_name_pattern` (String) Pattern for naming namespaces in AKS
293293
- `send_azure_invitation_mail` (Boolean) Flag to send Azure invitation emails. When true, meshStack instructs Azure to send out Invitation mails to invited users.
294294
- `service_principal` (Attributes) Service principal configuration for AKS (see [below for nested schema](#nestedatt--spec--config--aks--replication--service_principal))
295-
- `user_lookup_strategy` (String) Strategy for user lookup in Azure (`userPrincipalName` or `email`)
295+
- `user_lookup_strategy` (String) Strategy for user lookup in Azure (`UserByEmailLookupStrategy` or `UserByUsernameLookupStrategy`)
296296

297297
Optional:
298298

@@ -558,7 +558,7 @@ Required:
558558

559559
Required:
560560

561-
- `namespace_prefix` (String) Namespace prefix for tenant tags
561+
- `namespace_prefix` (String) This is the prefix for all labels created by meshStack. It helps to keep track of which labels are managed by meshStack. It is recommended to let this prefix end with a delimiter like an underscore.
562562

563563
Optional:
564564

@@ -648,15 +648,15 @@ Required:
648648
- `service_principal` (Attributes) Service principal configuration for Azure (see [below for nested schema](#nestedatt--spec--config--azure--replication--service_principal))
649649
- `skip_user_group_permission_cleanup` (Boolean) Flag to skip user group permission cleanup. For certain use cases you might want to preserve user groups and replicated permission after a tenant was deleted on the Azure platform. Checking this option preserves those permissions. Please keep in mind that the platform operator is then responsible for cleaning them up later.
650650
- `subscription_name_pattern` (String) Configures the pattern that defines the desired name of Azure Subscriptions managed by meshStack.
651-
- `user_lookup_strategy` (String) User lookup strategy (`userPrincipalName` or `email`). Users can either be looked up in cloud platforms by email or UPN (User Principal Name). In most cases email is the matching way as it is the only identifier that is consistently used throughout all cloud platforms and meshStack.
651+
- `user_lookup_strategy` (String) Strategy for user lookup in Azure (`UserByEmailLookupStrategy` or `UserByUsernameLookupStrategy`)
652652

653653
Optional:
654654

655655
- `administrative_unit_id` (String) If you enter an administrative unit ID the replicated (and potentially existing) groups will be put into this AU. This can be used to limit the permission scopes which are required for the replicator principal. If you remove the AU ID again or change it, the groups will not be removed from the old AU.
656656
- `b2b_user_invitation` (Attributes) Optional B2B user invitation configuration. When configured, instructs the replicator to create AAD B2B guest invitations for users missing in the AAD tenant managed by this meshPlatform. (see [below for nested schema](#nestedatt--spec--config--azure--replication--b2b_user_invitation))
657657
- `blueprint_location` (String) The Azure location where replication creates and updates Blueprint Assignments. Note that it's still possible that the Blueprint creates resources in other locations, this is merely the location where the Blueprint Assignment is managed.
658658
- `provisioning` (Attributes) To provide Azure Subscription for your organization's meshProjects, meshcloud supports using Enterprise Enrollment or allocating from a pool of pre-provisioned subscriptions. One of the subFields enterpriseEnrollment, customerAgreement or preProvisioned must be provided! (see [below for nested schema](#nestedatt--spec--config--azure--replication--provisioning))
659-
- `tenant_tags` (Attributes) Tenant tagging configuration. (see [below for nested schema](#nestedatt--spec--config--azure--replication--tenant_tags))
659+
- `tenant_tags` (Attributes) Tenant tags configuration (see [below for nested schema](#nestedatt--spec--config--azure--replication--tenant_tags))
660660

661661
<a id="nestedatt--spec--config--azure--replication--azure_role_mappings"></a>
662662
### Nested Schema for `spec.config.azure.replication.azure_role_mappings`
@@ -849,7 +849,7 @@ Required:
849849
- `skip_user_group_permission_cleanup` (Boolean) For certain use cases you might want to preserve user groups and replicated permission after a tenant was deleted on the Azure platform. Checking this option preserves those permissions. Please keep in mind that the platform operator is then responsible for cleaning them up later.
850850
- `subscription` (String) The Subscription that will contain all the created Resource Groups. Once you set the Subscription, you must not change it.
851851
- `user_group_name_pattern` (String) Configures the pattern that defines the desired name of AAD groups managed by meshStack. It follows the usual replicator string pattern features and provides the additional replacement 'platformGroupAlias', which contains the role name suffix. This suffix is configurable via Role Mappings in this platform config.
852-
- `user_lookup_strategy` (String) User lookup strategy (`userPrincipalName` or `email`). Users can either be looked up in cloud platforms by email or UPN (User Principal Name). In most cases email is the matching way as it is the only identifier that is consistently used throughout all cloud platforms and meshStack.
852+
- `user_lookup_strategy` (String) Strategy for user lookup in Azure (`UserByEmailLookupStrategy` or `UserByUsernameLookupStrategy`)
853853

854854
Optional:
855855

@@ -1061,7 +1061,7 @@ Required:
10611061

10621062
Required:
10631063

1064-
- `namespace_prefix` (String) Namespace prefix for tenant tags
1064+
- `namespace_prefix` (String) This is the prefix for all labels created by meshStack. It helps to keep track of which labels are managed by meshStack. It is recommended to let this prefix end with a delimiter like an underscore.
10651065

10661066
Optional:
10671067

@@ -1084,7 +1084,7 @@ Required:
10841084

10851085
Required:
10861086

1087-
- `base_url` (String) This URL is the base URL to your Kubernetes Cluster, which is used to call the APIs to create new Kubernetes projects, get raw data for metering the Kubernetes projects, etc. An example base URL is: https://k8s.dev.eu-de-central.msh.host:6443
1087+
- `base_url` (String) This is the base URL to your Kubernetes cluster, which is used to call the APIs to create new Kubernetes tenants, get raw data for metering the Kubernetes tenants, etc. An example base URL is: https://k8s.dev.eu-de-central.msh.host:6443
10881088

10891089
Optional:
10901090

@@ -1157,7 +1157,7 @@ Required:
11571157

11581158
Required:
11591159

1160-
- `base_url` (String) This URL is the base URL to your OpenShift Cluster, which is used to call the APIs to create new OpenShift projects, get raw data for metering the OpenShift projects, etc. An example base URL is: https://api.okd4.dev.eu-de-central.msh.host:6443
1160+
- `base_url` (String) This is the base URL to your OpenShift cluster, which is used to call the APIs to create new OpenShift tenants, get raw data for metering the OpenShift tenants, etc. An example base URL is: https://api.okd4.dev.eu-de-central.msh.host:6443
11611161

11621162
Optional:
11631163

internal/provider/platform_data_source.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -982,9 +982,8 @@ func azureRgReplicationConfigDataSourceSchema() schema.Attribute {
982982
},
983983
},
984984
},
985-
// TODO: enforce correct value
986985
"user_lookup_strategy": schema.StringAttribute{
987-
MarkdownDescription: "User lookup strategy (`userPrincipalName` or `email`). Users can either be looked up in cloud platforms by email or UPN (User Principal Name). In most cases email is the matching way as it is the only identifier that is consistently used throughout all cloud platforms and meshStack.",
986+
MarkdownDescription: "User lookup strategy (`UserByMailLookupStrategy` or `UserByUsernameLookupStrategy`). Users can either be looked up in cloud platforms by email or UPN (User Principal Name). In most cases email is the matching way as it is the only identifier that is consistently used throughout all cloud platforms and meshStack.",
988987
Computed: true,
989988
},
990989
"tenant_tags": schema.SingleNestedAttribute{

internal/provider/platform_resource_schema_aws.go

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -127,32 +127,7 @@ func awsReplicationConfigSchema() schema.Attribute {
127127
MarkdownDescription: "With a String Pattern you can define how the account email address of the created AWS account will be set. E.g. `aws+#{workspaceIdentifier}.#{projectIdentifier}@yourcompany.com`. Please consider that this email address is limited to 64 characters! Also have a look at our docs for more information.",
128128
Required: true,
129129
},
130-
"tenant_tags": schema.SingleNestedAttribute{
131-
MarkdownDescription: "Tenant tags configuration",
132-
Optional: true,
133-
Attributes: map[string]schema.Attribute{
134-
"namespace_prefix": schema.StringAttribute{
135-
MarkdownDescription: "Namespace prefix for tenant tags",
136-
Required: true,
137-
},
138-
"tag_mappers": schema.ListNestedAttribute{
139-
MarkdownDescription: "List of tag mappers for tenant tags",
140-
Optional: true,
141-
NestedObject: schema.NestedAttributeObject{
142-
Attributes: map[string]schema.Attribute{
143-
"key": schema.StringAttribute{
144-
MarkdownDescription: "Key for the tag mapper",
145-
Required: true,
146-
},
147-
"value_pattern": schema.StringAttribute{
148-
MarkdownDescription: "Value pattern for the tag mapper",
149-
Required: true,
150-
},
151-
},
152-
},
153-
},
154-
},
155-
},
130+
"tenant_tags": tenantTagsAttribute(),
156131
"aws_sso": schema.SingleNestedAttribute{
157132
MarkdownDescription: "AWS SSO configuration",
158133
Optional: true,

internal/provider/platform_resource_schema_azure.go

Lines changed: 33 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package provider
22

33
import (
4+
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
45
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
56
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
7+
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
68
"github.com/hashicorp/terraform-plugin-framework/types"
79
)
810

@@ -86,7 +88,7 @@ func azureReplicationConfigSchema() schema.Attribute {
8688
MarkdownDescription: "The Application (Client) ID. In Azure Portal, this is the Application ID of the \"Enterprise Application\" but can also be retrieved via the \"App Registration\" object as \"Application (Client) ID\".",
8789
Required: true,
8890
},
89-
"auth": azureAuthConfigSchema(),
91+
"auth": azureAuthSchema(),
9092
},
9193
},
9294
"destination_entra_id": schema.StringAttribute{
@@ -172,37 +174,8 @@ func azureReplicationConfigSchema() schema.Attribute {
172174
},
173175
},
174176
},
175-
"tenant_tags": schema.SingleNestedAttribute{
176-
MarkdownDescription: "Tenant tagging configuration.",
177-
Optional: true,
178-
Attributes: map[string]schema.Attribute{
179-
"namespace_prefix": schema.StringAttribute{
180-
MarkdownDescription: "This is the prefix for all labels created by meshStack. It helps to keep track of which labels are managed by meshStack. It is recommended to let this prefix end with a delimiter like an underscore.",
181-
Required: true,
182-
},
183-
"tag_mappers": schema.ListNestedAttribute{
184-
MarkdownDescription: "List of tag mappers for tenant tags",
185-
Optional: true,
186-
NestedObject: schema.NestedAttributeObject{
187-
Attributes: map[string]schema.Attribute{
188-
"key": schema.StringAttribute{
189-
MarkdownDescription: "Key for the tag mapper",
190-
Required: true,
191-
},
192-
"value_pattern": schema.StringAttribute{
193-
MarkdownDescription: "Value pattern for the tag mapper",
194-
Required: true,
195-
},
196-
},
197-
},
198-
},
199-
},
200-
},
201-
// TODO: enforce correct value
202-
"user_lookup_strategy": schema.StringAttribute{
203-
MarkdownDescription: "User lookup strategy (`userPrincipalName` or `email`). Users can either be looked up in cloud platforms by email or UPN (User Principal Name). In most cases email is the matching way as it is the only identifier that is consistently used throughout all cloud platforms and meshStack.",
204-
Required: true,
205-
},
177+
"tenant_tags": tenantTagsAttribute(),
178+
"user_lookup_strategy": azureUserLookupStrategySchema(),
206179
"skip_user_group_permission_cleanup": schema.BoolAttribute{
207180
MarkdownDescription: "Flag to skip user group permission cleanup. For certain use cases you might want to preserve user groups and replicated permission after a tenant was deleted on the Azure platform. Checking this option preserves those permissions. Please keep in mind that the platform operator is then responsible for cleaning them up later.",
208181
Required: true,
@@ -219,21 +192,6 @@ func azureReplicationConfigSchema() schema.Attribute {
219192
}
220193
}
221194

222-
func azureAuthConfigSchema() schema.Attribute {
223-
return schema.SingleNestedAttribute{
224-
MarkdownDescription: "Authentication configuration",
225-
Required: true,
226-
Attributes: map[string]schema.Attribute{
227-
"type": schema.StringAttribute{
228-
MarkdownDescription: "Authentication type (credential or workloadIdentity)",
229-
Computed: true,
230-
PlanModifiers: []planmodifier.String{authTypeDefault()},
231-
},
232-
"credential": secretEmbeddedSchema("Client secret (if type is credential)", true),
233-
},
234-
}
235-
}
236-
237195
func azureMeteringConfigSchema() schema.Attribute {
238196
return schema.SingleNestedAttribute{
239197
MarkdownDescription: "Metering configuration for Azure (optional, but required for metering)",
@@ -251,7 +209,7 @@ func azureMeteringConfigSchema() schema.Attribute {
251209
MarkdownDescription: "The Object ID of the Enterprise Application. You can get this Object ID via the API (e.g. when using our Terraform provider) or from Enterprise applications pane in Microsoft Entra admin center.",
252210
Required: true,
253211
},
254-
"auth": azureAuthConfigSchema(),
212+
"auth": azureAuthSchema(),
255213
},
256214
},
257215
"processing": meteringProcessingConfigSchema(),
@@ -292,7 +250,7 @@ func azureRgReplicationConfigSchema() schema.Attribute {
292250
MarkdownDescription: "The Object ID of the Enterprise Application. You can get this Object ID via the API (e.g. when using our Terraform provider) or from Enterprise applications pane in Microsoft Entra admin center.",
293251
Required: true,
294252
},
295-
"auth": azureAuthConfigSchema(),
253+
"auth": azureAuthSchema(),
296254
},
297255
},
298256
"subscription": schema.StringAttribute{
@@ -321,37 +279,8 @@ func azureRgReplicationConfigSchema() schema.Attribute {
321279
},
322280
},
323281
},
324-
// TODO: enforce correct value
325-
"user_lookup_strategy": schema.StringAttribute{
326-
MarkdownDescription: "User lookup strategy (`userPrincipalName` or `email`). Users can either be looked up in cloud platforms by email or UPN (User Principal Name). In most cases email is the matching way as it is the only identifier that is consistently used throughout all cloud platforms and meshStack.",
327-
Required: true,
328-
},
329-
"tenant_tags": schema.SingleNestedAttribute{
330-
MarkdownDescription: "Tenant tags configuration",
331-
Optional: true,
332-
Attributes: map[string]schema.Attribute{
333-
"namespace_prefix": schema.StringAttribute{
334-
MarkdownDescription: "This is the prefix for all labels created by meshStack. It helps to keep track of which labels are managed by meshStack. It is recommended to let this prefix end with a delimiter like an underscore.",
335-
Required: true,
336-
},
337-
"tag_mappers": schema.ListNestedAttribute{
338-
MarkdownDescription: "List of tag mappers for tenant tags",
339-
Optional: true,
340-
NestedObject: schema.NestedAttributeObject{
341-
Attributes: map[string]schema.Attribute{
342-
"key": schema.StringAttribute{
343-
MarkdownDescription: "Key for the tag mapper",
344-
Required: true,
345-
},
346-
"value_pattern": schema.StringAttribute{
347-
MarkdownDescription: "Value pattern for the tag mapper",
348-
Required: true,
349-
},
350-
},
351-
},
352-
},
353-
},
354-
},
282+
"user_lookup_strategy": azureUserLookupStrategySchema(),
283+
"tenant_tags": tenantTagsAttribute(),
355284
"skip_user_group_permission_cleanup": schema.BoolAttribute{
356285
MarkdownDescription: "For certain use cases you might want to preserve user groups and replicated permission after a tenant was deleted on the Azure platform. Checking this option preserves those permissions. Please keep in mind that the platform operator is then responsible for cleaning them up later.",
357286
Required: true,
@@ -367,3 +296,27 @@ func azureRgReplicationConfigSchema() schema.Attribute {
367296
},
368297
}
369298
}
299+
func azureUserLookupStrategySchema() schema.Attribute {
300+
return schema.StringAttribute{
301+
MarkdownDescription: "Strategy for user lookup in Azure (`UserByEmailLookupStrategy` or `UserByUsernameLookupStrategy`)",
302+
Required: true,
303+
Validators: []validator.String{
304+
stringvalidator.OneOf([]string{"UserByMailLookupStrategy", "UserByUsernameLookupStrategy"}...),
305+
},
306+
}
307+
}
308+
309+
func azureAuthSchema() schema.Attribute {
310+
return schema.SingleNestedAttribute{
311+
MarkdownDescription: "Authentication configuration",
312+
Required: true,
313+
Attributes: map[string]schema.Attribute{
314+
"type": schema.StringAttribute{
315+
MarkdownDescription: "Authentication type (credential or workloadIdentity)",
316+
Computed: true,
317+
PlanModifiers: []planmodifier.String{authTypeDefault()},
318+
},
319+
"credential": secretEmbeddedSchema("Client secret (if type is credential)", true),
320+
},
321+
}
322+
}

0 commit comments

Comments
 (0)