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

Add support for empty/none services in update #238

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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