Skip to content

Commit 59569c4

Browse files
committed
fix: adapt tenant_v4 resource to actual implementation
1 parent c6af469 commit 59569c4

File tree

8 files changed

+205
-123
lines changed

8 files changed

+205
-123
lines changed

docs/data-sources/tenant_v4.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ Fetches details of a single tenant by UUID (v4).
1414

1515
```terraform
1616
data "meshstack_tenant_v4" "example" {
17-
uuid = "00000000-0000-0000-0000-000000000000"
17+
metadata = {
18+
uuid = "00000000-0000-0000-0000-000000000000" # Tenant UUID
19+
}
1820
}
1921
```
2022

docs/resources/tenant_v4.md

Lines changed: 28 additions & 18 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

@@ -22,7 +22,6 @@ data "meshstack_project" "example" {
2222
2323
resource "meshstack_tenant_v4" "example" {
2424
metadata = {
25-
uuid = "1234-5345234-213123-123123"
2625
owned_by_workspace = data.meshstack_project.example.metadata.owned_by_workspace
2726
owned_by_project = data.meshstack_project.example.metadata.name
2827
}
@@ -39,28 +38,29 @@ resource "meshstack_tenant_v4" "example" {
3938

4039
### Required
4140

42-
- `metadata` (Attributes) Tenant metadata. Workspace, project and platform of the target tenant must be set here. (see [below for nested schema](#nestedatt--metadata))
41+
- `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))
4342
- `spec` (Attributes) Tenant specification. (see [below for nested schema](#nestedatt--spec))
4443

4544
### Read-Only
4645

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

5150
<a id="nestedatt--metadata"></a>
5251
### Nested Schema for `metadata`
5352

5453
Required:
5554

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.
55+
- `owned_by_project` (String) The identifier of the project that the tenant belongs to.
56+
- `owned_by_workspace` (String) The identifier of the workspace that the tenant belongs to.
5957

6058
Read-Only:
6159

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).
60+
- `created_on` (String) The creation timestamp of the meshTenant (e.g. `2020-12-22T09:37:43Z`).
61+
- `deleted_on` (String) The deletion timestamp of the tenant (e.g. `2020-12-22T09:37:43Z`).
62+
- `marked_for_deletion_on` (String) The timestamp when the tenant was marked for deletion (e.g. `2020-12-22T09:37:43Z`).
63+
- `uuid` (String) The unique identifier (UUID) of the tenant.
6464

6565

6666
<a id="nestedatt--spec"></a>
@@ -72,14 +72,14 @@ Required:
7272

7373
Optional:
7474

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))
75+
- `landing_zone_identifier` (String) The identifier of the landing zone to assign to this tenant.
76+
- `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.
77+
- `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))
7878

7979
<a id="nestedatt--spec--quotas"></a>
8080
### Nested Schema for `spec.quotas`
8181

82-
Read-Only:
82+
Required:
8383

8484
- `key` (String)
8585
- `value` (Number)
@@ -91,15 +91,25 @@ Read-Only:
9191

9292
Read-Only:
9393

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).
94+
- `platform_type_identifier` (String) Identifier of the platform type.
95+
- `platform_workspace_identifier` (String) Some platforms create representations of workspaces, in such cases this will contain the identifier of the workspace on the platform.
96+
- `quotas` (Attributes Set) The effective quotas applied to the tenant. (see [below for nested schema](#nestedatt--status--quotas))
9697
- `tags` (Map of List of String) Tags assigned to this tenant.
98+
- `tenant_name` (String) The full tenant name, a concatenation of the workspace identifier, project identifier and platform identifier.
99+
100+
<a id="nestedatt--status--quotas"></a>
101+
### Nested Schema for `status.quotas`
102+
103+
Read-Only:
104+
105+
- `key` (String)
106+
- `value` (Number)
97107

98108
## Import
99109

100110
Import is supported using the following syntax:
101111

102112
```shell
103113
# import via uuid
104-
terraform import 'meshstack_tenant.example' '00000000-0000-0000-0000-000000000000'
114+
terraform import 'meshstack_tenant_v4.example' '00000000-0000-0000-0000-000000000000'
105115
```
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
data "meshstack_tenant_v4" "example" {
2-
uuid = "00000000-0000-0000-0000-000000000000"
2+
metadata = {
3+
uuid = "00000000-0000-0000-0000-000000000000" # Tenant UUID
4+
}
35
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# import via uuid
2-
terraform import 'meshstack_tenant.example' '00000000-0000-0000-0000-000000000000'
2+
terraform import 'meshstack_tenant_v4.example' '00000000-0000-0000-0000-000000000000'

examples/resources/meshstack_tenant_v4/resource.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ data "meshstack_project" "example" {
77

88
resource "meshstack_tenant_v4" "example" {
99
metadata = {
10-
uuid = "1234-5345234-213123-123123"
1110
owned_by_workspace = data.meshstack_project.example.metadata.owned_by_workspace
1211
owned_by_project = data.meshstack_project.example.metadata.name
1312
}

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)