diff --git a/examples/edgeconnect-config/main.tf b/examples/edgeconnect-config/main.tf index fb6e114..6cd3bb8 100644 --- a/examples/edgeconnect-config/main.tf +++ b/examples/edgeconnect-config/main.tf @@ -17,26 +17,24 @@ 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" - flavor_name = "default" + region = "US" + cloudlet_org = "TelekomOp" + cloudlet_name = "gardener-shepherd-test" + flavor_name = "default" - network { - outbound_connections { - protocol = "tcp" - port_range_min = 80 - port_range_max = 80 - remote_cidr = "0.0.0.0/0" - } + network { + outbound_connections { + protocol = "tcp" + port_range_min = 80 + port_range_max = 80 + remote_cidr = "0.0.0.0/0" + } - outbound_connections { - protocol = "tcp" - port_range_min = 443 - port_range_max = 443 - remote_cidr = "0.0.0.0/0" - } + outbound_connections { + protocol = "tcp" + port_range_min = 443 + port_range_max = 443 + remote_cidr = "0.0.0.0/0" } } } diff --git a/internal/provider/app_resource.go b/internal/provider/app_resource.go index eeed10f..2c60a1c 100644 --- a/internal/provider/app_resource.go +++ b/internal/provider/app_resource.go @@ -27,20 +27,16 @@ type AppResource struct { } type AppResourceModel struct { - Id types.String `tfsdk:"id"` - Name types.String `tfsdk:"name"` - 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"` - FlavorName types.String `tfsdk:"flavor_name"` - Network *NetworkModel `tfsdk:"network"` + Id types.String `tfsdk:"id"` + Name types.String `tfsdk:"name"` + AppVersion types.String `tfsdk:"app_version"` + Organization types.String `tfsdk:"organization"` + Manifest types.String `tfsdk:"manifest"` + Region types.String `tfsdk:"region"` + CloudletOrg types.String `tfsdk:"cloudlet_org"` + CloudletName types.String `tfsdk:"cloudlet_name"` + FlavorName types.String `tfsdk:"flavor_name"` + Network *NetworkModel `tfsdk:"network"` } type NetworkModel struct { @@ -86,54 +82,46 @@ 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", + "region": schema.StringAttribute{ + MarkdownDescription: "Region (e.g., US, EU)", Required: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "region": schema.StringAttribute{ - MarkdownDescription: "Region (e.g., US, EU)", - Required: true, - }, - "cloudlet_org": schema.StringAttribute{ - MarkdownDescription: "Cloudlet organization", - Required: true, - }, - "cloudlet_name": schema.StringAttribute{ - MarkdownDescription: "Cloudlet name", - Required: true, - }, - "flavor_name": schema.StringAttribute{ - MarkdownDescription: "Flavor name", - Required: true, - }, - "network": schema.SingleNestedAttribute{ - MarkdownDescription: "Network configuration", - Optional: true, + }, + "cloudlet_org": schema.StringAttribute{ + MarkdownDescription: "Cloudlet organization", + Required: true, + }, + "cloudlet_name": schema.StringAttribute{ + MarkdownDescription: "Cloudlet name", + Required: true, + }, + "flavor_name": schema.StringAttribute{ + MarkdownDescription: "Flavor name", + Required: true, + }, + "network": schema.SingleNestedAttribute{ + MarkdownDescription: "Network configuration", + Optional: true, + Attributes: map[string]schema.Attribute{ + "outbound_connections": schema.ListNestedAttribute{ + MarkdownDescription: "Outbound connection rules", + Optional: true, + NestedObject: schema.NestedAttributeObject{ Attributes: map[string]schema.Attribute{ - "outbound_connections": schema.ListNestedAttribute{ - MarkdownDescription: "Outbound connection rules", - Optional: true, - NestedObject: schema.NestedAttributeObject{ - Attributes: map[string]schema.Attribute{ - "protocol": schema.StringAttribute{ - MarkdownDescription: "Protocol (tcp, udp, icmp)", - Required: true, - }, - "port_range_min": schema.Int64Attribute{ - MarkdownDescription: "Minimum port number", - Required: true, - }, - "port_range_max": schema.Int64Attribute{ - MarkdownDescription: "Maximum port number", - Required: true, - }, - "remote_cidr": schema.StringAttribute{ - MarkdownDescription: "Remote CIDR (e.g., 0.0.0.0/0)", - Required: true, - }, - }, - }, + "protocol": schema.StringAttribute{ + MarkdownDescription: "Protocol (tcp, udp, icmp)", + Required: true, + }, + "port_range_min": schema.Int64Attribute{ + MarkdownDescription: "Minimum port number", + Required: true, + }, + "port_range_max": schema.Int64Attribute{ + MarkdownDescription: "Maximum port number", + Required: true, + }, + "remote_cidr": schema.StringAttribute{ + MarkdownDescription: "Remote CIDR (e.g., 0.0.0.0/0)", + Required: true, }, }, }, @@ -172,29 +160,21 @@ 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 { - outboundConnections = append(outboundConnections, edgeclient.SecurityRule{ - Protocol: conn.Protocol.ValueString(), - PortRangeMin: int(conn.PortRangeMin.ValueInt64()), - PortRangeMax: int(conn.PortRangeMax.ValueInt64()), - RemoteCIDR: conn.RemoteCIDR.ValueString(), - }) - } + 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()), + PortRangeMax: int(conn.PortRangeMax.ValueInt64()), + RemoteCIDR: conn.RemoteCIDR.ValueString(), + }) } } - // 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,29 +243,21 @@ 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 { - outboundConnections = append(outboundConnections, edgeclient.SecurityRule{ - Protocol: conn.Protocol.ValueString(), - PortRangeMin: int(conn.PortRangeMin.ValueInt64()), - PortRangeMax: int(conn.PortRangeMax.ValueInt64()), - RemoteCIDR: conn.RemoteCIDR.ValueString(), - }) - } + 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()), + PortRangeMax: int(conn.PortRangeMax.ValueInt64()), + RemoteCIDR: conn.RemoteCIDR.ValueString(), + }) } } - // 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