added edge-connect_app_instance
This commit is contained in:
parent
f41b35cb33
commit
091621acf9
4 changed files with 111 additions and 72 deletions
|
|
@ -185,7 +185,7 @@ func (r *AppResource) Create(ctx context.Context, req resource.CreateRequest, re
|
|||
DefaultFlavor: edgeclient.Flavor{
|
||||
Name: data.FlavorName.ValueString(),
|
||||
},
|
||||
AllowServerless: false,
|
||||
AllowServerless: true,
|
||||
Deployment: "kubernetes",
|
||||
ServerlessConfig: struct{}{},
|
||||
ImageType: "Docker",
|
||||
|
|
|
|||
|
|
@ -27,12 +27,18 @@ type AppInstanceResource struct {
|
|||
}
|
||||
|
||||
type AppInstanceResourceModel 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"`
|
||||
Id types.String `tfsdk:"id"`
|
||||
Name types.String `tfsdk:"name"`
|
||||
Organization types.String `tfsdk:"organization"`
|
||||
Region types.String `tfsdk:"region"`
|
||||
CloudletOrg types.String `tfsdk:"cloudlet_org"`
|
||||
CloudletName types.String `tfsdk:"cloudlet_name"`
|
||||
AppName types.String `tfsdk:"app_name"`
|
||||
AppVersion types.String `tfsdk:"app_version"`
|
||||
AppOrganization types.String `tfsdk:"app_organization"`
|
||||
FlavorName types.String `tfsdk:"flavor_name"`
|
||||
State types.String `tfsdk:"state"`
|
||||
PowerState types.String `tfsdk:"power_state"`
|
||||
}
|
||||
|
||||
func (r *AppInstanceResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
|
||||
|
|
@ -41,7 +47,7 @@ func (r *AppInstanceResource) Metadata(ctx context.Context, req resource.Metadat
|
|||
|
||||
func (r *AppInstanceResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
MarkdownDescription: "AppInstance resource",
|
||||
MarkdownDescription: "EdgeConnect AppInstance deployment resource",
|
||||
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"id": schema.StringAttribute{
|
||||
|
|
@ -55,20 +61,44 @@ func (r *AppInstanceResource) Schema(ctx context.Context, req resource.SchemaReq
|
|||
MarkdownDescription: "AppInstance name",
|
||||
Required: true,
|
||||
},
|
||||
"app_id": schema.StringAttribute{
|
||||
MarkdownDescription: "Associated App ID",
|
||||
"organization": schema.StringAttribute{
|
||||
MarkdownDescription: "Organization name",
|
||||
Required: true,
|
||||
},
|
||||
"description": schema.StringAttribute{
|
||||
MarkdownDescription: "AppInstance description",
|
||||
Optional: true,
|
||||
"region": schema.StringAttribute{
|
||||
MarkdownDescription: "Region (e.g., US, EU)",
|
||||
Required: true,
|
||||
},
|
||||
"config": schema.StringAttribute{
|
||||
MarkdownDescription: "AppInstance configuration",
|
||||
Optional: true,
|
||||
"cloudlet_org": schema.StringAttribute{
|
||||
MarkdownDescription: "Cloudlet organization",
|
||||
Required: true,
|
||||
},
|
||||
"status": schema.StringAttribute{
|
||||
MarkdownDescription: "AppInstance status",
|
||||
"cloudlet_name": schema.StringAttribute{
|
||||
MarkdownDescription: "Cloudlet name",
|
||||
Required: true,
|
||||
},
|
||||
"app_name": schema.StringAttribute{
|
||||
MarkdownDescription: "Application name",
|
||||
Required: true,
|
||||
},
|
||||
"app_version": schema.StringAttribute{
|
||||
MarkdownDescription: "Application version",
|
||||
Required: true,
|
||||
},
|
||||
"app_organization": schema.StringAttribute{
|
||||
MarkdownDescription: "Application organization",
|
||||
Required: true,
|
||||
},
|
||||
"flavor_name": schema.StringAttribute{
|
||||
MarkdownDescription: "Flavor name",
|
||||
Required: true,
|
||||
},
|
||||
"state": schema.StringAttribute{
|
||||
MarkdownDescription: "AppInstance state",
|
||||
Computed: true,
|
||||
},
|
||||
"power_state": schema.StringAttribute{
|
||||
MarkdownDescription: "AppInstance power state",
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
|
|
@ -104,22 +134,22 @@ func (r *AppInstanceResource) Create(ctx context.Context, req resource.CreateReq
|
|||
}
|
||||
|
||||
appInstInput := &edgeclient.NewAppInstanceInput{
|
||||
Region: "default",
|
||||
Region: data.Region.ValueString(),
|
||||
AppInst: edgeclient.AppInstance{
|
||||
Key: edgeclient.AppInstanceKey{
|
||||
Organization: "default",
|
||||
Organization: data.Organization.ValueString(),
|
||||
Name: data.Name.ValueString(),
|
||||
CloudletKey: edgeclient.CloudletKey{
|
||||
Organization: "default",
|
||||
Name: "default-cloudlet",
|
||||
Organization: data.CloudletOrg.ValueString(),
|
||||
Name: data.CloudletName.ValueString(),
|
||||
},
|
||||
},
|
||||
AppKey: edgeclient.AppKey{
|
||||
Organization: "default",
|
||||
Name: data.AppId.ValueString(),
|
||||
Version: "1.0",
|
||||
Organization: data.AppOrganization.ValueString(),
|
||||
Name: data.AppName.ValueString(),
|
||||
Version: data.AppVersion.ValueString(),
|
||||
},
|
||||
Flavor: edgeclient.Flavor{Name: "m4.small"},
|
||||
Flavor: edgeclient.Flavor{Name: data.FlavorName.ValueString()},
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -130,11 +160,7 @@ func (r *AppInstanceResource) Create(ctx context.Context, req resource.CreateReq
|
|||
}
|
||||
|
||||
data.Id = types.StringValue(appInstInput.AppInst.Key.Name)
|
||||
data.Name = types.StringValue(appInstInput.AppInst.Key.Name)
|
||||
data.AppId = types.StringValue(appInstInput.AppInst.AppKey.Name)
|
||||
data.Description = types.StringValue("")
|
||||
data.Config = types.StringValue("")
|
||||
data.Status = types.StringValue("created")
|
||||
data.State = types.StringValue("created")
|
||||
|
||||
tflog.Trace(ctx, "created an app instance resource")
|
||||
|
||||
|
|
@ -151,25 +177,31 @@ func (r *AppInstanceResource) Read(ctx context.Context, req resource.ReadRequest
|
|||
}
|
||||
|
||||
appInstKey := edgeclient.AppInstanceKey{
|
||||
Organization: "default",
|
||||
Organization: data.Organization.ValueString(),
|
||||
Name: data.Id.ValueString(),
|
||||
CloudletKey: edgeclient.CloudletKey{
|
||||
Organization: "default",
|
||||
Name: "default-cloudlet",
|
||||
Organization: data.CloudletOrg.ValueString(),
|
||||
Name: data.CloudletName.ValueString(),
|
||||
},
|
||||
}
|
||||
|
||||
appInstance, err := r.client.ShowAppInstance(ctx, appInstKey, "default")
|
||||
appInstance, err := r.client.ShowAppInstance(ctx, appInstKey, data.Region.ValueString())
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read app instance %s, got error: %s", data.Id.ValueString(), err))
|
||||
return
|
||||
}
|
||||
|
||||
// Update state from API response
|
||||
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)
|
||||
data.Organization = types.StringValue(appInstance.Key.Organization)
|
||||
data.CloudletOrg = types.StringValue(appInstance.Key.CloudletKey.Organization)
|
||||
data.CloudletName = types.StringValue(appInstance.Key.CloudletKey.Name)
|
||||
data.AppName = types.StringValue(appInstance.AppKey.Name)
|
||||
data.AppVersion = types.StringValue(appInstance.AppKey.Version)
|
||||
data.AppOrganization = types.StringValue(appInstance.AppKey.Organization)
|
||||
data.FlavorName = types.StringValue(appInstance.Flavor.Name)
|
||||
data.State = types.StringValue(appInstance.State)
|
||||
data.PowerState = types.StringValue(appInstance.PowerState)
|
||||
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||
}
|
||||
|
|
@ -184,22 +216,22 @@ func (r *AppInstanceResource) Update(ctx context.Context, req resource.UpdateReq
|
|||
}
|
||||
|
||||
updateInput := &edgeclient.UpdateAppInstanceInput{
|
||||
Region: "default",
|
||||
Region: data.Region.ValueString(),
|
||||
AppInst: edgeclient.AppInstance{
|
||||
Key: edgeclient.AppInstanceKey{
|
||||
Organization: "default",
|
||||
Organization: data.Organization.ValueString(),
|
||||
Name: data.Name.ValueString(),
|
||||
CloudletKey: edgeclient.CloudletKey{
|
||||
Organization: "default",
|
||||
Name: "default-cloudlet",
|
||||
Organization: data.CloudletOrg.ValueString(),
|
||||
Name: data.CloudletName.ValueString(),
|
||||
},
|
||||
},
|
||||
AppKey: edgeclient.AppKey{
|
||||
Organization: "default",
|
||||
Name: data.AppId.ValueString(),
|
||||
Version: "1.0",
|
||||
Organization: data.AppOrganization.ValueString(),
|
||||
Name: data.AppName.ValueString(),
|
||||
Version: data.AppVersion.ValueString(),
|
||||
},
|
||||
Flavor: edgeclient.Flavor{Name: "m4.small"},
|
||||
Flavor: edgeclient.Flavor{Name: data.FlavorName.ValueString()},
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -209,11 +241,7 @@ func (r *AppInstanceResource) Update(ctx context.Context, req resource.UpdateReq
|
|||
return
|
||||
}
|
||||
|
||||
data.Name = types.StringValue(updateInput.AppInst.Key.Name)
|
||||
data.AppId = types.StringValue(updateInput.AppInst.AppKey.Name)
|
||||
data.Description = types.StringValue("")
|
||||
data.Config = types.StringValue("")
|
||||
data.Status = types.StringValue("updated")
|
||||
data.State = types.StringValue("updated")
|
||||
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||
}
|
||||
|
|
@ -228,15 +256,15 @@ func (r *AppInstanceResource) Delete(ctx context.Context, req resource.DeleteReq
|
|||
}
|
||||
|
||||
appInstKey := edgeclient.AppInstanceKey{
|
||||
Organization: "default",
|
||||
Organization: data.Organization.ValueString(),
|
||||
Name: data.Id.ValueString(),
|
||||
CloudletKey: edgeclient.CloudletKey{
|
||||
Organization: "default",
|
||||
Name: "default-cloudlet",
|
||||
Organization: data.CloudletOrg.ValueString(),
|
||||
Name: data.CloudletName.ValueString(),
|
||||
},
|
||||
}
|
||||
|
||||
err := r.client.DeleteAppInstance(ctx, appInstKey, "default")
|
||||
err := r.client.DeleteAppInstance(ctx, appInstKey, data.Region.ValueString())
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete app instance, got error: %s", err))
|
||||
return
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package provider
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
|
@ -150,25 +149,17 @@ func (p *EdgeConnectProvider) Configure(ctx context.Context, req provider.Config
|
|||
tflog.Debug(ctx, "Creating Edge Connect client with username/password authentication")
|
||||
}
|
||||
|
||||
// open output file
|
||||
f, err := os.Create("./output.txt")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// close fo on exit and check for its returned error
|
||||
defer f.Close()
|
||||
|
||||
var client *edgeclient.Client
|
||||
if token != "" {
|
||||
client = edgeclient.NewClient(endpoint,
|
||||
edgeclient.WithHTTPClient(&http.Client{Timeout: 30*time.Second}),
|
||||
edgeclient.WithAuthProvider(edgeclient.NewStaticTokenProvider(token)),
|
||||
edgeclient.WithLogger(fmtLogger{f}),
|
||||
edgeclient.WithLogger(tfLogger{}),
|
||||
)
|
||||
} else {
|
||||
client = edgeclient.NewClientWithCredentials(endpoint, username, password,
|
||||
edgeclient.WithHTTPClient(&http.Client{Timeout: 30*time.Second}),
|
||||
edgeclient.WithLogger(fmtLogger{f}),
|
||||
edgeclient.WithLogger(tfLogger{}),
|
||||
)
|
||||
}
|
||||
// TODO: Configure client with authentication credentials
|
||||
|
|
@ -203,10 +194,8 @@ func New(version string) func() provider.Provider {
|
|||
}
|
||||
}
|
||||
|
||||
type fmtLogger struct {
|
||||
out io.Writer
|
||||
}
|
||||
type tfLogger struct {}
|
||||
|
||||
func (logger fmtLogger) Printf(format string, v ...interface{}){
|
||||
fmt.Fprintf(logger.out, format, v...)
|
||||
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