Skip to content

Commit 33d4c44

Browse files
sodrestack72
authored andcommitted
Fixes time out when applying updates to Triton machine metadata. (hashicorp#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#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#6148
1 parent c682dec commit 33d4c44

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

builtin/providers/triton/resource_machine.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,12 @@ func resourceMachineUpdate(d *schema.ResourceData, meta interface{}) error {
365365
err = waitFor(
366366
func() (bool, error) {
367367
machine, err := client.GetMachine(d.Id())
368-
return reflect.DeepEqual(machine.Metadata, metadata), err
368+
for k, v := range metadata {
369+
if provider_v, ok := machine.Metadata[k]; !ok || v != provider_v {
370+
return false, err
371+
}
372+
}
373+
return true, err
369374
},
370375
machineStateChangeCheckInterval,
371376
1*time.Minute,

builtin/providers/triton/resource_machine_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,34 @@ func TestAccTritonMachine_firewall(t *testing.T) {
115115
})
116116
}
117117

118+
func TestAccTritonMachine_metadata(t *testing.T) {
119+
machineName := fmt.Sprintf("acctest-%d", acctest.RandInt())
120+
basic := fmt.Sprintf(testAccTritonMachine_basic, machineName)
121+
add_metadata := fmt.Sprintf(testAccTritonMachine_basic, machineName)
122+
123+
resource.Test(t, resource.TestCase{
124+
PreCheck: func() { testAccPreCheck(t) },
125+
Providers: testAccProviders,
126+
CheckDestroy: testCheckTritonMachineDestroy,
127+
Steps: []resource.TestStep{
128+
resource.TestStep{
129+
Config: basic,
130+
Check: resource.ComposeTestCheckFunc(
131+
testCheckTritonMachineExists("triton_machine.test"),
132+
),
133+
},
134+
resource.TestStep{
135+
Config: add_metadata,
136+
Check: resource.ComposeTestCheckFunc(
137+
testCheckTritonMachineExists("triton_machine.test"),
138+
resource.TestCheckResourceAttr(
139+
"triton_machine.test", "user_data", "hello"),
140+
),
141+
},
142+
},
143+
})
144+
}
145+
118146
var testAccTritonMachine_basic = `
119147
resource "triton_machine" "test" {
120148
name = "%s"
@@ -145,3 +173,17 @@ resource "triton_machine" "test" {
145173
firewall_enabled = 1
146174
}
147175
`
176+
177+
var testAccTritonMachine_metadata_1 = `
178+
resource "triton_machine" "test" {
179+
name = "%s"
180+
package = "t4-standard-128M"
181+
image = "eb9fc1ea-e19a-11e5-bb27-8b954d8c125c"
182+
183+
user_data = "hello"
184+
185+
tags = {
186+
test = "hello!"
187+
}
188+
}
189+
`

0 commit comments

Comments
 (0)