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

Commit

Permalink
fix: allow none/empty services in update
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenhansendk committed Sep 2, 2023
1 parent 195a1a6 commit 057d55e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/provider/machine_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,10 @@ func (r *flyMachineResource) Update(ctx context.Context, req resource.UpdateRequ

tfservices := ServicesToTfServices(updatedMachine.Config.Services)

if len(tfservices) == 0 {
tfservices = nil
}

state = flyMachineResourceData{
Name: types.StringValue(updatedMachine.Name),
Region: types.StringValue(updatedMachine.Region),
Expand Down
25 changes: 25 additions & 0 deletions internal/provider/machine_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,31 @@ func TestAccFlyMachineEmptyServices(t *testing.T) {
})
}

func TestAccFlyMachineEmptyServicesUpdate(t *testing.T) {
t.Parallel()
rName := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
resource.Test(t, resource.TestCase{
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
PreCheck: func() { testAccPreCheck(t) },
Steps: []resource.TestStep{
{
Config: testFlyMachineResourceConfig(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("fly_machine.testMachine", "name", rName),
resource.TestCheckResourceAttr("fly_machine.testMachine", "services.0.protocol", "tcp"),
),
},
{
Config: testFlyMachineResourceNoServicesConfig(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("fly_machine.testMachine", "name", rName),
resource.TestCheckNoResourceAttr("fly_machine.testMachine", "services"),
),
},
},
})
}

func testFlyMachineResourceEmptyServicesConfig(name string) string {
return providerConfig() + fmt.Sprintf(`
resource "fly_machine" "testMachine" {
Expand Down

0 comments on commit 057d55e

Please sign in to comment.