Skip to content

Commit 4012632

Browse files
committed
fix: adapt tenant_v4 resource to actual implementation
1 parent a36774c commit 4012632

File tree

11 files changed

+267
-146
lines changed

11 files changed

+267
-146
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
FEATURES:
44
- Added `meshstack_workspace` resource.
55
- Added `meshstack_workspace` data source.
6+
- Added `meshstack_tenant_v4` resource.
7+
- Added `meshstack_tenant_v4` data source.
68

79
FIXES:
810
- Allow `value_code` in `meshstack_building_block_v2` and `meshstack_building_block` resources.

client/tenant_v4.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (c *MeshStackProviderClient) ReadTenantV4(uuid string) (*MeshTenantV4, erro
8787
return nil, nil
8888
}
8989

90-
if res.StatusCode != 200 {
90+
if !isSuccessHTTPStatus(res) {
9191
return nil, fmt.Errorf("unexpected status code: %d, %s", res.StatusCode, data)
9292
}
9393

docs/data-sources/tenant_v4.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@
33
page_title: "meshstack_tenant_v4 Data Source - terraform-provider-meshstack"
44
subcategory: ""
55
description: |-
6-
Fetches details of a single tenant by UUID (v4).
6+
Fetches details of a single tenant by UUID.
7+
~> Note: This resource is in preview and may change in the near future.
78
---
89

910
# meshstack_tenant_v4 (Data Source)
1011

11-
Fetches details of a single tenant by UUID (v4).
12+
Fetches details of a single tenant by UUID.
13+
14+
~> **Note:** This resource is in preview and may change in the near future.
1215

1316
## Example Usage
1417

1518
```terraform
1619
data "meshstack_tenant_v4" "example" {
17-
uuid = "00000000-0000-0000-0000-000000000000"
20+
metadata = {
21+
uuid = "00000000-0000-0000-0000-000000000000" # Tenant UUID
22+
}
1823
}
1924
```
2025

@@ -23,21 +28,27 @@ data "meshstack_tenant_v4" "example" {
2328

2429
### Required
2530

26-
- `uuid` (String) UUID of the tenant.
31+
- `metadata` (Attributes) Tenant metadata. (see [below for nested schema](#nestedatt--metadata))
2732

2833
### Read-Only
2934

30-
- `metadata` (Attributes) Tenant metadata. (see [below for nested schema](#nestedatt--metadata))
35+
- `api_version` (String) Tenant datatype version
36+
- `kind` (String) meshObject type, always `meshTenant`.
3137
- `spec` (Attributes) Tenant specification. (see [below for nested schema](#nestedatt--spec))
3238
- `status` (Attributes) Tenant status. (see [below for nested schema](#nestedatt--status))
3339

3440
<a id="nestedatt--metadata"></a>
3541
### Nested Schema for `metadata`
3642

43+
Required:
44+
45+
- `uuid` (String) UUID of the tenant.
46+
3747
Read-Only:
3848

3949
- `created_on` (String) The date the tenant was created.
4050
- `deleted_on` (String) If the tenant has been submitted for deletion by a workspace manager, the date is shown here.
51+
- `marked_for_deletion_on` (String) Date when the tenant was marked for deletion.
4152
- `owned_by_project` (String) Identifier of the project the tenant belongs to.
4253
- `owned_by_workspace` (String) Identifier of the workspace the tenant belongs to.
4354

@@ -48,8 +59,8 @@ Read-Only:
4859
Read-Only:
4960

5061
- `landing_zone_identifier` (String) Identifier of landing zone to assign to this tenant.
51-
- `local_id` (String) Tenant ID local to the platform.
5262
- `platform_identifier` (String) Identifier of the target platform.
63+
- `platform_tenant_id` (String) Platform-specific tenant ID.
5364
- `quotas` (Attributes List) Set of applied tenant quotas. (see [below for nested schema](#nestedatt--spec--quotas))
5465

5566
<a id="nestedatt--spec--quotas"></a>
@@ -67,6 +78,7 @@ Read-Only:
6778

6879
Read-Only:
6980

70-
- `current_replication_status` (String) The current replication status of the tenant.
71-
- `last_replicated` (String) The last time the tenant was replicated.
81+
- `platform_type_identifier` (String) Identifier of the platform type.
82+
- `platform_workspace_identifier` (String) Identifier of the platform workspace.
7283
- `tags` (Map of List of String) Tags assigned to this tenant.
84+
- `tenant_name` (String) Name of the tenant.

docs/resources/tenant_v4.md

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
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.
7+
~> Note: This resource is in preview and may change in the near future.
78
---
89

910
# meshstack_tenant_v4 (Resource)
1011

11-
Single tenant by workspace, project, and platform (v4).
12+
Manages a `meshTenant` with API version 4.
13+
14+
~> **Note:** This resource is in preview and may change in the near future.
1215

1316
## Example Usage
1417

@@ -22,7 +25,6 @@ data "meshstack_project" "example" {
2225
2326
resource "meshstack_tenant_v4" "example" {
2427
metadata = {
25-
uuid = "1234-5345234-213123-123123"
2628
owned_by_workspace = data.meshstack_project.example.metadata.owned_by_workspace
2729
owned_by_project = data.meshstack_project.example.metadata.name
2830
}
@@ -39,28 +41,29 @@ resource "meshstack_tenant_v4" "example" {
3941

4042
### Required
4143

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

4547
### Read-Only
4648

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

5153
<a id="nestedatt--metadata"></a>
5254
### Nested Schema for `metadata`
5355

5456
Required:
5557

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

6061
Read-Only:
6162

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

6568

6669
<a id="nestedatt--spec"></a>
@@ -72,14 +75,14 @@ Required:
7275

7376
Optional:
7477

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))
78+
- `landing_zone_identifier` (String) The identifier of the landing zone to assign to this tenant.
79+
- `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.
80+
- `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))
7881

7982
<a id="nestedatt--spec--quotas"></a>
8083
### Nested Schema for `spec.quotas`
8184

82-
Read-Only:
85+
Required:
8386

8487
- `key` (String)
8588
- `value` (Number)
@@ -91,15 +94,25 @@ Read-Only:
9194

9295
Read-Only:
9396

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

98111
## Import
99112

100113
Import is supported using the following syntax:
101114

102115
```shell
103116
# import via uuid
104-
terraform import 'meshstack_tenant.example' '00000000-0000-0000-0000-000000000000'
117+
terraform import 'meshstack_tenant_v4.example' '00000000-0000-0000-0000-000000000000'
105118
```
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
@@ -366,7 +366,7 @@ func (r *buildingBlockResource) Create(ctx context.Context, req resource.CreateR
366366
)
367367
return
368368
}
369-
resp.Diagnostics.Append(setStateFromResponse(&ctx, &resp.State, created)...)
369+
resp.Diagnostics.Append(r.setStateFromResponse(&ctx, &resp.State, created)...)
370370

371371
// ensure that user inputs are passed along
372372
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("spec").AtName("inputs"), plan.Spec.Inputs)...)
@@ -389,7 +389,7 @@ func (r *buildingBlockResource) Read(ctx context.Context, req resource.ReadReque
389389
return
390390
}
391391

392-
resp.Diagnostics.Append(setStateFromResponse(&ctx, &resp.State, bb)...)
392+
resp.Diagnostics.Append(r.setStateFromResponse(&ctx, &resp.State, bb)...)
393393
}
394394

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

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

495495
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 {

internal/provider/tenant_v4_data_source.go

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import (
66

77
"github.com/meshcloud/terraform-provider-meshstack/client"
88

9+
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
910
"github.com/hashicorp/terraform-plugin-framework/datasource"
1011
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
1112
"github.com/hashicorp/terraform-plugin-framework/path"
13+
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1214
"github.com/hashicorp/terraform-plugin-framework/types"
1315
)
1416

@@ -48,16 +50,29 @@ func (d *tenantV4DataSource) Configure(_ context.Context, req datasource.Configu
4850

4951
func (d *tenantV4DataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
5052
resp.Schema = schema.Schema{
51-
MarkdownDescription: "Fetches details of a single tenant by UUID (v4).",
53+
MarkdownDescription: "Fetches details of a single tenant by UUID.\n\n~> **Note:** This resource is in preview and may change in the near future.",
5254
Attributes: map[string]schema.Attribute{
53-
"uuid": schema.StringAttribute{
54-
MarkdownDescription: "UUID of the tenant.",
55-
Required: true,
55+
"api_version": schema.StringAttribute{
56+
MarkdownDescription: "Tenant datatype version",
57+
Computed: true,
58+
},
59+
60+
"kind": schema.StringAttribute{
61+
MarkdownDescription: "meshObject type, always `meshTenant`.",
62+
Computed: true,
63+
Validators: []validator.String{
64+
stringvalidator.OneOf([]string{"meshTenant"}...),
65+
},
5666
},
67+
5768
"metadata": schema.SingleNestedAttribute{
5869
MarkdownDescription: "Tenant metadata.",
59-
Computed: true,
70+
Required: true,
6071
Attributes: map[string]schema.Attribute{
72+
"uuid": schema.StringAttribute{
73+
MarkdownDescription: "UUID of the tenant.",
74+
Required: true,
75+
},
6176
"owned_by_workspace": schema.StringAttribute{
6277
MarkdownDescription: "Identifier of the workspace the tenant belongs to.",
6378
Computed: true,
@@ -66,6 +81,10 @@ func (d *tenantV4DataSource) Schema(_ context.Context, _ datasource.SchemaReques
6681
MarkdownDescription: "Identifier of the project the tenant belongs to.",
6782
Computed: true,
6883
},
84+
"marked_for_deletion_on": schema.StringAttribute{
85+
MarkdownDescription: "Date when the tenant was marked for deletion.",
86+
Computed: true,
87+
},
6988
"deleted_on": schema.StringAttribute{
7089
MarkdownDescription: "If the tenant has been submitted for deletion by a workspace manager, the date is shown here.",
7190
Computed: true,
@@ -84,8 +103,8 @@ func (d *tenantV4DataSource) Schema(_ context.Context, _ datasource.SchemaReques
84103
MarkdownDescription: "Identifier of the target platform.",
85104
Computed: true,
86105
},
87-
"local_id": schema.StringAttribute{
88-
MarkdownDescription: "Tenant ID local to the platform.",
106+
"platform_tenant_id": schema.StringAttribute{
107+
MarkdownDescription: "Platform-specific tenant ID.",
89108
Computed: true,
90109
},
91110
"landing_zone_identifier": schema.StringAttribute{
@@ -108,17 +127,21 @@ func (d *tenantV4DataSource) Schema(_ context.Context, _ datasource.SchemaReques
108127
MarkdownDescription: "Tenant status.",
109128
Computed: true,
110129
Attributes: map[string]schema.Attribute{
111-
"tags": schema.MapAttribute{
112-
MarkdownDescription: "Tags assigned to this tenant.",
113-
ElementType: types.ListType{ElemType: types.StringType},
130+
"tenant_name": schema.StringAttribute{
131+
MarkdownDescription: "Name of the tenant.",
114132
Computed: true,
115133
},
116-
"last_replicated": schema.StringAttribute{
117-
MarkdownDescription: "The last time the tenant was replicated.",
134+
"platform_type_identifier": schema.StringAttribute{
135+
MarkdownDescription: "Identifier of the platform type.",
118136
Computed: true,
119137
},
120-
"current_replication_status": schema.StringAttribute{
121-
MarkdownDescription: "The current replication status of the tenant.",
138+
"platform_workspace_identifier": schema.StringAttribute{
139+
MarkdownDescription: "Identifier of the platform workspace.",
140+
Computed: true,
141+
},
142+
"tags": schema.MapAttribute{
143+
MarkdownDescription: "Tags assigned to this tenant.",
144+
ElementType: types.ListType{ElemType: types.StringType},
122145
Computed: true,
123146
},
124147
},
@@ -129,7 +152,7 @@ func (d *tenantV4DataSource) Schema(_ context.Context, _ datasource.SchemaReques
129152

130153
func (d *tenantV4DataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
131154
var uuid string
132-
resp.Diagnostics.Append(req.Config.GetAttribute(ctx, path.Root("uuid"), &uuid)...)
155+
resp.Diagnostics.Append(req.Config.GetAttribute(ctx, path.Root("metadata").AtName("uuid"), &uuid)...)
133156

134157
if resp.Diagnostics.HasError() {
135158
return

0 commit comments

Comments
 (0)