Skip to content

Commit 95bedac

Browse files
author
Sander van Harmelen
authored
Make the hash consistent again (hashicorp#11546)
The existing hash function for set items cannot generate consistent hashes when using both `Optional` and `Computed` on a schema field. I tried to add this use case to the existing code base, but came to the conclusion this would be quite an endeavor. That together with the fact this is the only field in all sets used in all builtin providers/resources that would be using both options at the same time, made me decide to change this single resource instead.
1 parent 2639ffc commit 95bedac

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

builtin/providers/cloudstack/resource_cloudstack_port_forward.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ package cloudstack
33
import (
44
"fmt"
55
"log"
6-
"sync"
7-
"time"
8-
96
"strconv"
107
"strings"
8+
"sync"
9+
"time"
1110

1211
"github.com/hashicorp/go-multierror"
1312
"github.com/hashicorp/terraform/helper/schema"
@@ -68,7 +67,6 @@ func resourceCloudStackPortForward() *schema.Resource {
6867
"vm_guest_ip": &schema.Schema{
6968
Type: schema.TypeString,
7069
Optional: true,
71-
Computed: true,
7270
},
7371

7472
"uuid": &schema.Schema{
@@ -160,7 +158,7 @@ func createPortForward(d *schema.ResourceData, meta interface{}, forward map[str
160158
p := cs.Firewall.NewCreatePortForwardingRuleParams(d.Id(), forward["private_port"].(int),
161159
forward["protocol"].(string), forward["public_port"].(int), vm.Id)
162160

163-
if vmGuestIP, ok := forward["vm_guest_ip"]; ok {
161+
if vmGuestIP, ok := forward["vm_guest_ip"]; ok && vmGuestIP.(string) != "" {
164162
p.SetVmguestip(vmGuestIP.(string))
165163

166164
// Set the network ID based on the guest IP, needed when the public IP address
@@ -273,7 +271,13 @@ func resourceCloudStackPortForwardRead(d *schema.ResourceData, meta interface{})
273271
forward["private_port"] = privPort
274272
forward["public_port"] = pubPort
275273
forward["virtual_machine_id"] = f.Virtualmachineid
276-
forward["vm_guest_ip"] = f.Vmguestip
274+
275+
// This one is a bit tricky. We only want to update this optional value
276+
// if we've set one ourselves. If not this would become a computed value
277+
// and that would mess up the calculated hash of the set item.
278+
if forward["vm_guest_ip"].(string) != "" {
279+
forward["vm_guest_ip"] = f.Vmguestip
280+
}
277281

278282
forwards.Add(forward)
279283
}

0 commit comments

Comments
 (0)