mirror of
https://github.com/kreuzwerker/terraform-provider-docker.git
synced 2026-01-26 08:32:59 -05:00
Merge branch 'docker-extra-hosts' of https://github.com/paulbellamy/terraform into paulbellamy-docker-extra-hosts
This commit is contained in:
commit
ed0a250129
2 changed files with 115 additions and 66 deletions
|
|
@ -119,16 +119,91 @@ func resourceDockerContainer() *schema.Resource {
|
|||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Elem: getVolumesElem(),
|
||||
Set: resourceDockerVolumesHash,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"from_container": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"container_path": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"host_path": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"read_only": &schema.Schema{
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
Set: resourceDockerVolumesHash,
|
||||
},
|
||||
|
||||
"ports": &schema.Schema{
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Elem: getPortsElem(),
|
||||
Set: resourceDockerPortsHash,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"internal": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"external": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"ip": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"protocol": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Default: "tcp",
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
Set: resourceDockerPortsHash,
|
||||
},
|
||||
|
||||
"hosts": &schema.Schema{
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"ip": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"host": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
Set: resourceDockerHostsHash,
|
||||
},
|
||||
|
||||
"env": &schema.Schema{
|
||||
|
|
@ -256,67 +331,6 @@ func resourceDockerContainer() *schema.Resource {
|
|||
}
|
||||
}
|
||||
|
||||
func getVolumesElem() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"from_container": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"container_path": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"host_path": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"read_only": &schema.Schema{
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func getPortsElem() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"internal": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"external": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"ip": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"protocol": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Default: "tcp",
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func resourceDockerPortsHash(v interface{}) int {
|
||||
var buf bytes.Buffer
|
||||
m := v.(map[string]interface{})
|
||||
|
|
@ -338,6 +352,21 @@ func resourceDockerPortsHash(v interface{}) int {
|
|||
return hashcode.String(buf.String())
|
||||
}
|
||||
|
||||
func resourceDockerHostsHash(v interface{}) int {
|
||||
var buf bytes.Buffer
|
||||
m := v.(map[string]interface{})
|
||||
|
||||
if v, ok := m["ip"]; ok {
|
||||
buf.WriteString(fmt.Sprintf("%v-", v.(string)))
|
||||
}
|
||||
|
||||
if v, ok := m["host"]; ok {
|
||||
buf.WriteString(fmt.Sprintf("%v-", v.(string)))
|
||||
}
|
||||
|
||||
return hashcode.String(buf.String())
|
||||
}
|
||||
|
||||
func resourceDockerVolumesHash(v interface{}) int {
|
||||
var buf bytes.Buffer
|
||||
m := v.(map[string]interface{})
|
||||
|
|
|
|||
|
|
@ -67,6 +67,11 @@ func resourceDockerContainerCreate(d *schema.ResourceData, meta interface{}) err
|
|||
createOpts.Config.ExposedPorts = exposedPorts
|
||||
}
|
||||
|
||||
extraHosts := []string{}
|
||||
if v, ok := d.GetOk("extra_hosts"); ok {
|
||||
extraHosts = extraHostsSetToDockerExtraHosts(v.(*schema.Set))
|
||||
}
|
||||
|
||||
volumes := map[string]struct{}{}
|
||||
binds := []string{}
|
||||
volumesFrom := []string{}
|
||||
|
|
@ -100,7 +105,9 @@ func resourceDockerContainerCreate(d *schema.ResourceData, meta interface{}) err
|
|||
if len(portBindings) != 0 {
|
||||
hostConfig.PortBindings = portBindings
|
||||
}
|
||||
|
||||
if len(extraHosts) != 0 {
|
||||
hostConfig.ExtraHosts = extraHosts
|
||||
}
|
||||
if len(binds) != 0 {
|
||||
hostConfig.Binds = binds
|
||||
}
|
||||
|
|
@ -324,6 +331,19 @@ func portSetToDockerPorts(ports *schema.Set) (map[dc.Port]struct{}, map[dc.Port]
|
|||
return retExposedPorts, retPortBindings
|
||||
}
|
||||
|
||||
func extraHostsSetToDockerExtraHosts(extraHosts *schema.Set) []string {
|
||||
retExtraHosts := []string{}
|
||||
|
||||
for _, hostInt := range extraHosts.List() {
|
||||
host := hostInt.(map[string]interface{})
|
||||
ip := host["ip"].(string)
|
||||
hostname := host["host"].(string)
|
||||
retExtraHosts = append(retExtraHosts, hostname+":"+ip)
|
||||
}
|
||||
|
||||
return retExtraHosts
|
||||
}
|
||||
|
||||
func volumeSetToDockerVolumes(volumes *schema.Set) (map[string]struct{}, []string, []string, error) {
|
||||
retVolumeMap := map[string]struct{}{}
|
||||
retHostConfigBinds := []string{}
|
||||
|
|
|
|||
Loading…
Reference in a new issue