github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/docker/resource_docker_network.go (about) 1 package docker 2 3 import ( 4 "bytes" 5 "fmt" 6 "sort" 7 8 "github.com/hashicorp/terraform/helper/hashcode" 9 "github.com/hashicorp/terraform/helper/schema" 10 ) 11 12 func resourceDockerNetwork() *schema.Resource { 13 return &schema.Resource{ 14 Create: resourceDockerNetworkCreate, 15 Read: resourceDockerNetworkRead, 16 Delete: resourceDockerNetworkDelete, 17 18 Schema: map[string]*schema.Schema{ 19 "name": &schema.Schema{ 20 Type: schema.TypeString, 21 Required: true, 22 ForceNew: true, 23 }, 24 25 "check_duplicate": &schema.Schema{ 26 Type: schema.TypeBool, 27 Optional: true, 28 ForceNew: true, 29 }, 30 31 "driver": &schema.Schema{ 32 Type: schema.TypeString, 33 Optional: true, 34 ForceNew: true, 35 Computed: true, 36 }, 37 38 "options": &schema.Schema{ 39 Type: schema.TypeMap, 40 Optional: true, 41 ForceNew: true, 42 Computed: true, 43 }, 44 45 "internal": &schema.Schema{ 46 Type: schema.TypeBool, 47 Optional: true, 48 Computed: true, 49 ForceNew: true, 50 }, 51 52 "ipam_driver": &schema.Schema{ 53 Type: schema.TypeString, 54 Optional: true, 55 ForceNew: true, 56 }, 57 58 "ipam_config": &schema.Schema{ 59 Type: schema.TypeSet, 60 Optional: true, 61 ForceNew: true, 62 Elem: getIpamConfigElem(), 63 Set: resourceDockerIpamConfigHash, 64 }, 65 66 "id": &schema.Schema{ 67 Type: schema.TypeString, 68 Computed: true, 69 }, 70 71 "scope": &schema.Schema{ 72 Type: schema.TypeString, 73 Computed: true, 74 }, 75 }, 76 } 77 } 78 79 func getIpamConfigElem() *schema.Resource { 80 return &schema.Resource{ 81 Schema: map[string]*schema.Schema{ 82 "subnet": &schema.Schema{ 83 Type: schema.TypeString, 84 Optional: true, 85 ForceNew: true, 86 }, 87 88 "ip_range": &schema.Schema{ 89 Type: schema.TypeString, 90 Optional: true, 91 ForceNew: true, 92 }, 93 94 "gateway": &schema.Schema{ 95 Type: schema.TypeString, 96 Optional: true, 97 ForceNew: true, 98 }, 99 100 "aux_address": &schema.Schema{ 101 Type: schema.TypeMap, 102 Optional: true, 103 ForceNew: true, 104 }, 105 }, 106 } 107 } 108 109 func resourceDockerIpamConfigHash(v interface{}) int { 110 var buf bytes.Buffer 111 m := v.(map[string]interface{}) 112 113 if v, ok := m["subnet"]; ok { 114 buf.WriteString(fmt.Sprintf("%v-", v.(string))) 115 } 116 117 if v, ok := m["ip_range"]; ok { 118 buf.WriteString(fmt.Sprintf("%v-", v.(string))) 119 } 120 121 if v, ok := m["gateway"]; ok { 122 buf.WriteString(fmt.Sprintf("%v-", v.(string))) 123 } 124 125 if v, ok := m["aux_address"]; ok { 126 auxAddress := v.(map[string]interface{}) 127 128 keys := make([]string, len(auxAddress)) 129 i := 0 130 for k, _ := range auxAddress { 131 keys[i] = k 132 i++ 133 } 134 sort.Strings(keys) 135 136 for _, k := range keys { 137 buf.WriteString(fmt.Sprintf("%v-%v-", k, auxAddress[k].(string))) 138 } 139 } 140 141 return hashcode.String(buf.String()) 142 }