mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-09 15:43:53 -06:00
Fixes time out when applying updates to Triton machine metadata. (#6149)
* Add Triton Metadata modification AccTest. The test starts the basic machine and then adds the metadata field user_data. Test fails if the user_data field does not match what we expect OR it times out. Related to hashicorp/terraform#6148 * Fix the non-convergence of Triton metadata changes The code waiting for the entire Machine Metadata to "deep equal" the Terraform metadata modifications. These two sets will only be the same if the user changes all metadata fields of the resource before calling `apply`. Closes hashicorp/terraform#6148
This commit is contained in:
parent
c682dece84
commit
33d4c44292
@ -365,7 +365,12 @@ func resourceMachineUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||
err = waitFor(
|
||||
func() (bool, error) {
|
||||
machine, err := client.GetMachine(d.Id())
|
||||
return reflect.DeepEqual(machine.Metadata, metadata), err
|
||||
for k, v := range metadata {
|
||||
if provider_v, ok := machine.Metadata[k]; !ok || v != provider_v {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
return true, err
|
||||
},
|
||||
machineStateChangeCheckInterval,
|
||||
1*time.Minute,
|
||||
|
@ -115,6 +115,34 @@ func TestAccTritonMachine_firewall(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccTritonMachine_metadata(t *testing.T) {
|
||||
machineName := fmt.Sprintf("acctest-%d", acctest.RandInt())
|
||||
basic := fmt.Sprintf(testAccTritonMachine_basic, machineName)
|
||||
add_metadata := fmt.Sprintf(testAccTritonMachine_basic, machineName)
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testCheckTritonMachineDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: basic,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckTritonMachineExists("triton_machine.test"),
|
||||
),
|
||||
},
|
||||
resource.TestStep{
|
||||
Config: add_metadata,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testCheckTritonMachineExists("triton_machine.test"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"triton_machine.test", "user_data", "hello"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
var testAccTritonMachine_basic = `
|
||||
resource "triton_machine" "test" {
|
||||
name = "%s"
|
||||
@ -145,3 +173,17 @@ resource "triton_machine" "test" {
|
||||
firewall_enabled = 1
|
||||
}
|
||||
`
|
||||
|
||||
var testAccTritonMachine_metadata_1 = `
|
||||
resource "triton_machine" "test" {
|
||||
name = "%s"
|
||||
package = "t4-standard-128M"
|
||||
image = "eb9fc1ea-e19a-11e5-bb27-8b954d8c125c"
|
||||
|
||||
user_data = "hello"
|
||||
|
||||
tags = {
|
||||
test = "hello!"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
Loading…
Reference in New Issue
Block a user