added edge-connect_app_instance
This commit is contained in:
parent
f41b35cb33
commit
091621acf9
4 changed files with 111 additions and 72 deletions
|
|
@ -39,7 +39,29 @@ resource "edge-connect_app" "edge_app_demo" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resource "edge-connect_app_instance" "edge_app_demo" {
|
||||||
|
name = "edge-app-demo-instance"
|
||||||
|
organization = "edp2"
|
||||||
|
region = "EU"
|
||||||
|
cloudlet_org = "TelekomOP"
|
||||||
|
cloudlet_name = "Munich"
|
||||||
|
app_name = edge-connect_app.edge_app_demo.name
|
||||||
|
app_version = edge-connect_app.edge_app_demo.app_version
|
||||||
|
app_organization = edge-connect_app.edge_app_demo.organization
|
||||||
|
flavor_name = "EU.small"
|
||||||
|
}
|
||||||
|
|
||||||
output "app_id" {
|
output "app_id" {
|
||||||
description = "ID of the EdgeConnect app"
|
description = "ID of the EdgeConnect app"
|
||||||
value = edge-connect_app.edge_app_demo.id
|
value = edge-connect_app.edge_app_demo.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output "app_instance_id" {
|
||||||
|
description = "ID of the EdgeConnect app instance"
|
||||||
|
value = edge-connect_app_instance.edge_app_demo.id
|
||||||
|
}
|
||||||
|
|
||||||
|
output "app_instance_state" {
|
||||||
|
description = "State of the EdgeConnect app instance"
|
||||||
|
value = edge-connect_app_instance.edge_app_demo.state
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ func (r *AppResource) Create(ctx context.Context, req resource.CreateRequest, re
|
||||||
DefaultFlavor: edgeclient.Flavor{
|
DefaultFlavor: edgeclient.Flavor{
|
||||||
Name: data.FlavorName.ValueString(),
|
Name: data.FlavorName.ValueString(),
|
||||||
},
|
},
|
||||||
AllowServerless: false,
|
AllowServerless: true,
|
||||||
Deployment: "kubernetes",
|
Deployment: "kubernetes",
|
||||||
ServerlessConfig: struct{}{},
|
ServerlessConfig: struct{}{},
|
||||||
ImageType: "Docker",
|
ImageType: "Docker",
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,18 @@ type AppInstanceResource struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type AppInstanceResourceModel struct {
|
type AppInstanceResourceModel struct {
|
||||||
Id types.String `tfsdk:"id"`
|
Id types.String `tfsdk:"id"`
|
||||||
Name types.String `tfsdk:"name"`
|
Name types.String `tfsdk:"name"`
|
||||||
AppId types.String `tfsdk:"app_id"`
|
Organization types.String `tfsdk:"organization"`
|
||||||
Description types.String `tfsdk:"description"`
|
Region types.String `tfsdk:"region"`
|
||||||
Config types.String `tfsdk:"config"`
|
CloudletOrg types.String `tfsdk:"cloudlet_org"`
|
||||||
Status types.String `tfsdk:"status"`
|
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) {
|
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) {
|
func (r *AppInstanceResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||||
resp.Schema = schema.Schema{
|
resp.Schema = schema.Schema{
|
||||||
MarkdownDescription: "AppInstance resource",
|
MarkdownDescription: "EdgeConnect AppInstance deployment resource",
|
||||||
|
|
||||||
Attributes: map[string]schema.Attribute{
|
Attributes: map[string]schema.Attribute{
|
||||||
"id": schema.StringAttribute{
|
"id": schema.StringAttribute{
|
||||||
|
|
@ -55,20 +61,44 @@ func (r *AppInstanceResource) Schema(ctx context.Context, req resource.SchemaReq
|
||||||
MarkdownDescription: "AppInstance name",
|
MarkdownDescription: "AppInstance name",
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
"app_id": schema.StringAttribute{
|
"organization": schema.StringAttribute{
|
||||||
MarkdownDescription: "Associated App ID",
|
MarkdownDescription: "Organization name",
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
"description": schema.StringAttribute{
|
"region": schema.StringAttribute{
|
||||||
MarkdownDescription: "AppInstance description",
|
MarkdownDescription: "Region (e.g., US, EU)",
|
||||||
Optional: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
"config": schema.StringAttribute{
|
"cloudlet_org": schema.StringAttribute{
|
||||||
MarkdownDescription: "AppInstance configuration",
|
MarkdownDescription: "Cloudlet organization",
|
||||||
Optional: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
"status": schema.StringAttribute{
|
"cloudlet_name": schema.StringAttribute{
|
||||||
MarkdownDescription: "AppInstance status",
|
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,
|
Computed: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -104,22 +134,22 @@ func (r *AppInstanceResource) Create(ctx context.Context, req resource.CreateReq
|
||||||
}
|
}
|
||||||
|
|
||||||
appInstInput := &edgeclient.NewAppInstanceInput{
|
appInstInput := &edgeclient.NewAppInstanceInput{
|
||||||
Region: "default",
|
Region: data.Region.ValueString(),
|
||||||
AppInst: edgeclient.AppInstance{
|
AppInst: edgeclient.AppInstance{
|
||||||
Key: edgeclient.AppInstanceKey{
|
Key: edgeclient.AppInstanceKey{
|
||||||
Organization: "default",
|
Organization: data.Organization.ValueString(),
|
||||||
Name: data.Name.ValueString(),
|
Name: data.Name.ValueString(),
|
||||||
CloudletKey: edgeclient.CloudletKey{
|
CloudletKey: edgeclient.CloudletKey{
|
||||||
Organization: "default",
|
Organization: data.CloudletOrg.ValueString(),
|
||||||
Name: "default-cloudlet",
|
Name: data.CloudletName.ValueString(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
AppKey: edgeclient.AppKey{
|
AppKey: edgeclient.AppKey{
|
||||||
Organization: "default",
|
Organization: data.AppOrganization.ValueString(),
|
||||||
Name: data.AppId.ValueString(),
|
Name: data.AppName.ValueString(),
|
||||||
Version: "1.0",
|
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.Id = types.StringValue(appInstInput.AppInst.Key.Name)
|
||||||
data.Name = types.StringValue(appInstInput.AppInst.Key.Name)
|
data.State = types.StringValue("created")
|
||||||
data.AppId = types.StringValue(appInstInput.AppInst.AppKey.Name)
|
|
||||||
data.Description = types.StringValue("")
|
|
||||||
data.Config = types.StringValue("")
|
|
||||||
data.Status = types.StringValue("created")
|
|
||||||
|
|
||||||
tflog.Trace(ctx, "created an app instance resource")
|
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{
|
appInstKey := edgeclient.AppInstanceKey{
|
||||||
Organization: "default",
|
Organization: data.Organization.ValueString(),
|
||||||
Name: data.Id.ValueString(),
|
Name: data.Id.ValueString(),
|
||||||
CloudletKey: edgeclient.CloudletKey{
|
CloudletKey: edgeclient.CloudletKey{
|
||||||
Organization: "default",
|
Organization: data.CloudletOrg.ValueString(),
|
||||||
Name: "default-cloudlet",
|
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 {
|
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, got error: %s", data.Id.ValueString(), err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update state from API response
|
||||||
data.Name = types.StringValue(appInstance.Key.Name)
|
data.Name = types.StringValue(appInstance.Key.Name)
|
||||||
data.AppId = types.StringValue(appInstance.AppKey.Name)
|
data.Organization = types.StringValue(appInstance.Key.Organization)
|
||||||
data.Description = types.StringValue("")
|
data.CloudletOrg = types.StringValue(appInstance.Key.CloudletKey.Organization)
|
||||||
data.Config = types.StringValue("")
|
data.CloudletName = types.StringValue(appInstance.Key.CloudletKey.Name)
|
||||||
data.Status = types.StringValue(appInstance.State)
|
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)...)
|
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{
|
updateInput := &edgeclient.UpdateAppInstanceInput{
|
||||||
Region: "default",
|
Region: data.Region.ValueString(),
|
||||||
AppInst: edgeclient.AppInstance{
|
AppInst: edgeclient.AppInstance{
|
||||||
Key: edgeclient.AppInstanceKey{
|
Key: edgeclient.AppInstanceKey{
|
||||||
Organization: "default",
|
Organization: data.Organization.ValueString(),
|
||||||
Name: data.Name.ValueString(),
|
Name: data.Name.ValueString(),
|
||||||
CloudletKey: edgeclient.CloudletKey{
|
CloudletKey: edgeclient.CloudletKey{
|
||||||
Organization: "default",
|
Organization: data.CloudletOrg.ValueString(),
|
||||||
Name: "default-cloudlet",
|
Name: data.CloudletName.ValueString(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
AppKey: edgeclient.AppKey{
|
AppKey: edgeclient.AppKey{
|
||||||
Organization: "default",
|
Organization: data.AppOrganization.ValueString(),
|
||||||
Name: data.AppId.ValueString(),
|
Name: data.AppName.ValueString(),
|
||||||
Version: "1.0",
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data.Name = types.StringValue(updateInput.AppInst.Key.Name)
|
data.State = types.StringValue("updated")
|
||||||
data.AppId = types.StringValue(updateInput.AppInst.AppKey.Name)
|
|
||||||
data.Description = types.StringValue("")
|
|
||||||
data.Config = types.StringValue("")
|
|
||||||
data.Status = types.StringValue("updated")
|
|
||||||
|
|
||||||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
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{
|
appInstKey := edgeclient.AppInstanceKey{
|
||||||
Organization: "default",
|
Organization: data.Organization.ValueString(),
|
||||||
Name: data.Id.ValueString(),
|
Name: data.Id.ValueString(),
|
||||||
CloudletKey: edgeclient.CloudletKey{
|
CloudletKey: edgeclient.CloudletKey{
|
||||||
Organization: "default",
|
Organization: data.CloudletOrg.ValueString(),
|
||||||
Name: "default-cloudlet",
|
Name: data.CloudletName.ValueString(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
err := r.client.DeleteAppInstance(ctx, appInstKey, "default")
|
err := r.client.DeleteAppInstance(ctx, appInstKey, data.Region.ValueString())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete app instance, got error: %s", err))
|
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete app instance, got error: %s", err))
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package provider
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"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")
|
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
|
var client *edgeclient.Client
|
||||||
if token != "" {
|
if token != "" {
|
||||||
client = edgeclient.NewClient(endpoint,
|
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.WithAuthProvider(edgeclient.NewStaticTokenProvider(token)),
|
||||||
edgeclient.WithLogger(fmtLogger{f}),
|
edgeclient.WithLogger(tfLogger{}),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
client = edgeclient.NewClientWithCredentials(endpoint, username, password,
|
client = edgeclient.NewClientWithCredentials(endpoint, username, password,
|
||||||
edgeclient.WithHTTPClient(&http.Client{Timeout: 30*time.Second}),
|
edgeclient.WithHTTPClient(&http.Client{Timeout: 30*time.Second}),
|
||||||
edgeclient.WithLogger(fmtLogger{f}),
|
edgeclient.WithLogger(tfLogger{}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// TODO: Configure client with authentication credentials
|
// TODO: Configure client with authentication credentials
|
||||||
|
|
@ -203,10 +194,8 @@ func New(version string) func() provider.Provider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type fmtLogger struct {
|
type tfLogger struct {}
|
||||||
out io.Writer
|
|
||||||
}
|
|
||||||
|
|
||||||
func (logger fmtLogger) Printf(format string, v ...interface{}){
|
func (tfLogger) Printf(format string, v ...interface{}){
|
||||||
fmt.Fprintf(logger.out, format, v...)
|
tflog.Debug(context.TODO(), fmt.Sprintf(format, v...))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue