Fixing some logic issues with the aws-instance resource
1. The schema contained a few fields that where not marked as `computed`, while they were updated inside the resource. 2. While updating the `volume_size` it was doing so with a `string`, but in the schema this field is set as `int`. 3. The set func for calculating the hashes for the `block` set items, also used computed values to calculate the hash. As these values will not be in the config, but only in the state, this will always show as a diff. The solution is to only use the fields that aren’t computed in order to get consistent hashes. These where all issues before, but weren’t visible as such. All should be good again now.
This commit is contained in:
parent
fd6382fbaf
commit
b96f373ee9
|
@ -6,6 +6,7 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -153,18 +154,21 @@ func resourceAwsInstance() *schema.Resource {
|
||||||
"snapshot_id": &schema.Schema{
|
"snapshot_id": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"volume_type": &schema.Schema{
|
"volume_type": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"volume_size": &schema.Schema{
|
"volume_size": &schema.Schema{
|
||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -178,6 +182,7 @@ func resourceAwsInstance() *schema.Resource {
|
||||||
"encrypted": &schema.Schema{
|
"encrypted": &schema.Schema{
|
||||||
Type: schema.TypeBool,
|
Type: schema.TypeBool,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
Computed: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -385,11 +390,15 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
||||||
bds := make([]map[string]interface{}, len(volResp.Volumes))
|
bds := make([]map[string]interface{}, len(volResp.Volumes))
|
||||||
for i, vol := range volResp.Volumes {
|
for i, vol := range volResp.Volumes {
|
||||||
|
volSize, err := strconv.Atoi(vol.Size)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
bds[i] = make(map[string]interface{})
|
bds[i] = make(map[string]interface{})
|
||||||
bds[i]["device_name"] = bdByVolID[vol.VolumeId].DeviceName
|
bds[i]["device_name"] = bdByVolID[vol.VolumeId].DeviceName
|
||||||
bds[i]["snapshot_id"] = vol.SnapshotId
|
bds[i]["snapshot_id"] = vol.SnapshotId
|
||||||
bds[i]["volume_type"] = vol.VolumeType
|
bds[i]["volume_type"] = vol.VolumeType
|
||||||
bds[i]["volume_size"] = vol.Size
|
bds[i]["volume_size"] = volSize
|
||||||
bds[i]["delete_on_termination"] = bdByVolID[vol.VolumeId].DeleteOnTermination
|
bds[i]["delete_on_termination"] = bdByVolID[vol.VolumeId].DeleteOnTermination
|
||||||
bds[i]["encrypted"] = vol.Encrypted
|
bds[i]["encrypted"] = vol.Encrypted
|
||||||
}
|
}
|
||||||
|
@ -491,10 +500,7 @@ func resourceAwsInstanceBlockDevicesHash(v interface{}) int {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
m := v.(map[string]interface{})
|
m := v.(map[string]interface{})
|
||||||
buf.WriteString(fmt.Sprintf("%s-", m["device_name"].(string)))
|
buf.WriteString(fmt.Sprintf("%s-", m["device_name"].(string)))
|
||||||
buf.WriteString(fmt.Sprintf("%s-", m["snapshot_id"].(string)))
|
buf.WriteString(fmt.Sprintf("%s-", m["virtual_name"].(string)))
|
||||||
buf.WriteString(fmt.Sprintf("%s-", m["volume_type"].(string)))
|
|
||||||
buf.WriteString(fmt.Sprintf("%d-", m["volume_size"].(int)))
|
|
||||||
buf.WriteString(fmt.Sprintf("%t-", m["delete_on_termination"].(bool)))
|
buf.WriteString(fmt.Sprintf("%t-", m["delete_on_termination"].(bool)))
|
||||||
buf.WriteString(fmt.Sprintf("%t-", m["encrypted"].(bool)))
|
|
||||||
return hashcode.String(buf.String())
|
return hashcode.String(buf.String())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue