Fix state diff logic for network subresource of compute

rc-1.0
Sergey Shubin svs1370 4 years ago
parent 78258789eb
commit b924fe681d

@ -394,9 +394,9 @@ func dataSourceCompute() *schema.Resource {
*/
"network": {
Type: schema.TypeSet,
Type: schema.TypeList,
Optional: true,
// MaxItems: MaxNetworksPerCompute,
MaxItems: MaxNetworksPerCompute,
Elem: &schema.Resource{
Schema: networkSubresourceSchemaMake(),
},

@ -21,7 +21,7 @@ import (
// "encoding/json"
// "fmt"
// "log"
log "github.com/sirupsen/logrus"
// "net/url"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
@ -30,6 +30,15 @@ import (
// This is subresource of compute resource used when creating/managing compute network connections
func networkSubresIPAddreDiffSupperss(key, oldVal, newVal string, d *schema.ResourceData) bool {
if newVal != "" && newVal != oldVal {
log.Debugf("networkSubresIPAddreDiffSupperss: key=%s, oldVal=%q, newVal=%q -> suppress=FALSE", key, oldVal, newVal)
return false
}
log.Debugf("networkSubresIPAddreDiffSupperss: key=%s, oldVal=%q, newVal=%q -> suppress=TRUE", key, oldVal, newVal)
return true // suppress difference
}
func networkSubresourceSchemaMake() map[string]*schema.Schema {
rets := map[string]*schema.Schema{
"net_type": {
@ -49,7 +58,7 @@ func networkSubresourceSchemaMake() map[string]*schema.Schema {
"ip_address": {
Type: schema.TypeString,
Optional: true,
// DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {}
DiffSuppressFunc: networkSubresIPAddreDiffSupperss,
Description: "Optional IP address to assign to this connection. This IP should belong to the selected network and free for use.",
},

@ -380,9 +380,9 @@ func resourceCompute() *schema.Resource {
},
"network": {
Type: schema.TypeSet,
Type: schema.TypeList,
Optional: true,
// MaxItems: MaxNetworksPerCompute,
MaxItems: MaxNetworksPerCompute,
Elem: &schema.Resource{
Schema: networkSubresourceSchemaMake(),
},

Loading…
Cancel
Save