Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

.services: was null, but now ... #151

Open
andrewbaxter opened this issue Feb 6, 2023 · 4 comments · May be fixed by #238
Open

.services: was null, but now ... #151

andrewbaxter opened this issue Feb 6, 2023 · 4 comments · May be fixed by #238

Comments

@andrewbaxter
Copy link

I encountered this error after updating a machine image:

│ When applying changes to fly_machine.MYID, provider "provider[\"registry.terraform.io/fly-apps/fly\"]" produced an unexpected new value: .services: was null, but now
│ cty.ListValEmpty(cty.Object(map[string]cty.Type{"internal_port":cty.Number, "ports":cty.List(cty.Object(map[string]cty.Type{"handlers":cty.List(cty.String), "port":cty.Number})),
│ "protocol":cty.String})).

I guess Read and Create set services = nil but this is missing from Update? At

	tfservices := ServicesToTfServices(updatedMachine.Config.Services)
@andrewbaxter
Copy link
Author

Yeah,

diff --git a/internal/provider/machine_resource.go b/internal/provider/machine_resource.go
index 83b4dd9..e46b78a 100644
--- a/internal/provider/machine_resource.go
+++ b/internal/provider/machine_resource.go
@@ -4,6 +4,7 @@ import (
        "context"
        "errors"
        "fmt"
+
        "github.com/fly-apps/terraform-provider-fly/internal/utils"
        "github.com/fly-apps/terraform-provider-fly/pkg/apiv1"
        "github.com/hashicorp/terraform-plugin-framework/diag"
@@ -552,6 +553,10 @@ func (mr flyMachineResource) Update(ctx context.Context, req resource.UpdateRequ
 
        tfservices := ServicesToTfServices(updatedMachine.Config.Services)
 
+       if plan.Services == nil && len(tfservices) == 0 {
+               tfservices = nil
+       }
+
        state = flyMachineResourceData{
                Name:       types.String{Value: updatedMachine.Name},
                Region:     types.String{Value: updatedMachine.Region},

seems to have fixed it.

@andrewbaxter
Copy link
Author

andrewbaxter commented Feb 11, 2023

This prevents updating machines with no services defined (eg: databases).

@loganmimaroglu
Copy link

I ran into a similar issue. As a temporary fix, I initially defined the service on my database machine to be an empty array, that way I am able to update the configuration on subsequent deployments:

resource "fly_machine" "database" {
  ...
  services  = []
  ...
}

@kdevan
Copy link

kdevan commented Mar 23, 2023

Same on my end. If you omit services completely, tfstate still sets services = [] but it expects null. If I manually change tfstate to services = null it gets rid of the error and I'm able to continue forward until the next update. But @GlueStix workaround is much better :)

@sorenhansendk sorenhansendk linked a pull request Sep 2, 2023 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants