tested app
This commit is contained in:
parent
6c7a34d68a
commit
f41b35cb33
4 changed files with 45 additions and 15 deletions
|
|
@ -2,6 +2,7 @@ package provider
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/path"
|
||||
|
|
@ -98,14 +99,14 @@ func (r *AppResource) Schema(ctx context.Context, req resource.SchemaRequest, re
|
|||
MarkdownDescription: "Flavor name",
|
||||
Required: true,
|
||||
},
|
||||
"network": schema.SingleNestedAttribute{
|
||||
},
|
||||
Blocks: map[string]schema.Block{
|
||||
"network": schema.SingleNestedBlock{
|
||||
MarkdownDescription: "Network configuration",
|
||||
Optional: true,
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"outbound_connections": schema.ListNestedAttribute{
|
||||
Blocks: map[string]schema.Block{
|
||||
"outbound_connections": schema.ListNestedBlock{
|
||||
MarkdownDescription: "Outbound connection rules",
|
||||
Optional: true,
|
||||
NestedObject: schema.NestedAttributeObject{
|
||||
NestedObject: schema.NestedBlockObject{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"protocol": schema.StringAttribute{
|
||||
MarkdownDescription: "Protocol (tcp, udp, icmp)",
|
||||
|
|
@ -181,13 +182,22 @@ func (r *AppResource) Create(ctx context.Context, req resource.CreateRequest, re
|
|||
Name: data.Name.ValueString(),
|
||||
Version: data.AppVersion.ValueString(),
|
||||
},
|
||||
DefaultFlavor: edgeclient.Flavor{
|
||||
Name: data.FlavorName.ValueString(),
|
||||
},
|
||||
AllowServerless: false,
|
||||
Deployment: "kubernetes",
|
||||
ImageType: "docker",
|
||||
ServerlessConfig: struct{}{},
|
||||
ImageType: "Docker",
|
||||
ImagePath: "docker.io/library/nginx:latest",
|
||||
DeploymentManifest: data.Manifest.ValueString(),
|
||||
RequiredOutboundConnections: outboundConnections,
|
||||
},
|
||||
}
|
||||
|
||||
appInputJson, _ := json.Marshal(appInput)
|
||||
tflog.Info(ctx, fmt.Sprintf("appInput: %v\n", string(appInputJson)), map[string]interface{}{})
|
||||
|
||||
err := r.client.CreateApp(ctx, appInput)
|
||||
if err != nil {
|
||||
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create app, got error: %s", err))
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package provider
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
|
@ -148,15 +150,25 @@ 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}),
|
||||
)
|
||||
} else {
|
||||
client = edgeclient.NewClientWithCredentials(endpoint, username, password,
|
||||
edgeclient.WithHTTPClient(&http.Client{Timeout: 30*time.Second}),
|
||||
edgeclient.WithLogger(fmtLogger{f}),
|
||||
)
|
||||
}
|
||||
// TODO: Configure client with authentication credentials
|
||||
|
|
@ -190,3 +202,11 @@ func New(version string) func() provider.Provider {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
type fmtLogger struct {
|
||||
out io.Writer
|
||||
}
|
||||
|
||||
func (logger fmtLogger) Printf(format string, v ...interface{}){
|
||||
fmt.Fprintf(logger.out, format, v...)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue