Skip to content

Commit

Permalink
Fix Triton firewall_enabled bug with AccTest (#6119)
Browse files Browse the repository at this point in the history
Update github.com/joyent/gosdc/...

Test does the minimum described in hashicorp/terraform#6109, i.e.
	- Start a small instance, t4-standard-128M
	- Check firewall is enabled
	- Change configuration to disable firewall
	- Check firewall is disabled.

Fixes #6119.
  • Loading branch information
sodre authored and jen20 committed Apr 12, 2016
1 parent a8567f7 commit 2d05ae6
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
13 changes: 13 additions & 0 deletions resource_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,19 @@ func resourceMachineUpdate(d *schema.ResourceData, meta interface{}) error {
return err
}

err = waitFor(
func() (bool, error) {
machine, err := client.GetMachine(d.Id())
return machine.FirewallEnabled == d.Get("firewall_enabled").(bool), err
},
machineStateChangeCheckInterval,
machineStateChangeTimeout,
)

if err != nil {
return err
}

d.SetPartial("firewall_enabled")
}

Expand Down
61 changes: 59 additions & 2 deletions resource_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,71 @@ func testCheckTritonMachineDestroy(s *terraform.State) error {
return nil
}

func TestAccTritonMachine_firewall(t *testing.T) {
machineName := fmt.Sprintf("acctest-%d", acctest.RandInt())
disabled_config := fmt.Sprintf(testAccTritonMachine_firewall_0, machineName)
enabled_config := fmt.Sprintf(testAccTritonMachine_firewall_1, machineName)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckTritonMachineDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: enabled_config,
Check: resource.ComposeTestCheckFunc(
testCheckTritonMachineExists("triton_machine.test"),
resource.TestCheckResourceAttr(
"triton_machine.test", "firewall_enabled", "true"),
),
},
resource.TestStep{
Config: disabled_config,
Check: resource.ComposeTestCheckFunc(
testCheckTritonMachineExists("triton_machine.test"),
resource.TestCheckResourceAttr(
"triton_machine.test", "firewall_enabled", "false"),
),
},
resource.TestStep{
Config: enabled_config,
Check: resource.ComposeTestCheckFunc(
testCheckTritonMachineExists("triton_machine.test"),
resource.TestCheckResourceAttr(
"triton_machine.test", "firewall_enabled", "true"),
),
},
},
})
}

var testAccTritonMachine_basic = `
resource "triton_machine" "test" {
name = "%s"
package = "g3-standard-0.25-smartos"
image = "842e6fa6-6e9b-11e5-8402-1b490459e334"
package = "t4-standard-128M"
image = "eb9fc1ea-e19a-11e5-bb27-8b954d8c125c"
tags = {
test = "hello!"
}
}
`

var testAccTritonMachine_firewall_0 = `
resource "triton_machine" "test" {
name = "%s"
package = "t4-standard-128M"
image = "eb9fc1ea-e19a-11e5-bb27-8b954d8c125c"
firewall_enabled = 0
}
`
var testAccTritonMachine_firewall_1 = `
resource "triton_machine" "test" {
name = "%s"
package = "t4-standard-128M"
image = "eb9fc1ea-e19a-11e5-bb27-8b954d8c125c"
firewall_enabled = 1
}
`

0 comments on commit 2d05ae6

Please sign in to comment.