updated data statement for appinst and app

This commit is contained in:
Manuel Ganter 2025-11-12 11:53:39 +01:00
parent af22841b7f
commit cc46ee8974
No known key found for this signature in database
2 changed files with 59 additions and 56 deletions

View file

@ -23,11 +23,12 @@ type AppDataSource struct {
}
type AppDataSourceModel struct {
Id types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Description types.String `tfsdk:"description"`
Version types.String `tfsdk:"version"`
Status types.String `tfsdk:"status"`
Name types.String `tfsdk:"name"`
Organization types.String `tfsdk:"organization"`
Version types.String `tfsdk:"version"`
Region types.String `tfsdk:"region"`
Description types.String `tfsdk:"description"`
Status types.String `tfsdk:"status"`
}
func (d *AppDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
@ -39,25 +40,21 @@ func (d *AppDataSource) Schema(ctx context.Context, req datasource.SchemaRequest
MarkdownDescription: "App data source",
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
MarkdownDescription: "App identifier",
"name": schema.StringAttribute{
MarkdownDescription: "App name (primary key)",
Required: true,
},
"name": schema.StringAttribute{
MarkdownDescription: "App name",
Computed: true,
},
"description": schema.StringAttribute{
MarkdownDescription: "App description",
Computed: true,
"organization": schema.StringAttribute{
MarkdownDescription: "Organization name (primary key)",
Required: true,
},
"version": schema.StringAttribute{
MarkdownDescription: "App version",
Computed: true,
MarkdownDescription: "App version (primary key)",
Required: true,
},
"status": schema.StringAttribute{
MarkdownDescription: "App status",
Computed: true,
"region": schema.StringAttribute{
MarkdownDescription: "Region (EU or US)",
Required: true,
},
},
}
@ -92,20 +89,24 @@ func (d *AppDataSource) Read(ctx context.Context, req datasource.ReadRequest, re
}
appKey := edgeclient.AppKey{
Organization: "default",
Name: data.Id.ValueString(),
Version: "",
Organization: data.Organization.ValueString(),
Name: data.Name.ValueString(),
Version: data.Version.ValueString(),
}
app, err := d.client.ShowApp(ctx, appKey, "default")
region := data.Region.ValueString()
app, err := d.client.ShowApp(ctx, appKey, region)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read app %s, got error: %s", data.Id.ValueString(), err))
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read app %s/%s/%s in region %s, got error: %s",
data.Organization.ValueString(), data.Name.ValueString(), data.Version.ValueString(), region, err))
return
}
data.Name = types.StringValue(app.Key.Name)
data.Description = types.StringValue("")
data.Organization = types.StringValue(app.Key.Organization)
data.Version = types.StringValue(app.Key.Version)
data.Description = types.StringValue("")
data.Status = types.StringValue("")
tflog.Trace(ctx, "read an app data source")

View file

@ -23,12 +23,13 @@ type AppInstanceDataSource struct {
}
type AppInstanceDataSourceModel struct {
Id types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
AppId types.String `tfsdk:"app_id"`
Description types.String `tfsdk:"description"`
Config types.String `tfsdk:"config"`
Status types.String `tfsdk:"status"`
Name types.String `tfsdk:"name"`
Organization types.String `tfsdk:"organization"`
CloudletName types.String `tfsdk:"cloudlet_name"`
CloudletOrganization types.String `tfsdk:"cloudlet_organization"`
Region types.String `tfsdk:"region"`
AppId types.String `tfsdk:"app_id"`
Status types.String `tfsdk:"status"`
}
func (d *AppInstanceDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
@ -40,30 +41,30 @@ func (d *AppInstanceDataSource) Schema(ctx context.Context, req datasource.Schem
MarkdownDescription: "AppInstance data source",
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
MarkdownDescription: "AppInstance identifier",
"name": schema.StringAttribute{
MarkdownDescription: "AppInstance name (primary key)",
Required: true,
},
"name": schema.StringAttribute{
MarkdownDescription: "AppInstance name",
Computed: true,
"organization": schema.StringAttribute{
MarkdownDescription: "Organization name (primary key)",
Required: true,
},
"cloudlet_name": schema.StringAttribute{
MarkdownDescription: "Cloudlet name (primary key)",
Required: true,
},
"cloudlet_organization": schema.StringAttribute{
MarkdownDescription: "Cloudlet organization (primary key)",
Required: true,
},
"region": schema.StringAttribute{
MarkdownDescription: "Region (EU or US) (primary key)",
Required: true,
},
"app_id": schema.StringAttribute{
MarkdownDescription: "Associated App ID",
Computed: true,
},
"description": schema.StringAttribute{
MarkdownDescription: "AppInstance description",
Computed: true,
},
"config": schema.StringAttribute{
MarkdownDescription: "AppInstance configuration",
Computed: true,
},
"status": schema.StringAttribute{
MarkdownDescription: "AppInstance status",
Computed: true,
},
},
}
}
@ -97,24 +98,25 @@ func (d *AppInstanceDataSource) Read(ctx context.Context, req datasource.ReadReq
}
appInstKey := edgeclient.AppInstanceKey{
Organization: "default",
Name: data.Id.ValueString(),
Organization: data.Organization.ValueString(),
Name: data.Name.ValueString(),
CloudletKey: edgeclient.CloudletKey{
Organization: "default",
Name: "default-cloudlet",
Organization: data.CloudletOrganization.ValueString(),
Name: data.CloudletName.ValueString(),
},
}
appInstance, err := d.client.ShowAppInstance(ctx, appInstKey, "default")
region := data.Region.ValueString()
appInstance, err := d.client.ShowAppInstance(ctx, appInstKey, region)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read app instance %s, got error: %s", data.Id.ValueString(), err))
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read app instance %s/%s in region %s, got error: %s",
data.Organization.ValueString(), data.Name.ValueString(), region, err))
return
}
data.Name = types.StringValue(appInstance.Key.Name)
data.AppId = types.StringValue(appInstance.AppKey.Name)
data.Description = types.StringValue("")
data.Config = types.StringValue("")
data.Status = types.StringValue(appInstance.State)
tflog.Trace(ctx, "read an app instance data source")