Update appinstance data schema to return list
This commit is contained in:
parent
39b88941a6
commit
676370b62b
3 changed files with 78 additions and 19 deletions
|
|
@ -31,30 +31,39 @@ type AppInstanceDataSourceModel struct {
|
|||
AppId types.String `tfsdk:"app_id"`
|
||||
}
|
||||
|
||||
type AppInstancesDataSourceModel struct {
|
||||
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"`
|
||||
AppInstances []AppInstanceDataSourceModel `tfsdk:"appinstances"`
|
||||
}
|
||||
|
||||
func (d *AppInstanceDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_app_instance"
|
||||
}
|
||||
|
||||
func (d *AppInstanceDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
MarkdownDescription: "AppInstance data source",
|
||||
|
||||
MarkdownDescription: "AppInstances data source",
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"name": schema.StringAttribute{
|
||||
MarkdownDescription: "AppInstance name (primary key)",
|
||||
Required: true,
|
||||
Optional: true,
|
||||
},
|
||||
"organization": schema.StringAttribute{
|
||||
MarkdownDescription: "Organization name (primary key)",
|
||||
Required: true,
|
||||
Optional: true,
|
||||
},
|
||||
"cloudlet_name": schema.StringAttribute{
|
||||
MarkdownDescription: "Cloudlet name (primary key)",
|
||||
Required: true,
|
||||
Optional: true,
|
||||
},
|
||||
"cloudlet_organization": schema.StringAttribute{
|
||||
MarkdownDescription: "Cloudlet organization (primary key)",
|
||||
Required: true,
|
||||
Optional: true,
|
||||
},
|
||||
"region": schema.StringAttribute{
|
||||
MarkdownDescription: "Region (EU or US) (primary key)",
|
||||
|
|
@ -62,7 +71,38 @@ func (d *AppInstanceDataSource) Schema(ctx context.Context, req datasource.Schem
|
|||
},
|
||||
"app_id": schema.StringAttribute{
|
||||
MarkdownDescription: "Associated App ID",
|
||||
Computed: true,
|
||||
Optional: true,
|
||||
},
|
||||
"appinstances": schema.ListNestedAttribute{
|
||||
Computed: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"name": schema.StringAttribute{
|
||||
MarkdownDescription: "AppInstance name (primary key)",
|
||||
Computed: true,
|
||||
},
|
||||
"organization": schema.StringAttribute{
|
||||
MarkdownDescription: "Organization name (primary key)",
|
||||
Computed: true,
|
||||
},
|
||||
"cloudlet_name": schema.StringAttribute{
|
||||
MarkdownDescription: "Cloudlet name (primary key)",
|
||||
Computed: true,
|
||||
},
|
||||
"cloudlet_organization": schema.StringAttribute{
|
||||
MarkdownDescription: "Cloudlet organization (primary key)",
|
||||
Computed: true,
|
||||
},
|
||||
"region": schema.StringAttribute{
|
||||
MarkdownDescription: "Region (EU or US) (primary key)",
|
||||
Computed: true,
|
||||
},
|
||||
"app_id": schema.StringAttribute{
|
||||
MarkdownDescription: "Associated App ID",
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -88,7 +128,7 @@ func (d *AppInstanceDataSource) Configure(ctx context.Context, req datasource.Co
|
|||
}
|
||||
|
||||
func (d *AppInstanceDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
var data AppInstanceDataSourceModel
|
||||
var data AppInstancesDataSourceModel
|
||||
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
|
||||
|
||||
|
|
@ -107,17 +147,24 @@ func (d *AppInstanceDataSource) Read(ctx context.Context, req datasource.ReadReq
|
|||
|
||||
region := data.Region.ValueString()
|
||||
|
||||
appInstance, err := d.client.ShowAppInstance(ctx, appInstKey, region)
|
||||
appInstances, err := d.client.ShowAppInstances(ctx, appInstKey, region)
|
||||
if err != nil {
|
||||
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)
|
||||
|
||||
tflog.Trace(ctx, "read an app instance data source")
|
||||
for _, appInst := range appInstances {
|
||||
data.AppInstances = append(data.AppInstances, AppInstanceDataSourceModel{
|
||||
Name: types.StringValue(appInst.Key.Name),
|
||||
Organization: types.StringValue(appInst.Key.Organization),
|
||||
CloudletName: types.StringValue(appInst.Key.CloudletKey.Name),
|
||||
CloudletOrganization: types.StringValue(appInst.Key.CloudletKey.Organization),
|
||||
Region: types.StringValue(region),
|
||||
AppId: types.StringValue(appInst.AppKey.Name),
|
||||
})
|
||||
}
|
||||
tflog.Trace(ctx, "read app instances data source")
|
||||
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -152,13 +152,13 @@ func (p *EdgeConnectProvider) Configure(ctx context.Context, req provider.Config
|
|||
var client *edgeclient.Client
|
||||
if token != "" {
|
||||
client = edgeclient.NewClient(endpoint,
|
||||
edgeclient.WithHTTPClient(&http.Client{Timeout: 30*time.Second}),
|
||||
edgeclient.WithHTTPClient(&http.Client{Timeout: 30 * time.Second}),
|
||||
edgeclient.WithAuthProvider(edgeclient.NewStaticTokenProvider(token)),
|
||||
edgeclient.WithLogger(tfLogger{}),
|
||||
)
|
||||
} else {
|
||||
client = edgeclient.NewClientWithCredentials(endpoint, username, password,
|
||||
edgeclient.WithHTTPClient(&http.Client{Timeout: 30*time.Second}),
|
||||
edgeclient.WithHTTPClient(&http.Client{Timeout: 30 * time.Second}),
|
||||
edgeclient.WithLogger(tfLogger{}),
|
||||
)
|
||||
}
|
||||
|
|
@ -194,8 +194,8 @@ func New(version string) func() provider.Provider {
|
|||
}
|
||||
}
|
||||
|
||||
type tfLogger struct {}
|
||||
type tfLogger struct{}
|
||||
|
||||
func (tfLogger) Printf(format string, v ...interface{}){
|
||||
func (tfLogger) Printf(format string, v ...interface{}) {
|
||||
tflog.Debug(context.TODO(), fmt.Sprintf(format, v...))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue