Skip to content

Commit 4cfa89f

Browse files
committed
fix: adapt tenant_v4 resource to actual implementation
1 parent c6af469 commit 4cfa89f

File tree

4 files changed

+197
-117
lines changed

4 files changed

+197
-117
lines changed

docs/resources/tenant_v4.md

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
page_title: "meshstack_tenant_v4 Resource - terraform-provider-meshstack"
44
subcategory: ""
55
description: |-
6-
Single tenant by workspace, project, and platform (v4).
6+
Manages a meshTenant with API version 4.
77
---
88

99
# meshstack_tenant_v4 (Resource)
1010

11-
Single tenant by workspace, project, and platform (v4).
11+
Manages a `meshTenant` with API version 4.
1212

1313
## Example Usage
1414

@@ -39,28 +39,29 @@ resource "meshstack_tenant_v4" "example" {
3939

4040
### Required
4141

42-
- `metadata` (Attributes) Tenant metadata. Workspace, project and platform of the target tenant must be set here. (see [below for nested schema](#nestedatt--metadata))
42+
- `metadata` (Attributes) Metadata of the tenant. The `owned_by_workspace` and `owned_by_project` attributes must be set here. (see [below for nested schema](#nestedatt--metadata))
4343
- `spec` (Attributes) Tenant specification. (see [below for nested schema](#nestedatt--spec))
4444

4545
### Read-Only
4646

47-
- `api_version` (String) Tenant datatype version
48-
- `kind` (String) meshObject type, always `meshTenant`.
47+
- `api_version` (String) API version of the tenant resource.
48+
- `kind` (String) The kind of the meshObject, always `meshTenant`.
4949
- `status` (Attributes) Tenant status. (see [below for nested schema](#nestedatt--status))
5050

5151
<a id="nestedatt--metadata"></a>
5252
### Nested Schema for `metadata`
5353

5454
Required:
5555

56-
- `owned_by_project` (String) Identifier of the project the tenant belongs to.
57-
- `owned_by_workspace` (String) Identifier of the workspace the tenant belongs to.
58-
- `uuid` (String) UUID of the tenant.
56+
- `owned_by_project` (String) The identifier of the project that the tenant belongs to.
57+
- `owned_by_workspace` (String) The identifier of the workspace that the tenant belongs to.
5958

6059
Read-Only:
6160

62-
- `created_on` (String) The date the tenant was created (e.g. 2020-12-22T09:37:43Z).
63-
- `deleted_on` (String) If the tenant has been submitted for deletion by a workspace manager, the date is shown here (e.g. 2020-12-22T09:37:43Z).
61+
- `created_on` (String) The creation timestamp of the meshTenant (e.g. `2020-12-22T09:37:43Z`).
62+
- `deleted_on` (String) The deletion timestamp of the tenant (e.g. `2020-12-22T09:37:43Z`).
63+
- `marked_for_deletion_on` (String) The timestamp when the tenant was marked for deletion (e.g. `2020-12-22T09:37:43Z`).
64+
- `uuid` (String) The unique identifier (UUID) of the tenant.
6465

6566

6667
<a id="nestedatt--spec"></a>
@@ -72,14 +73,14 @@ Required:
7273

7374
Optional:
7475

75-
- `landing_zone_identifier` (String) Identifier of landing zone to assign to this tenant.
76-
- `local_id` (String) Tenant ID local to the platform (e.g. GCP project ID, Azure subscription ID). Setting the local ID means that a tenant with this ID should be imported into meshStack. Not setting a local ID means that a new tenant should be created. Field will be empty until a successful replication has run.
77-
- `quotas` (Attributes List) Set of applied tenant quotas. By default the landing zone quotas are applied to new tenants. (see [below for nested schema](#nestedatt--spec--quotas))
76+
- `landing_zone_identifier` (String) The identifier of the landing zone to assign to this tenant.
77+
- `platform_tenant_id` (String) The identifier of the tenant on the platform (e.g. GCP project ID or Azure subscription ID). If this is not set, a new tenant will be created. If this is set, an existing tenant will be imported. Otherwise, this field will be empty until a successful replication has run.
78+
- `quotas` (Attributes Set) Landing zone quota settings will be applied by default but can be changed here. (see [below for nested schema](#nestedatt--spec--quotas))
7879

7980
<a id="nestedatt--spec--quotas"></a>
8081
### Nested Schema for `spec.quotas`
8182

82-
Read-Only:
83+
Required:
8384

8485
- `key` (String)
8586
- `value` (Number)
@@ -91,9 +92,19 @@ Read-Only:
9192

9293
Read-Only:
9394

94-
- `current_replication_status` (String) The current replication status of the tenant.
95-
- `last_replicated` (String) The last time the tenant was replicated (e.g. 2020-12-22T09:37:43Z).
95+
- `platform_type_identifier` (String) Identifier of the platform type.
96+
- `platform_workspace_identifier` (String) Some platforms create representations of workspaces, in such cases this will contain the identifier of the workspace on the platform.
97+
- `quotas` (Attributes Set) The effective quotas applied to the tenant. (see [below for nested schema](#nestedatt--status--quotas))
9698
- `tags` (Map of List of String) Tags assigned to this tenant.
99+
- `tenant_name` (String) The full tenant name, a concatenation of the workspace identifier, project identifier and platform identifier.
100+
101+
<a id="nestedatt--status--quotas"></a>
102+
### Nested Schema for `status.quotas`
103+
104+
Read-Only:
105+
106+
- `key` (String)
107+
- `value` (Number)
97108

98109
## Import
99110

internal/provider/buildingblock_resource.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func (r *buildingBlockResource) Create(ctx context.Context, req resource.CreateR
355355
)
356356
return
357357
}
358-
resp.Diagnostics.Append(setStateFromResponse(&ctx, &resp.State, created)...)
358+
resp.Diagnostics.Append(r.setStateFromResponse(&ctx, &resp.State, created)...)
359359

360360
// ensure that user inputs are passed along
361361
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("spec").AtName("inputs"), plan.Spec.Inputs)...)
@@ -378,7 +378,7 @@ func (r *buildingBlockResource) Read(ctx context.Context, req resource.ReadReque
378378
return
379379
}
380380

381-
resp.Diagnostics.Append(setStateFromResponse(&ctx, &resp.State, bb)...)
381+
resp.Diagnostics.Append(r.setStateFromResponse(&ctx, &resp.State, bb)...)
382382
}
383383

384384
func (r *buildingBlockResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
@@ -471,7 +471,7 @@ func toResourceModel(io *client.MeshBuildingBlockIO) (*buildingBlockIoModel, err
471471
return nil, fmt.Errorf("Input '%s' with value type '%s' does not match actual value.", io.Key, io.ValueType)
472472
}
473473

474-
func setStateFromResponse(ctx *context.Context, state *tfsdk.State, bb *client.MeshBuildingBlock) diag.Diagnostics {
474+
func (r *buildingBlockResource) setStateFromResponse(ctx *context.Context, state *tfsdk.State, bb *client.MeshBuildingBlock) diag.Diagnostics {
475475
diags := make(diag.Diagnostics, 0)
476476

477477
diags.Append(state.SetAttribute(*ctx, path.Root("api_version"), bb.ApiVersion)...)

internal/provider/tenant_resource.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package provider
33
import (
44
"context"
55
"fmt"
6+
"slices"
67
"strings"
78

89
"github.com/meshcloud/terraform-provider-meshstack/client"
@@ -255,14 +256,12 @@ func (r *tenantResource) Delete(ctx context.Context, req resource.DeleteRequest,
255256
func (r *tenantResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
256257
identifier := strings.Split(req.ID, ".")
257258

258-
for _, s := range identifier {
259-
if s == "" {
260-
resp.Diagnostics.AddError(
261-
"Incomplete Import Identifier",
262-
fmt.Sprintf("Encountered empty import identifier field. Got: %q", req.ID),
263-
)
264-
return
265-
}
259+
if slices.Contains(identifier, "") {
260+
resp.Diagnostics.AddError(
261+
"Incomplete Import Identifier",
262+
fmt.Sprintf("Encountered empty import identifier field. Got: %q", req.ID),
263+
)
264+
return
266265
}
267266

268267
if len(identifier) != 4 {

0 commit comments

Comments
 (0)