Skip to content

Commit 29713a0

Browse files
malhussanhenryde
authored andcommitted
feat: meshstack_tenant_v4 data source
1 parent ecf4ab0 commit 29713a0

File tree

5 files changed

+247
-15
lines changed

5 files changed

+247
-15
lines changed

docs/data-sources/tenant_v4.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "meshstack_tenant_v4 Data Source - terraform-provider-meshstack"
4+
subcategory: ""
5+
description: |-
6+
Fetches details of a single tenant by UUID (v4).
7+
---
8+
9+
# meshstack_tenant_v4 (Data Source)
10+
11+
Fetches details of a single tenant by UUID (v4).
12+
13+
## Example Usage
14+
15+
```terraform
16+
data "meshstack_tenant_v4" "example" {
17+
uuid = "00000000-0000-0000-0000-000000000000"
18+
}
19+
```
20+
21+
<!-- schema generated by tfplugindocs -->
22+
## Schema
23+
24+
### Required
25+
26+
- `uuid` (String) UUID of the tenant.
27+
28+
### Read-Only
29+
30+
- `metadata` (Attributes) Tenant metadata. (see [below for nested schema](#nestedatt--metadata))
31+
- `spec` (Attributes) Tenant specification. (see [below for nested schema](#nestedatt--spec))
32+
- `status` (Attributes) Tenant status. (see [below for nested schema](#nestedatt--status))
33+
34+
<a id="nestedatt--metadata"></a>
35+
### Nested Schema for `metadata`
36+
37+
Read-Only:
38+
39+
- `created_on` (String) The date the tenant was created.
40+
- `deleted_on` (String) If the tenant has been submitted for deletion by a workspace manager, the date is shown here.
41+
- `owned_by_project` (String) Identifier of the project the tenant belongs to.
42+
- `owned_by_workspace` (String) Identifier of the workspace the tenant belongs to.
43+
44+
45+
<a id="nestedatt--spec"></a>
46+
### Nested Schema for `spec`
47+
48+
Read-Only:
49+
50+
- `landing_zone_identifier` (String) Identifier of landing zone to assign to this tenant.
51+
- `local_id` (String) Tenant ID local to the platform.
52+
- `platform_identifier` (String) Identifier of the target platform.
53+
- `quotas` (Attributes List) Set of applied tenant quotas. (see [below for nested schema](#nestedatt--spec--quotas))
54+
55+
<a id="nestedatt--spec--quotas"></a>
56+
### Nested Schema for `spec.quotas`
57+
58+
Read-Only:
59+
60+
- `key` (String)
61+
- `value` (Number)
62+
63+
64+
65+
<a id="nestedatt--status"></a>
66+
### Nested Schema for `status`
67+
68+
Read-Only:
69+
70+
- `current_replication_status` (String) The current replication status of the tenant.
71+
- `last_replicated` (String) The last time the tenant was replicated.
72+
- `tags` (Map of List of String) Tags assigned to this tenant.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
data "meshstack_tenant_v4" "example" {
2+
uuid = "00000000-0000-0000-0000-000000000000"
3+
}

internal/provider/provider.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (p *MeshStackProvider) Resources(ctx context.Context) []func() resource.Res
105105
return []func() resource.Resource{
106106
NewProjectResource,
107107
NewTenantResource,
108-
NewTenantResourceV4,
108+
NewTenantV4Resource,
109109
NewProjectUserBindingResource,
110110
NewProjectGroupBindingResource,
111111
NewWorkspaceResource,
@@ -127,6 +127,7 @@ func (p *MeshStackProvider) DataSources(ctx context.Context) []func() datasource
127127
NewTenantDataSource,
128128
NewTagDefinitionDataSource,
129129
NewTagDefinitionsDataSource,
130+
NewTenantV4DataSource,
130131
}
131132
}
132133

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
package provider
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/meshcloud/terraform-provider-meshstack/client"
8+
9+
"github.com/hashicorp/terraform-plugin-framework/datasource"
10+
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
11+
"github.com/hashicorp/terraform-plugin-framework/path"
12+
"github.com/hashicorp/terraform-plugin-framework/types"
13+
)
14+
15+
var (
16+
_ datasource.DataSource = &tenantV4DataSource{}
17+
_ datasource.DataSourceWithConfigure = &tenantV4DataSource{}
18+
)
19+
20+
func NewTenantV4DataSource() datasource.DataSource {
21+
return &tenantV4DataSource{}
22+
}
23+
24+
type tenantV4DataSource struct {
25+
client *client.MeshStackProviderClient
26+
}
27+
28+
func (d *tenantV4DataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
29+
resp.TypeName = req.ProviderTypeName + "_tenant_v4"
30+
}
31+
32+
func (d *tenantV4DataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
33+
if req.ProviderData == nil {
34+
return
35+
}
36+
37+
client, ok := req.ProviderData.(*client.MeshStackProviderClient)
38+
if !ok {
39+
resp.Diagnostics.AddError(
40+
"Unexpected Data Source Configure Type",
41+
fmt.Sprintf("Expected *client.MeshStackProviderClient, got: %T. Please report this issue to the provider developers.", req.ProviderData),
42+
)
43+
return
44+
}
45+
46+
d.client = client
47+
}
48+
49+
func (d *tenantV4DataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
50+
resp.Schema = schema.Schema{
51+
MarkdownDescription: "Fetches details of a single tenant by UUID (v4).",
52+
Attributes: map[string]schema.Attribute{
53+
"uuid": schema.StringAttribute{
54+
MarkdownDescription: "UUID of the tenant.",
55+
Required: true,
56+
},
57+
"metadata": schema.SingleNestedAttribute{
58+
MarkdownDescription: "Tenant metadata.",
59+
Computed: true,
60+
Attributes: map[string]schema.Attribute{
61+
"owned_by_workspace": schema.StringAttribute{
62+
MarkdownDescription: "Identifier of the workspace the tenant belongs to.",
63+
Computed: true,
64+
},
65+
"owned_by_project": schema.StringAttribute{
66+
MarkdownDescription: "Identifier of the project the tenant belongs to.",
67+
Computed: true,
68+
},
69+
"deleted_on": schema.StringAttribute{
70+
MarkdownDescription: "If the tenant has been submitted for deletion by a workspace manager, the date is shown here.",
71+
Computed: true,
72+
},
73+
"created_on": schema.StringAttribute{
74+
MarkdownDescription: "The date the tenant was created.",
75+
Computed: true,
76+
},
77+
},
78+
},
79+
"spec": schema.SingleNestedAttribute{
80+
MarkdownDescription: "Tenant specification.",
81+
Computed: true,
82+
Attributes: map[string]schema.Attribute{
83+
"platform_identifier": schema.StringAttribute{
84+
MarkdownDescription: "Identifier of the target platform.",
85+
Computed: true,
86+
},
87+
"local_id": schema.StringAttribute{
88+
MarkdownDescription: "Tenant ID local to the platform.",
89+
Computed: true,
90+
},
91+
"landing_zone_identifier": schema.StringAttribute{
92+
MarkdownDescription: "Identifier of landing zone to assign to this tenant.",
93+
Computed: true,
94+
},
95+
"quotas": schema.ListNestedAttribute{
96+
MarkdownDescription: "Set of applied tenant quotas.",
97+
Computed: true,
98+
NestedObject: schema.NestedAttributeObject{
99+
Attributes: map[string]schema.Attribute{
100+
"key": schema.StringAttribute{Computed: true},
101+
"value": schema.Int64Attribute{Computed: true},
102+
},
103+
},
104+
},
105+
},
106+
},
107+
"status": schema.SingleNestedAttribute{
108+
MarkdownDescription: "Tenant status.",
109+
Computed: true,
110+
Attributes: map[string]schema.Attribute{
111+
"tags": schema.MapAttribute{
112+
MarkdownDescription: "Tags assigned to this tenant.",
113+
ElementType: types.ListType{ElemType: types.StringType},
114+
Computed: true,
115+
},
116+
"last_replicated": schema.StringAttribute{
117+
MarkdownDescription: "The last time the tenant was replicated.",
118+
Computed: true,
119+
},
120+
"current_replication_status": schema.StringAttribute{
121+
MarkdownDescription: "The current replication status of the tenant.",
122+
Computed: true,
123+
},
124+
},
125+
},
126+
},
127+
}
128+
}
129+
130+
func (d *tenantV4DataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
131+
var uuid string
132+
resp.Diagnostics.Append(req.Config.GetAttribute(ctx, path.Root("uuid"), &uuid)...)
133+
134+
if resp.Diagnostics.HasError() {
135+
return
136+
}
137+
138+
tenant, err := d.client.ReadTenantV4(uuid)
139+
if err != nil {
140+
resp.Diagnostics.AddError(
141+
"Error reading tenant",
142+
fmt.Sprintf("Could not read tenant, unexpected error: %s", err.Error()),
143+
)
144+
return
145+
}
146+
147+
if tenant == nil {
148+
resp.Diagnostics.AddError(
149+
"Error reading tenant",
150+
"Tenant not found",
151+
)
152+
return
153+
}
154+
155+
resp.Diagnostics.Append(resp.State.Set(ctx, tenant)...)
156+
}

internal/provider/tenant_v4_resource.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@ import (
1818
)
1919

2020
var (
21-
_ resource.Resource = &tenantResourceV4{}
22-
_ resource.ResourceWithConfigure = &tenantResourceV4{}
23-
_ resource.ResourceWithImportState = &tenantResourceV4{}
21+
_ resource.Resource = &tenantV4Resource{}
22+
_ resource.ResourceWithConfigure = &tenantV4Resource{}
23+
_ resource.ResourceWithImportState = &tenantV4Resource{}
2424
)
2525

26-
func NewTenantResourceV4() resource.Resource {
27-
return &tenantResourceV4{}
26+
func NewTenantV4Resource() resource.Resource {
27+
return &tenantV4Resource{}
2828
}
2929

30-
type tenantResourceV4 struct {
30+
type tenantV4Resource struct {
3131
client *client.MeshStackProviderClient
3232
}
3333

34-
func (r *tenantResourceV4) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
34+
func (r *tenantV4Resource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
3535
resp.TypeName = req.ProviderTypeName + "_tenant_v4"
3636
}
3737

38-
func (r *tenantResourceV4) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
38+
func (r *tenantV4Resource) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
3939
if req.ProviderData == nil {
4040
return
4141
}
@@ -54,7 +54,7 @@ func (r *tenantResourceV4) Configure(_ context.Context, req resource.ConfigureRe
5454
r.client = client
5555
}
5656

57-
func (r *tenantResourceV4) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
57+
func (r *tenantV4Resource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
5858
resp.Schema = schema.Schema{
5959
MarkdownDescription: "Single tenant by workspace, project, and platform (v4).",
6060

@@ -158,7 +158,7 @@ func (r *tenantResourceV4) Schema(_ context.Context, _ resource.SchemaRequest, r
158158
}
159159
}
160160

161-
func (r *tenantResourceV4) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
161+
func (r *tenantV4Resource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
162162
var metadata client.MeshTenantCreateMetadataV4
163163
resp.Diagnostics.Append(req.Plan.GetAttribute(ctx, path.Root("metadata"), &metadata)...)
164164

@@ -186,7 +186,7 @@ func (r *tenantResourceV4) Create(ctx context.Context, req resource.CreateReques
186186
resp.Diagnostics.Append(resp.State.Set(ctx, tenant)...)
187187
}
188188

189-
func (r *tenantResourceV4) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
189+
func (r *tenantV4Resource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
190190
var uuid string
191191
resp.Diagnostics.Append(req.State.GetAttribute(ctx, path.Root("metadata").AtName("uuid"), &uuid)...)
192192

@@ -211,7 +211,7 @@ func (r *tenantResourceV4) Read(ctx context.Context, req resource.ReadRequest, r
211211
resp.Diagnostics.Append(resp.State.Set(ctx, tenant)...)
212212
}
213213

214-
func (r *tenantResourceV4) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
214+
func (r *tenantV4Resource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
215215
var metadata client.MeshTenantCreateMetadataV4
216216
resp.Diagnostics.Append(req.Plan.GetAttribute(ctx, path.Root("metadata"), &metadata)...)
217217

@@ -239,7 +239,7 @@ func (r *tenantResourceV4) Update(ctx context.Context, req resource.UpdateReques
239239
resp.Diagnostics.Append(resp.State.Set(ctx, tenant)...)
240240
}
241241

242-
func (r *tenantResourceV4) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
242+
func (r *tenantV4Resource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
243243
var uuid string
244244
resp.Diagnostics.Append(req.State.GetAttribute(ctx, path.Root("metadata").AtName("uuid"), &uuid)...)
245245

@@ -257,7 +257,7 @@ func (r *tenantResourceV4) Delete(ctx context.Context, req resource.DeleteReques
257257
}
258258
}
259259

260-
func (r *tenantResourceV4) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
260+
func (r *tenantV4Resource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
261261
uuid := req.ID
262262

263263
tenant, err := r.client.ReadTenantV4(uuid)

0 commit comments

Comments
 (0)