terraform-provider-docker/internal/provider/resource_docker_network_structures.go
Manuel Vogel 2845519dce
fix/move helpers (#170)
* chore: rename structures file

* fix: create volume migrators

* fix: move service migrators

* fix: move network migrators

* fix: rename container migrators

* chore: move label migrators and helpers

* chore: move container structures

* chore: move network structures

* fix: move container extrahosts flattener

* fix: move container ulimits flattener

* fix: move container devices flattener

* chore: move service mappers to structures file

* chore: move image helper funcs

* chore: add constants for network refresher funcs

* chore: move plugin crud funcs to the top

* chore: move registry image funcs to the top

* chore: add resfresh func constants for volume

* chore: extract ipam config flatten func
2021-04-19 22:33:13 +09:00

39 lines
1 KiB
Go

package provider
import (
"log"
"github.com/docker/docker/api/types/network"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
// TODO 2: seems like we can replace the set hash generation with plain lists -> #219
func flattenIpamConfigSpec(in []network.IPAMConfig) *schema.Set { // []interface{} {
out := make([]interface{}, len(in))
for i, v := range in {
log.Printf("[DEBUG] flatten ipam %d: %#v", i, v)
m := make(map[string]interface{})
if len(v.Subnet) > 0 {
m["subnet"] = v.Subnet
}
if len(v.IPRange) > 0 {
m["ip_range"] = v.IPRange
}
if len(v.Gateway) > 0 {
m["gateway"] = v.Gateway
}
if len(v.AuxAddress) > 0 {
aux := make(map[string]interface{}, len(v.AuxAddress))
for ka, va := range v.AuxAddress {
aux[ka] = va
}
m["aux_address"] = aux
}
out[i] = m
}
// log.Printf("[INFO] flatten ipam out: %#v", out)
imapConfigsResource := resourceDockerNetwork().Schema["ipam_config"].Elem.(*schema.Resource)
f := schema.HashResource(imapConfigsResource)
return schema.NewSet(f, out)
// return out
}