diff --git a/internal/provider/app_resource.go b/internal/provider/app_resource.go index 72261f6..0ce9489 100644 --- a/internal/provider/app_resource.go +++ b/internal/provider/app_resource.go @@ -189,6 +189,7 @@ func (r *AppResource) Create(ctx context.Context, req resource.CreateRequest, re Deployment: "kubernetes", ServerlessConfig: struct{}{}, ImageType: "Docker", + DeploymentGenerator: "kubernetes-basic", ImagePath: "docker.io/library/nginx:latest", DeploymentManifest: data.Manifest.ValueString(), RequiredOutboundConnections: outboundConnections, diff --git a/internal/provider/appinst_resource.go b/internal/provider/appinst_resource.go index 68f3854..381ca76 100644 --- a/internal/provider/appinst_resource.go +++ b/internal/provider/appinst_resource.go @@ -162,6 +162,15 @@ func (r *AppInstanceResource) Create(ctx context.Context, req resource.CreateReq data.Id = types.StringValue(appInstInput.AppInst.Key.Name) data.State = types.StringValue("created") + appInstance, err := r.client.ShowAppInstance(ctx, appInstInput.AppInst.Key, data.Region.ValueString()) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read app instance %s, got error: %s", data.Id.ValueString(), err)) + return + } + + // Update state from API response + UpdateDataFromAppInstance(&appInstance, &data) + tflog.Trace(ctx, "created an app instance resource") resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) @@ -192,16 +201,7 @@ func (r *AppInstanceResource) Read(ctx context.Context, req resource.ReadRequest } // Update state from API response - data.Name = types.StringValue(appInstance.Key.Name) - data.Organization = types.StringValue(appInstance.Key.Organization) - data.CloudletOrg = types.StringValue(appInstance.Key.CloudletKey.Organization) - data.CloudletName = types.StringValue(appInstance.Key.CloudletKey.Name) - 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) + UpdateDataFromAppInstance(&appInstance, &data) resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } @@ -241,6 +241,14 @@ func (r *AppInstanceResource) Update(ctx context.Context, req resource.UpdateReq return } + appInstance, err := r.client.ShowAppInstance(ctx, updateInput.AppInst.Key, data.Region.ValueString()) + if err != nil { + resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read app instance %s, got error: %s", data.Id.ValueString(), err)) + return + } + + // Update state from API response + UpdateDataFromAppInstance(&appInstance, &data) data.State = types.StringValue("updated") resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) @@ -274,3 +282,16 @@ func (r *AppInstanceResource) Delete(ctx context.Context, req resource.DeleteReq func (r *AppInstanceResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { resource.ImportStatePassthroughID(ctx, path.Root("id"), req, resp) } + +func UpdateDataFromAppInstance(appInstance *edgeclient.AppInstance, data *AppInstanceResourceModel){ + data.Name = types.StringValue(appInstance.Key.Name) + data.Organization = types.StringValue(appInstance.Key.Organization) + data.CloudletOrg = types.StringValue(appInstance.Key.CloudletKey.Organization) + data.CloudletName = types.StringValue(appInstance.Key.CloudletKey.Name) + 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) +}