updated app resource

This commit is contained in:
Manuel Ganter 2025-11-11 16:20:36 +01:00
parent 728b27146e
commit 6c7a34d68a
No known key found for this signature in database
2 changed files with 88 additions and 132 deletions

View file

@ -17,7 +17,6 @@ resource "edge-connect_app" "edge_app_demo" {
manifest = file("${path.module}/k8s-deployment.yaml")
infra_template {
region = "US"
cloudlet_org = "TelekomOp"
cloudlet_name = "gardener-shepherd-test"
@ -39,7 +38,6 @@ resource "edge-connect_app" "edge_app_demo" {
}
}
}
}
output "app_id" {
description = "ID of the EdgeConnect app"

View file

@ -32,10 +32,6 @@ type AppResourceModel struct {
AppVersion types.String `tfsdk:"app_version"`
Organization types.String `tfsdk:"organization"`
Manifest types.String `tfsdk:"manifest"`
InfraTemplate []InfraTemplateModel `tfsdk:"infra_template"`
}
type InfraTemplateModel struct {
Region types.String `tfsdk:"region"`
CloudletOrg types.String `tfsdk:"cloudlet_org"`
CloudletName types.String `tfsdk:"cloudlet_name"`
@ -86,11 +82,6 @@ func (r *AppResource) Schema(ctx context.Context, req resource.SchemaRequest, re
MarkdownDescription: "Kubernetes manifest YAML content",
Required: true,
},
"infra_template": schema.ListNestedAttribute{
MarkdownDescription: "Infrastructure template configurations",
Required: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"region": schema.StringAttribute{
MarkdownDescription: "Region (e.g., US, EU)",
Required: true,
@ -138,9 +129,6 @@ func (r *AppResource) Schema(ctx context.Context, req resource.SchemaRequest, re
},
},
},
},
},
},
}
}
@ -172,11 +160,10 @@ func (r *AppResource) Create(ctx context.Context, req resource.CreateRequest, re
return
}
// Build outbound connections from all infra templates
// Build outbound connections from network
var outboundConnections []edgeclient.SecurityRule
for _, infraTemplate := range data.InfraTemplate {
if infraTemplate.Network != nil && len(infraTemplate.Network.OutboundConnections) > 0 {
for _, conn := range infraTemplate.Network.OutboundConnections {
if data.Network != nil && len(data.Network.OutboundConnections) > 0 {
for _, conn := range data.Network.OutboundConnections {
outboundConnections = append(outboundConnections, edgeclient.SecurityRule{
Protocol: conn.Protocol.ValueString(),
PortRangeMin: int(conn.PortRangeMin.ValueInt64()),
@ -185,16 +172,9 @@ func (r *AppResource) Create(ctx context.Context, req resource.CreateRequest, re
})
}
}
}
// Use the first infra template's region as the deployment region
region := "default"
if len(data.InfraTemplate) > 0 {
region = data.InfraTemplate[0].Region.ValueString()
}
appInput := &edgeclient.NewAppInput{
Region: region,
Region: data.Region.ValueString(),
App: edgeclient.App{
Key: edgeclient.AppKey{
Organization: data.Organization.ValueString(),
@ -236,13 +216,7 @@ func (r *AppResource) Read(ctx context.Context, req resource.ReadRequest, resp *
Version: data.AppVersion.ValueString(),
}
// Use the first infra template's region for the query
region := "default"
if len(data.InfraTemplate) > 0 {
region = data.InfraTemplate[0].Region.ValueString()
}
app, err := r.client.ShowApp(ctx, appKey, region)
app, err := r.client.ShowApp(ctx, appKey, data.Region.ValueString())
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read app %s, got error: %s", data.Id.ValueString(), err))
return
@ -254,10 +228,8 @@ func (r *AppResource) Read(ctx context.Context, req resource.ReadRequest, resp *
data.Organization = types.StringValue(app.Key.Organization)
data.Manifest = types.StringValue(app.DeploymentManifest)
// Reconstruct infra templates from outbound connections if available
// Note: The API returns RequiredOutboundConnections but not the full infra template details
// We preserve the existing infra template from state since the API doesn't return it
// The outbound connections can be compared if needed
// Note: The API returns RequiredOutboundConnections but not the full infrastructure details
// We preserve the existing region, cloudlet, flavor, and network from state since the API doesn't return them
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
@ -271,11 +243,10 @@ func (r *AppResource) Update(ctx context.Context, req resource.UpdateRequest, re
return
}
// Build outbound connections from all infra templates
// Build outbound connections from network
var outboundConnections []edgeclient.SecurityRule
for _, infraTemplate := range data.InfraTemplate {
if infraTemplate.Network != nil && len(infraTemplate.Network.OutboundConnections) > 0 {
for _, conn := range infraTemplate.Network.OutboundConnections {
if data.Network != nil && len(data.Network.OutboundConnections) > 0 {
for _, conn := range data.Network.OutboundConnections {
outboundConnections = append(outboundConnections, edgeclient.SecurityRule{
Protocol: conn.Protocol.ValueString(),
PortRangeMin: int(conn.PortRangeMin.ValueInt64()),
@ -284,16 +255,9 @@ func (r *AppResource) Update(ctx context.Context, req resource.UpdateRequest, re
})
}
}
}
// Use the first infra template's region as the deployment region
region := "default"
if len(data.InfraTemplate) > 0 {
region = data.InfraTemplate[0].Region.ValueString()
}
updateInput := &edgeclient.UpdateAppInput{
Region: region,
Region: data.Region.ValueString(),
App: edgeclient.App{
Key: edgeclient.AppKey{
Organization: data.Organization.ValueString(),
@ -331,13 +295,7 @@ func (r *AppResource) Delete(ctx context.Context, req resource.DeleteRequest, re
Version: data.AppVersion.ValueString(),
}
// Use the first infra template's region for deletion
region := "default"
if len(data.InfraTemplate) > 0 {
region = data.InfraTemplate[0].Region.ValueString()
}
err := r.client.DeleteApp(ctx, appKey, region)
err := r.client.DeleteApp(ctx, appKey, data.Region.ValueString())
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete app, got error: %s", err))
return