tested app
This commit is contained in:
parent
6c7a34d68a
commit
f41b35cb33
4 changed files with 45 additions and 15 deletions
|
|
@ -5,7 +5,7 @@ metadata:
|
||||||
labels:
|
labels:
|
||||||
app: nginx
|
app: nginx
|
||||||
spec:
|
spec:
|
||||||
replicas: 3
|
replicas: 1
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
app: nginx
|
app: nginx
|
||||||
|
|
@ -16,7 +16,7 @@ spec:
|
||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: nginx
|
- name: nginx
|
||||||
image: nginx:latest
|
image: docker.io/library/nginx:latest
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 80
|
- containerPort: 80
|
||||||
---
|
---
|
||||||
|
|
|
||||||
|
|
@ -12,15 +12,15 @@ provider "edge-connect" {
|
||||||
|
|
||||||
resource "edge-connect_app" "edge_app_demo" {
|
resource "edge-connect_app" "edge_app_demo" {
|
||||||
name = "edge-app-demo"
|
name = "edge-app-demo"
|
||||||
app_version = "1"
|
app_version = "1.0.0"
|
||||||
organization = "edp2-orca"
|
organization = "edp2"
|
||||||
|
|
||||||
manifest = file("${path.module}/k8s-deployment.yaml")
|
manifest = file("${path.module}/k8s-deployment.yaml")
|
||||||
|
|
||||||
region = "US"
|
region = "EU"
|
||||||
cloudlet_org = "TelekomOp"
|
cloudlet_org = "TelekomOP"
|
||||||
cloudlet_name = "gardener-shepherd-test"
|
cloudlet_name = "Munich"
|
||||||
flavor_name = "default"
|
flavor_name = "EU.small"
|
||||||
|
|
||||||
network {
|
network {
|
||||||
outbound_connections {
|
outbound_connections {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package provider
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-framework/path"
|
"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",
|
MarkdownDescription: "Flavor name",
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
"network": schema.SingleNestedAttribute{
|
},
|
||||||
|
Blocks: map[string]schema.Block{
|
||||||
|
"network": schema.SingleNestedBlock{
|
||||||
MarkdownDescription: "Network configuration",
|
MarkdownDescription: "Network configuration",
|
||||||
Optional: true,
|
Blocks: map[string]schema.Block{
|
||||||
Attributes: map[string]schema.Attribute{
|
"outbound_connections": schema.ListNestedBlock{
|
||||||
"outbound_connections": schema.ListNestedAttribute{
|
|
||||||
MarkdownDescription: "Outbound connection rules",
|
MarkdownDescription: "Outbound connection rules",
|
||||||
Optional: true,
|
NestedObject: schema.NestedBlockObject{
|
||||||
NestedObject: schema.NestedAttributeObject{
|
|
||||||
Attributes: map[string]schema.Attribute{
|
Attributes: map[string]schema.Attribute{
|
||||||
"protocol": schema.StringAttribute{
|
"protocol": schema.StringAttribute{
|
||||||
MarkdownDescription: "Protocol (tcp, udp, icmp)",
|
MarkdownDescription: "Protocol (tcp, udp, icmp)",
|
||||||
|
|
@ -181,13 +182,22 @@ func (r *AppResource) Create(ctx context.Context, req resource.CreateRequest, re
|
||||||
Name: data.Name.ValueString(),
|
Name: data.Name.ValueString(),
|
||||||
Version: data.AppVersion.ValueString(),
|
Version: data.AppVersion.ValueString(),
|
||||||
},
|
},
|
||||||
|
DefaultFlavor: edgeclient.Flavor{
|
||||||
|
Name: data.FlavorName.ValueString(),
|
||||||
|
},
|
||||||
|
AllowServerless: false,
|
||||||
Deployment: "kubernetes",
|
Deployment: "kubernetes",
|
||||||
ImageType: "docker",
|
ServerlessConfig: struct{}{},
|
||||||
|
ImageType: "Docker",
|
||||||
|
ImagePath: "docker.io/library/nginx:latest",
|
||||||
DeploymentManifest: data.Manifest.ValueString(),
|
DeploymentManifest: data.Manifest.ValueString(),
|
||||||
RequiredOutboundConnections: outboundConnections,
|
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)
|
err := r.client.CreateApp(ctx, appInput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create app, got error: %s", err))
|
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create app, got error: %s", err))
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package provider
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"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")
|
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}),
|
||||||
)
|
)
|
||||||
} 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}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// TODO: Configure client with authentication credentials
|
// 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