Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling services is broken #25

Open
carlo-blohm opened this issue Oct 14, 2024 · 0 comments
Open

Handling services is broken #25

carlo-blohm opened this issue Oct 14, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@carlo-blohm
Copy link

Describe the bug

Reading services is not possible, which will run in a type miss match error.
You can create a service but after this, doing a new plan will fail.
Seems like missing correct pointer creation from the generator.

Expected behavior

Being able to read the response from the API into terraform struct. Which should make terraform run as expected in a usual way without errors on this level.

Current behavior

Terraform fails with following message, after the second run, where the first run created a service:

Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: Value Conversion Error
│ 
│ An unexpected error was encountered trying to build a value. This is always an error in the provider. Please report the following to the provider developer:
│ 
│ Received null value, however the target type cannot handle null values. Use the corresponding `types` package type, a pointer type or a custom type that handles null values.
│ 
│ Path: protocol
│ Target Type: provider.serviceRsModel_ujXZojh_ProtocolObject
│ Suggested `types` Type: basetypes.ObjectValue
│ Suggested Pointer Type: *provider.serviceRsModel_ujXZojh_ProtocolObject

Possible solution

change serviceRsModel_ujXZojh_ProtocolObject to pointer

diff --git a/internal/provider/service.go b/internal/provider/service.go
index 1249380..8c20376 100644
--- a/internal/provider/service.go
+++ b/internal/provider/service.go
@@ -66,13 +66,14 @@ type serviceListDsModel_ujXZojh_Config struct {
        Description types.String                              `tfsdk:"description"`
        Id          types.String                              `tfsdk:"id"`
        Name        types.String                              `tfsdk:"name"`
-       Protocol    serviceListDsModel_ujXZojh_ProtocolObject `tfsdk:"protocol"`
+       Protocol    *serviceListDsModel_ujXZojh_ProtocolObject `tfsdk:"protocol"`
        Tags        types.List                                `tfsdk:"tags"`
 }
 
 type serviceListDsModel_ujXZojh_ProtocolObject struct {
        Tcp *serviceListDsModel_ujXZojh_TcpObject `tfsdk:"tcp"`
        Udp *serviceListDsModel_ujXZojh_UdpObject `tfsdk:"udp"`
+       // Empty *types.Object `tfsdk:"empty"` // add an empty object to handle null values
 }
 
 type serviceListDsModel_ujXZojh_TcpObject struct {
@@ -342,7 +343,7 @@ func (d *serviceListDataSource) Read(ctx context.Context, req datasource.ReadReq
 
                        var1.Name = types.StringValue(var0.Name)
 
-                       var1.Protocol = serviceListDsModel_ujXZojh_ProtocolObject{}
+                       var1.Protocol = &serviceListDsModel_ujXZojh_ProtocolObject{}
 
                        if var0.Protocol.Tcp == nil {
                                var1.Protocol.Tcp = nil
@@ -426,7 +427,7 @@ type serviceDsModel struct {
        Description types.String `tfsdk:"description"`
        // omit input: id
        Name     types.String                          `tfsdk:"name"`
-       Protocol serviceDsModel_ujXZojh_ProtocolObject `tfsdk:"protocol"`
+       Protocol *serviceDsModel_ujXZojh_ProtocolObject `tfsdk:"protocol"`
        Tags     types.List                            `tfsdk:"tags"`
 }
 
@@ -614,7 +615,7 @@ func (d *serviceDataSource) Read(ctx context.Context, req datasource.ReadRequest
 
        state.Name = types.StringValue(ans.Name)
 
-       state.Protocol = serviceDsModel_ujXZojh_ProtocolObject{}
+       state.Protocol = &serviceDsModel_ujXZojh_ProtocolObject{}
 
        if ans.Protocol.Tcp == nil {
                state.Protocol.Tcp = nil
@@ -689,7 +690,7 @@ type serviceRsModel struct {
        Folder      types.String                          `tfsdk:"folder"`
        Id          types.String                          `tfsdk:"id"`
        Name        types.String                          `tfsdk:"name"`
-       Protocol    serviceRsModel_ujXZojh_ProtocolObject `tfsdk:"protocol"`
+       Protocol    *serviceRsModel_ujXZojh_ProtocolObject `tfsdk:"protocol"`
        Snippet     types.String                          `tfsdk:"snippet"`
        Tags        types.List                            `tfsdk:"tags"`
 
@@ -1034,7 +1035,7 @@ func (r *serviceResource) Create(ctx context.Context, req resource.CreateRequest
 
        state.Name = types.StringValue(ans.Name)
 
-       state.Protocol = serviceRsModel_ujXZojh_ProtocolObject{}
+       state.Protocol = &serviceRsModel_ujXZojh_ProtocolObject{}
 
        if ans.Protocol.Tcp == nil {
                state.Protocol.Tcp = nil
@@ -1153,7 +1154,7 @@ func (r *serviceResource) Read(ctx context.Context, req resource.ReadRequest, re
 
        state.Name = types.StringValue(ans.Name)
 
-       state.Protocol = serviceRsModel_ujXZojh_ProtocolObject{}
+       state.Protocol = &serviceRsModel_ujXZojh_ProtocolObject{}
 
        if ans.Protocol.Tcp == nil {
                state.Protocol.Tcp = nil
@@ -1306,7 +1307,7 @@ func (r *serviceResource) Update(ctx context.Context, req resource.UpdateRequest
 
        state.Name = types.StringValue(ans.Name)
 
-       state.Protocol = serviceRsModel_ujXZojh_ProtocolObject{}
+       state.Protocol = &serviceRsModel_ujXZojh_ProtocolObject{}
 
        if ans.Protocol.Tcp == nil {
                state.Protocol.Tcp = nil

Steps to reproduce

  1. use resource "scm_service" "default" { ... to create a service
  2. run terraform plan & apply
  3. run terraform plan again, it will fail on the refresh state step

Screenshots

image

Context

I want to manage strata cloud services via terraform

Your Environment

Linux, docker

@carlo-blohm carlo-blohm added the bug Something isn't working label Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant